Socket
Socket
Sign inDemoInstall

whichx

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

15

assets/scripts/whichx.js

@@ -94,2 +94,17 @@ // Defining the Whichx object.

// Exports the WhichX internal data representation learned from provided
// labeled text. Please see th typesMap comments for more details.
this.export = function() {
return typesMap;
};
// Imports a previously exported typesMap. This will write over any data this instance has already learned.
this.import = function(importedTypesMap) {
var newTotal = importedTypesMap.total;
if (newTotal === "undefined" || newTotal.tcount === "undefined" || newTotal.wordTotal === "undefined") {
throw new Error("Import invalid. This doesn't look like it was exported from a prior model.");
}
typesMap = importedTypesMap;
};
// Loop through words and work out probability of type given each word.

@@ -96,0 +111,0 @@ // Multiply each word's probability by total probability to determine type probability.

15

package.json
{
"name": "whichx",
"version": "2.0.0",
"version": "2.1.0",
"description": "A text description classifier for classifying arbitrary strings into provided labels",

@@ -16,5 +16,14 @@ "main": "whichx.js",

"keywords": [
"naive",
"bayes",
"text",
"bayes",
"classifier"
"classifier",
"machine-learning",
"nlp",
"natural-language-processing",
"bayesian",
"text-classifier",
"bayes-classifier",
"naive-bayes-classification",
"natural-language"
],

@@ -21,0 +30,0 @@ "author": "Rudi Kershaw <alexander_kershaw@hotmail.co.uk> (http://www.rudikershaw.com)",

45

test/tests.js

@@ -5,3 +5,22 @@ (function(){

var Whichx = require("../assets/scripts/whichx.js");
var classificationAssertions = function(classifier) {
it("should classify text 'correctly'", function() {
assert.equal(classifier.classify("sits"), "cat");
assert.equal(classifier.classify("bark"), "dog");
classifier.addData("dog", "sits sits");
assert.equal(classifier.classify("sits"), "dog");
});
it("should classify by most instances when unsure", function() {
classifier.addData("dog", "test");
assert.equal(classifier.classify("never"), "dog");
});
it("should not be confused by unknown words", function() {
assert.equal(classifier.classify("meow unknown"), "cat");
});
};
describe("Whichx", function() {

@@ -105,20 +124,20 @@

it("should classify text 'correctly'", function() {
assert.equal(classifier.classify("sits"), "cat");
assert.equal(classifier.classify("bark"), "dog");
classificationAssertions(classifier);
});
classifier.addData("dog", "sits sits");
assert.equal(classifier.classify("sits"), "dog");
});
describe("imported export", function() {
var classifier = new Whichx();
var validLabels = ["cat", "dog"];
var dataExport;
it("should classify by most instances when unsure", function() {
classifier.addData("dog", "test");
assert.equal(classifier.classify("never"), "dog");
});
classifier.addLabels(validLabels);
classifier.addData("cat", "meow purr sits on lap");
classifier.addData("dog", "bark woof wag fetch");
dataExport = classifier.export();
classifier = new Whichx();
classifier.import(dataExport);
it("should not be confused by unknown words", function() {
assert.equal(classifier.classify("meow unknown"), "cat");
});
classificationAssertions(classifier);
});
});
})();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc