mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-02 00:00:04 +00:00
Merge pull request #34648 from ybentz/natural-classifiers-classification
[natural] updated classifiers classification definition
This commit is contained in:
8
types/natural/index.d.ts
vendored
8
types/natural/index.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Natural 0.2.2
|
||||
// Type definitions for Natural 0.6
|
||||
// Project: https://github.com/NaturalNode/natural
|
||||
// Definitions by: Dylan R. E. Moonfire <https://github.com/dmoonfire>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -67,6 +67,7 @@ declare var LancasterStemmer: {
|
||||
stem(token: string): string;
|
||||
}
|
||||
|
||||
interface BayesClassifierClassification { label: string, value: number }
|
||||
interface BayesClassifierCallback { (err: any, classifier: any): void }
|
||||
declare class BayesClassifier {
|
||||
events: events.EventEmitter;
|
||||
@@ -74,12 +75,13 @@ declare class BayesClassifier {
|
||||
addDocument(text: string[], stem: string): void;
|
||||
train(): void;
|
||||
classify(observation: string): string;
|
||||
getClassifications(observation: string): string[];
|
||||
getClassifications(observation: string): BayesClassifierClassification[];
|
||||
save(filename: string, callback: BayesClassifierCallback): void;
|
||||
static load(filename: string, stemmer: Stemmer, callback: BayesClassifierCallback): void;
|
||||
static restore(classifier: any, stemmer?: Stemmer): BayesClassifier;
|
||||
}
|
||||
|
||||
interface LogisticRegressionClassifierClassification { label: string, value: number }
|
||||
interface LogisticRegressionClassifierCallback { (err: any, classifier: any): void }
|
||||
declare class LogisticRegressionClassifier {
|
||||
events: events.EventEmitter;
|
||||
@@ -87,7 +89,7 @@ declare class LogisticRegressionClassifier {
|
||||
addDocument(text: string[], stem: string): void;
|
||||
train(): void;
|
||||
classify(observation: string): string;
|
||||
getClassifications(observation: string): string[];
|
||||
getClassifications(observation: string): LogisticRegressionClassifierClassification[];
|
||||
save(filename: string, callback: LogisticRegressionClassifierCallback): void;
|
||||
static load(filename: string, stemmer: Stemmer, callback: LogisticRegressionClassifierCallback): void;
|
||||
static restore(classifier: any, stemmer?: Stemmer): LogisticRegressionClassifier;
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
// Type definitions for Natural 0.2.1
|
||||
// Project: https://github.com/NaturalNode/natural
|
||||
// Definitions by: Dylan R. E. Moonfire <https://github.com/dmoonfire/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
|
||||
import natural = require('natural');
|
||||
|
||||
// Tokenizers
|
||||
@@ -59,7 +53,12 @@ classifier.addDocument('sell gold', 'sell');
|
||||
classifier.train();
|
||||
console.log(classifier.classify('i am short silver'));
|
||||
console.log(classifier.classify('i am long copper'));
|
||||
console.log(classifier.getClassifications('i am long copper'));
|
||||
var classifications = classifier.getClassifications('i am long copper');
|
||||
classifications.forEach(function(classification) {
|
||||
var label = classification.label
|
||||
var value = classification.value
|
||||
console.log('label: ' + label + ', value: ' + value)
|
||||
})
|
||||
classifier.addDocument(['sell', 'gold'], 'sell');
|
||||
classifier.events.on('trainedWithDocument', function (obj: any) {
|
||||
console.log(obj);
|
||||
|
||||
Reference in New Issue
Block a user