Skip to content

Commit 92b827b

Browse files
authored
Merge pull request DefinitelyTyped#15726 from viskin/master
@types/natural: added POS Tagger
2 parents bbc61fb + a33a4e6 commit 92b827b

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

types/natural/index.d.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for Natural 0.2.1
1+
// Type definitions for Natural 0.2.2
22
// Project: https://github.com/NaturalNode/natural
33
// Definitions by: Dylan R. E. Moonfire <https://github.com/dmoonfire/>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -202,3 +202,40 @@ declare class Spellcheck {
202202
isCorrect(word: string): boolean;
203203
getCorrections(word: string, maxDistance?: number): string[];
204204
}
205+
206+
declare class Predicate {
207+
constructor(name: string, parameter1: string, parameter2?: string);
208+
name: string;
209+
parameter1: string;
210+
parameter2?: string;
211+
function?: (tagged_sentence: string[][], i: number, parameter: string) => boolean;
212+
evaluate(tagged_sentence: string[][], position: number): boolean;
213+
}
214+
215+
declare class TransformationRule {
216+
constructor(c1: string, c2: string, predicate: string, parameter1: string, parameter2?: string);
217+
literal: string[];
218+
predicate: Predicate;
219+
old_category: string;
220+
new_category: string;
221+
apply(tagged_sentence: string[][], position: number): void;
222+
}
223+
224+
declare class RuleSet {
225+
constructor(filename: string);
226+
rules: TransformationRule[];
227+
}
228+
229+
declare class Lexicon {
230+
constructor(filename: string, defaultCategory: string);
231+
defaultCategory: string;
232+
parseLexicon(data: string): void;
233+
tagWord(word: string): string[];
234+
}
235+
236+
declare class BrillPOSTagger {
237+
constructor(lexicon: Lexicon, ruleSet: RuleSet);
238+
lexicon: Lexicon;
239+
ruleSet: RuleSet;
240+
tag(sentence: string[]): string[][];
241+
}

types/natural/natural-tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,16 @@ var spellcheck = new natural.Spellcheck(corpus);
259259
spellcheck.isCorrect('cat'); // false
260260
spellcheck.getCorrections('soemthing', 1); // ['something']
261261
spellcheck.getCorrections('soemthing', 2); // ['something', 'soothing']
262+
263+
// POS Tagger
264+
265+
var rulesFilename = 'fileName';
266+
var lexiconFilename = 'fileName';
267+
var defaultCategory = 'N';
268+
269+
var lexicon = new natural.Lexicon(lexiconFilename, defaultCategory);
270+
var rules = new natural.RuleSet(rulesFilename);
271+
var tagger = new natural.BrillPOSTagger(lexicon, rules);
272+
273+
var sentence = ["I", "see", "the", "man", "with", "the", "telescope"];
274+
tagger.tag(sentence);

0 commit comments

Comments
 (0)