Code Monkey home page Code Monkey logo

languagetool-service's Introduction

languagetool-service

Node.js CI

A lightweight JavaScript library for managing a LanguageTool service. This is an abstract class.

Installation

npm:

npm install languagetool-server

Usage

Use this to extend the LanguageTool service classes.

You MUST implement:

  • isInstalled()
  • install()
  • isUpdated()
  • update()

You MAY override and of the other methods as needed. You can also extend ILanguageToolServiceConfiguration to include additional configuration items per service.

class LanguageToolServiceMock extends LanguageToolService {
  public isInstalled(): boolean {
    return true;
  }

  public install(): Promise<boolean> {
    return new Promise((resolve) => {
      resolve(true);
    });
  }

  public isUpdated(): boolean {
    return true;
  }

  public update(): Promise<boolean> {
    return new Promise((resolve) => {
      resolve(true);
    });
  }
}

Types

ILanguageToolService

This is the main class to implement.

export interface ILanguageToolService {
  start(): Promise<boolean>; // Start the service
  stop(): Promise<boolean>; // Stop the service
  ping(): Promise<boolean>; // Ping the service
  info(): Promise<ILanguageToolInfo>; // Get info from the service
  isInstalled(): boolean; // Check if the service is installed
  install(): Promise<boolean>; // Install the service
  isUpdated(): boolean; // Check if the service is updated
  update(): Promise<boolean>; // Update the service
  getConfiguration(): ILanguageToolServiceConfiguration; // Get the configuration
  setConfiguration(configuration: ILanguageToolServiceConfiguration): void; // Set the configuration
  check(annotatedText: IAnnotatedtext): Promise<ILanguageToolResponse>; // Check the annotated text
  languages(): Promise<ILanguageToolLanguage[]>; // Get the list of languages
  getState(): string; // Get the state of the service
  getBaseURL(): string | undefined; // Get the base URL of the service
  getCheckURL(): string | undefined; // Get the check URL of the service
  getLanguagesURL(): string | undefined; // Get the languages URL of the service
  getRuleURL(ruleId: string, language: string): string; // Get the rule base URI of the service
  DEFAULT_CHECK_PATH: string; // "/check"
  DEFAULT_LANGUAGES_PATH: string; // "/languages"
  DEFAULT_RULE_BASE_URI: string; // "https://community.languagetool.org/rule/show/"
  STATES: {
    READY: string, // Service is ready
    STARTING: string, // Service is starting
    STOPPING: string, // Service is stopping
    IDLE: string, // Service is idle
    STOPPED: string, // Service is stopped
    ERROR: string, // Service is in error state
  };
}

ILanguageToolServiceConfiguration

This is the configuration to implement.

export interface ILanguageToolServiceConfiguration {
  host: string;
  port: number;
  basePath?: string;
  checkPath?: string;
  languagesPath?: string;
  ruleBaseURI?: string;
  parameters: {
    language: string,
    username?: string,
    apiKey?: string,
    dicts?: string[],
    motherTongue?: string,
    preferredVariants?: string[],
    enabledRules?: string[],
    disabledRules?: string[],
    enabledCategories?: string[],
    disabledCategories?: string[],
    enabledOnly?: string, // "true" | "false"
    level?: string, // "default" | "picky"
  };
}

ILanguageToolMatch

export interface ILanguageToolMatch {
  message: string;
  shortMessage: string;
  offset: number;
  length: number;
  replacements: ILanguageToolReplacement[];
  context: {
    text: string,
    offset: number,
    length: number,
  };
  sentence: string;
  type: {
    typeName: string,
  };
  rule: {
    id: string,
    description: string,
    issueType: string,
    category: {
      id: string,
      name: string,
    },
  };
  ignoreForIncompleteSentence: boolean;
  contextForSureMatch: number;
}

ILanguageToolReplacement

export interface ILanguageToolReplacement {
  value: string;
  shortDescription: string;
}

ILanguageToolLanguage

export interface ILanguageToolLanguage {
  name: string;
  code: string;
  longCode: string;
}

ILanguageToolInfo

export interface ILanguageToolInfo {
  name: string;
  version: string;
  buildDate: string;
  apiVersion: number;
  premium: boolean;
  premiumHint: string;
  status: string;
}

ILanguageToolResponse

export interface ILanguageToolResponse {
  software: ILanguageToolInfo;
  warnings: {
    incompleteResults: boolean,
  };
  language: {
    name: string,
    code: string,
    detectedLanguage: {
      name: string,
      code: string,
      confidence: number,
    },
  };
  matches: ILanguageToolMatch[];
}

languagetool-service's People

Contributors

davidlday avatar dependabot[bot] avatar github-actions[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.