diff --git a/types/bayes-classifier/bayes-classifier-tests.ts b/types/bayes-classifier/bayes-classifier-tests.ts new file mode 100644 index 0000000000..0f6a487dd3 --- /dev/null +++ b/types/bayes-classifier/bayes-classifier-tests.ts @@ -0,0 +1,33 @@ +import BayesClassifier = require('bayes-classifier'); + +const classifier = new BayesClassifier(); + +const positiveDocuments = [ + `I love tacos.`, + `Dude, that burrito was epic!`, + `Holy cow, these nachos are so good and tasty.`, + `I am drooling over the awesome bean and cheese quesadillas.`, +]; + +const negativeDocuments = [ + `Gross, worst taco ever.`, + `The buritos gave me horrible diarrhea.`, + `I'm going to puke if I eat another bad nacho.`, + `I'd rather die than eat those nasty enchiladas.`, +]; + +classifier.addDocuments(positiveDocuments, `positive`); +classifier.addDocuments(negativeDocuments, `negative`); + +classifier.train(); + +classifier.classify(`I heard the mexican restaurant is great!`); // "positive" +classifier.classify(`I don't want to eat there again.`); // "negative" +classifier.classify(`The torta is epicly bad.`); // "negative" +classifier.classify(`The torta is tasty.`); // "positive" + +classifier.getClassifications(`Burritos are the meaning of life.`); +/* + [ { label: 'positive', value: 0.22222222222222224 }, + { label: 'negative', value: 0.11111111111111112 } ] +*/ diff --git a/types/bayes-classifier/index.d.ts b/types/bayes-classifier/index.d.ts new file mode 100644 index 0000000000..66e1cf8c0c --- /dev/null +++ b/types/bayes-classifier/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for bayes-classifier 0.0 +// Project: https://github.com/miguelmota/bayes-classifier +// Definitions by: Jason Harrison +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.5 + +interface Classifications { + label: string; + value: number; +} + +declare class BayesClassifier { + constructor(); + + addDocument(doc: string, label: string): void; + + addDocuments(docs: string[], label: string): void; + + classify(doc: string): string; + + getClassifications(doc: string): Classifications; + + restore(classifier: any): void; + + train(): void; +} + +export = BayesClassifier; diff --git a/types/bayes-classifier/tsconfig.json b/types/bayes-classifier/tsconfig.json new file mode 100644 index 0000000000..75da2240b0 --- /dev/null +++ b/types/bayes-classifier/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "bayes-classifier-tests.ts" + ] +} diff --git a/types/bayes-classifier/tslint.json b/types/bayes-classifier/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/bayes-classifier/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}