diff --git a/types/wink-pos-tagger/index.d.ts b/types/wink-pos-tagger/index.d.ts new file mode 100644 index 0000000000..f37a367f6f --- /dev/null +++ b/types/wink-pos-tagger/index.d.ts @@ -0,0 +1,71 @@ +// Type definitions for wink-pos-tagger 2.2 +// Project: http://winkjs.org/ +// Definitions by: Lars Klein +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Token } from 'wink-tokenizer'; + +declare class Tagger { + /** + * create a tagger instance + */ + constructor(); + + /** + * This API has no effect. It has been maintained for compatibility purpose. + * The wink-tokenizer will now always add lemma and normal forms. + * Note, lemmas are added only for nouns (excluding proper noun), verbs and adjectives. + * @param config configuration object + * @returns object with active configuration + */ + defineConfig(config: any): { lemma: true, normal: true }; + + /** + * Tags the input tokens with their pos. + * In order to pos tag a sentence directly, use tagSentence API instead + * @param tokens array of tokens, as produced by the wink tokenizer + * @return pos tagged tokens + */ + tag(tokens: Token[]): Tagger.PosTaggedToken[]; + + /** + * Tags the raw tokens with their pos. + * Note, it only categorizes each token in to one of the following 3-categories (a) word, or (b) punctuation, or (c) number. + * @param tokens to be pos tagged. They are simple array of string. + * @return pos tagged tokens + */ + tagRawTokens(tokens: string[]): Tagger.PosTaggedToken[]; + + /** + * Tokenizes the input sentence and tags the tokens. + * @param sentence to be pos tagged + * @return pos tagged tokens + */ + tagSentence(sentence: string): Tagger.PosTaggedToken[]; + + /** + * Updates the internal lexicon using the input lexicon. + * If a word/pos pair is found in the internal lexicon then it's value is updated with the new pos; otherwise it added. + * @param lexicon object with word/pos pairs to be added or replaced in the existing lexicon. + * @return pos tagged tokens + */ + updateLexicon(lexicon: object): void; +} + +declare namespace Tagger { + type Tag = "word" | "email" | "emoji" | "punctuation" + | "number" | "time" | "hashtag" | "mention" | "emoticon" | "ordinal" + | "quoted_phrase" | "url" | "symbol" | "currency" | "alien"; + + type PosTag = "PRP" | "VBD" | "DT" | "JJ" | "NN" | "IN" | "VBG" | "."; + + interface PosTaggedToken { + value: string; + tag: Tag; + normal: string; + pos: PosTag; + lemma?: string; + } +} + +export = Tagger; diff --git a/types/wink-pos-tagger/tsconfig.json b/types/wink-pos-tagger/tsconfig.json new file mode 100644 index 0000000000..fd4a4e4813 --- /dev/null +++ b/types/wink-pos-tagger/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "wink-pos-tagger-tests.ts" + ] +} diff --git a/types/wink-pos-tagger/tslint.json b/types/wink-pos-tagger/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wink-pos-tagger/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wink-pos-tagger/wink-pos-tagger-tests.ts b/types/wink-pos-tagger/wink-pos-tagger-tests.ts new file mode 100644 index 0000000000..486316909f --- /dev/null +++ b/types/wink-pos-tagger/wink-pos-tagger-tests.ts @@ -0,0 +1,20 @@ +import * as Tagger from 'wink-pos-tagger'; +import * as Tokenizer from 'wink-tokenizer'; + +const myTagger = new Tagger(); +const myTokenizer = new Tokenizer(); + +// examples taken from official API: https://winkjs.org/wink-pos-tagger/ +// There will not be any effect: +myTagger.defineConfig({ lemma: false }); +// -> { lemma: true, normal: true } + +myTagger.tag(myTokenizer.tokenize('I ate the entire pizza as I was feeling hungry.')); + +const rawTokens = ['I', 'ate', 'the', 'entire', 'pizza', 'as', 'I', 'was', 'feeling', 'hungry', '.']; +// Tag the raw tokens. +myTagger.tagRawTokens(rawTokens); + +myTagger.tagSentence('A bear just crossed the road.'); +myTagger.tagSentence('I will bear all the expenses.'); +myTagger.updateLexicon({ Obama: ['NNP'] });