@types/natural: added POS Tagger

This commit is contained in:
viskin
2017-04-08 13:28:00 +03:00
parent e3fa8a2176
commit f82fb85b43
2 changed files with 50 additions and 0 deletions
+37
View File
@@ -202,3 +202,40 @@ declare class Spellcheck {
isCorrect(word: string): boolean;
getCorrections(word: string, maxDistance?: number): string[];
}
declare class Predicate {
constructor(name: string, parameter1: string, parameter2?: string);
name: string;
parameter1: string;
parameter2?: string;
function?: (tagged_sentence: string[][], i: number, parameter: string) => boolean;
evaluate(tagged_sentence: string[][], position: number): boolean;
}
declare class TransformationRule {
constructor(c1: string, c2: string, predicate: string, parameter1: string, parameter2?: string);
literal: string[];
predicate: Predicate;
old_category: string;
new_category: string;
apply(tagged_sentence: string[][], position: number): void;
}
declare class RuleSet {
constructor(filename: string);
rules: TransformationRule[];
}
declare class Lexicon {
constructor(filename: string, defaultCategory: string);
defaultCategory: string;
parseLexicon(data: string): void;
tagWord(word: string): string[];
}
declare class BrillPOSTagger {
constructor(lexicon: Lexicon, ruleSet: RuleSet);
lexicon: Lexicon;
ruleSet: RuleSet;
tag(sentence: string[]): string[][];
}
+13
View File
@@ -259,3 +259,16 @@ var spellcheck = new natural.Spellcheck(corpus);
spellcheck.isCorrect('cat'); // false
spellcheck.getCorrections('soemthing', 1); // ['something']
spellcheck.getCorrections('soemthing', 2); // ['something', 'soothing']
// POS Tagger
var rulesFilename = 'fileName';
var lexiconFilename = 'fileName';
var defaultCategory = 'N';
var lexicon = new natural.Lexicon(lexiconFilename, defaultCategory);
var rules = new natural.RuleSet(rulesFilename);
var tagger = new natural.BrillPOSTagger(lexicon, rules);
var sentence = ["I", "see", "the", "man", "with", "the", "telescope"];
tagger.tag(sentence);