whichx
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -11,3 +11,3 @@ // Defining the Whichx object. | ||
// Total must exist and be incremented for probability calculations. | ||
"total": { "tcount": 0, "wordTotal": 0 } | ||
"total": { "tcount": 0, "wordTotal": 1 } | ||
}; | ||
@@ -38,4 +38,4 @@ | ||
if (label in typesMap && typeof description === "string") { | ||
type = typesMap[label]; | ||
if (label.toLowerCase() in typesMap && typeof description === "string") { | ||
type = typesMap[label.toLowerCase()]; | ||
type.tcount = type.tcount + 1; | ||
@@ -75,4 +75,4 @@ total.tcount = total.tcount + 1; | ||
wordArray = processToArray(description); | ||
bestChance = 0; | ||
bestLabel = "pet"; | ||
bestChance = -1; | ||
bestLabel = undefined; | ||
@@ -98,3 +98,3 @@ // Loop through types working out the chance of the description being | ||
// Exports the WhichX internal data representation learned from provided | ||
// labeled text. Please see th typesMap comments for more details. | ||
// labeled text. Please see the typesMap comments for more details. | ||
this.export = function() { | ||
@@ -101,0 +101,0 @@ return typesMap; |
{ | ||
"name": "whichx", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "A text description classifier for classifying arbitrary strings into provided labels", | ||
@@ -5,0 +5,0 @@ "main": "assets/scripts/whichx.js", |
@@ -48,2 +48,6 @@ (function(){ | ||
}); | ||
it("object should have default classify value", function() { | ||
assert.equal(classifier.classify("no labels"), undefined); | ||
}); | ||
}); | ||
@@ -118,2 +122,9 @@ | ||
classificationAssertions(classifier); | ||
it("should successfully classify with only 1 label", function() { | ||
classifier = new Whichx(); | ||
classifier.addLabels("pokemon"); | ||
classifier.addData("pokemon", "pikachu yellow lightning"); | ||
assert.equal(classifier.classify("pokemanz?"), "pokemon"); | ||
}); | ||
}); | ||
@@ -120,0 +131,0 @@ |
42622
407