mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add types for bayes-classifier (#37337)
* Add types for bayes-classifier * Address review * Address review
This commit is contained in:
parent
86f1551d60
commit
537ab33583
33
types/bayes-classifier/bayes-classifier-tests.ts
Normal file
33
types/bayes-classifier/bayes-classifier-tests.ts
Normal file
@ -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 } ]
|
||||
*/
|
||||
28
types/bayes-classifier/index.d.ts
vendored
Normal file
28
types/bayes-classifier/index.d.ts
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// Type definitions for bayes-classifier 0.0
|
||||
// Project: https://github.com/miguelmota/bayes-classifier
|
||||
// Definitions by: Jason Harrison <https://github.com/jasonharrison>
|
||||
// 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;
|
||||
23
types/bayes-classifier/tsconfig.json
Normal file
23
types/bayes-classifier/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
3
types/bayes-classifier/tslint.json
Normal file
3
types/bayes-classifier/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user