adding declarations for wink-pos-tagger (#43229)

* adding missing addRegex method to type definitions

* formatting

* formatting

* removing trailing whitespace

* adding definitions for wink-pos-tagger

* adding author information

* const instead of var in tests

* removing trailing whitespace

* formatting

* formatting
This commit is contained in:
Lars Klein
2020-03-20 11:54:12 -04:00
committed by GitHub
parent 876117fb54
commit 490cf94683
4 changed files with 115 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
// Type definitions for wink-pos-tagger 2.2
// Project: http://winkjs.org/
// Definitions by: Lars Klein <https://github.com/lhk>
// 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;
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
@@ -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'] });