bravey
Version:
A simple JavaScript NLP-like library to help you creating your own bot.
1,794 lines (1,616 loc) • 94.7 kB
JavaScript
var TestTools = {
SECOND: 1000,
MINUTE: 60000,
HOUR: 60000 * 60,
DAY: 60000 * 60 * 24,
formatDate: function(timestamp) {
var myDate = new Date(timestamp);
return myDate.getFullYear() + "-" + this.pad(myDate.getMonth() + 1, 2) + "-" + this.pad(myDate.getDate(), 2);
},
formatTime: function(time) {
return this.pad(Math.floor(time / this.HOUR), 2) + ":" + this.pad(Math.floor((time % this.HOUR) / this.MINUTE), 2) + ":" + this.pad(Math.floor((time % this.MINUTE) / this.SECOND), 2);
},
getYear: function() {
var myDate = new Date();
return myDate.getFullYear();
},
getMonth: function() {
var myDate = new Date();
return this.pad(myDate.getMonth() + 1, 2);
},
getLastDay: function(month, day) {
day = day * 1;
month = month * 1;
var myDate = new Date();
var y = myDate.getFullYear() * 1;
var m = myDate.getMonth() + 1;
var d = myDate.getDate() * 1;
if (month > m)
return (y - 1) + "-" + this.pad(month, 2) + "-" + this.pad(day, 2);
else
return (y) + "-" + this.pad(month, 2) + "-" + this.pad(day, 2);
},
getNextDay: function(month, day) {
day = day * 1;
month = month * 1;
var myDate = new Date();
var y = myDate.getFullYear() * 1;
var m = myDate.getMonth() + 1;
var d = myDate.getDate() * 1;
if (month < m)
return (y - 1) + "-" + this.pad(month, 2) + "-" + this.pad(day, 2);
else
return (y) + "-" + this.pad(month, 2) + "-" + this.pad(day, 2);
},
pad: function(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
},
nlpTest: function(assert, nlp, text, intent, entities, mode) {
var r = nlp.test(text, mode, "Ask " + text);
if (intent == false)
assert.strictEqual(r, false, text + " must not match.");
else {
assert.strictEqual(r.intent, intent, text + " must match intent " + intent);
for (var a in entities) {
assert.ok(r.entitiesIndex[a] !== undefined, "Must have entity " + a);
assert.deepEqual(r.entitiesIndex[a].value, entities[a], "Must have entity " + a + " = " + JSON.stringify(entities[a]));
}
}
},
nlpAddDocument: function(assert, nlp, text, intent, mods, expected) {
assert.strictEqual(nlp.addDocument(text, intent, mods), expected, "Adding document: " + text + " -> " + expected);
if (mods && mods.fromFullSentence) {
var match = nlp.test(text);
assert.strictEqual(match.intent, intent, text + " must match its intent " + intent);
}
},
nlpClassifyDocument: function(assert, nlp, text, intent) {
assert.strictEqual(nlp.addDocument(text, intent), text, "Adding document: " + text);
var match = nlp.classifyDocument(text);
assert.strictEqual(match.winner.label, intent, text + " must match its intent " + intent);
}
};
// Text
QUnit.test("Text.generateGUID", function(assert) {
var guid = Bravey.Text.generateGUID();
assert.ok(guid.match(/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/g), "GUID format is correct");
});
QUnit.test("Text.clean", function(assert) {
assert.strictEqual(Bravey.Text.clean(" this IS a {tag}*! tòàst Iлtèrnåtïonɑlíƶatï߀ԉ "), "this is a {tag}*! toast internationalizati0n", "Misc accents and consecutive spaces stripped");
});
QUnit.test("Text.pad", function(assert) {
assert.strictEqual(Bravey.Text.pad(12, 1), "12", "Padded number can be longer than specified");
assert.strictEqual(Bravey.Text.pad(12, 2), "12", "Padded number is log as specified");
assert.strictEqual(Bravey.Text.pad(12, 3), "012", "Padding symbols are added");
assert.strictEqual(Bravey.Text.pad(12, 5, "*"), "***12", "Can specify padding symbol");
});
QUnit.test("Text.unique", function(assert) {
assert.deepEqual(Bravey.Text.unique(["1", "2", "3", "4"]), ["1", "2", "3", "4"], "Unique arrays are kept as-is");
assert.deepEqual(Bravey.Text.unique(["1", "2", "2", "4"]), ["1", "2", "4"], "Equal elements are uniqued");
assert.deepEqual(Bravey.Text.unique(["1", "2", "3", "3"]), ["1", "2", "3"], "Equal last elements are uniqued");
assert.deepEqual(Bravey.Text.unique(["1", "1", "3", "4"]), ["1", "3", "4"], "Equal first elements are uniqued");
});
QUnit.test("Text.RegexMap", function(assert) {
var match, iteration = 0;
var reg = new Bravey.Text.RegexMap([{
str: ["ciao"],
val: "Hello1!"
}, {
str: ["welcome"],
val: "Hello2!"
}], "default1");
var reg2 = new Bravey.Text.RegexMap([{
str: ["va"],
val: "andare1!"
}, {
str: ["andale"],
val: "andare2!"
}], "default2");
var find = new RegExp(reg.regex() + "[^(va)]*" + reg2.regex(1), "gi");
var s = "ciao come va? Welcome! Come andale!";
while ((match = find.exec(s)) != null) {
iteration++;
switch (iteration) {
case 1:
{
assert.strictEqual(reg.get(match, 1), "Hello1!", "reg must match");
assert.strictEqual(reg2.get(match, 2), "andare1!", "reg2 must match");
break;
}
case 2:
{
assert.strictEqual(reg.get(match, 1), "default1", "reg must match");
assert.strictEqual(reg2.get(match, 2), "andare2!", "reg2 must match");
break;
}
}
}
assert.strictEqual(iteration, 2, "Iterations number must be correct");
reg = new Bravey.Text.RegexMap([{
str: ["~bar", "~foo"],
val: "is matched!"
}], "default1");
find = new RegExp(reg.regex(1), "gi");
s = "bar foobar foo barfoo afoobara endfoo endbar";
var matches = 0;
while ((match = find.exec(s)) != null) matches++;
assert.strictEqual(matches, 4, "Matched only when word starts");
reg = new Bravey.Text.RegexMap([{
str: ["bar~", "foo~"],
val: "is matched!"
}], "default1");
find = new RegExp(reg.regex(1), "gi");
matches = 0;
while ((match = find.exec(s)) != null) matches++;
assert.strictEqual(matches, 6, "Matched only when word ends");
reg = new Bravey.Text.RegexMap([{
str: ["~bar~", "~foo~"],
val: "is matched!"
}], "default1");
find = new RegExp(reg.regex(1), "gi");
matches = 0;
while ((match = find.exec(s)) != null) matches++;
assert.strictEqual(matches, 2, "Matched only when whole words");
find = new RegExp("afoobara " + reg.regex(), "gi");
matches = 0;
while ((match = find.exec(s)) != null) {
matches++;
assert.strictEqual(reg.get(match, 1, "default2"), "default2", "Per-call defaults must be correct");
}
assert.strictEqual(matches, 1, "Not-obligatory parts must be valid");
});
QUnit.test("Text.removeDiacritics", function(assert) {
assert.strictEqual(Bravey.Text.removeDiacritics("Iлtèrnåtïonɑlíƶatï߀ԉ"), "Internationalizati0n", "Accents are replaced");
assert.strictEqual(Bravey.Text.removeDiacritics("Båcòл ípѕùm ðoɭ߀r ѕït aϻèt âùþê aԉᏧ߀üïlɭê ƃëéf culρá fïlèt ϻiǥnòn cuρiᏧatat ut êлim tòлɢùê."), "Bacon ipѕum dhol0r ѕit aMet authe and0uille beef culpa filet Mignon cupidatat ut enim tonGue.", "Complex accents must be replaced");
assert.strictEqual(Bravey.Text.removeDiacritics("ᴎᴑᴅᴇȷʂ"), "NoDEJs", "Complex accents must be replaced");
assert.strictEqual(Bravey.Text.removeDiacritics("hambúrguer"), "hamburguer", "Complex accents must be replaced");
assert.strictEqual(Bravey.Text.removeDiacritics("hŒllœ"), "hOElloe", "Complex accents must be replaced");
assert.strictEqual(Bravey.Text.removeDiacritics("Fußball"), "Fussball", "Complex accents must be replaced");
assert.strictEqual(Bravey.Text.removeDiacritics("ABCDEFGHIJKLMNOPQRSTUVWXYZé"), "ABCDEFGHIJKLMNOPQRSTUVWXYZe", "Not-diacritics letters are kept as-is");
});
QUnit.test("Text.tokenize", function(assert) {
assert.deepEqual(Bravey.Text.tokenize("The Dog is on the table!"), ["The", "Dog", "is", "on", "the", "table"], "Strings are tokenized");
});
QUnit.test("Text.calculateScore", function(assert) {
var splits = ["", "the", "", "dog"];
assert.deepEqual(Bravey.Text.calculateScore(splits, []), 0, "No score set = 0");
assert.deepEqual(Bravey.Text.calculateScore(splits, [-1, 10]), 0, "Out = 0");
assert.deepEqual(Bravey.Text.calculateScore(splits, [0, 2]), 0, "Empty spaces = 0");
assert.deepEqual(Bravey.Text.calculateScore(splits, [0, 1]), 1, "One point = 1");
assert.deepEqual(Bravey.Text.calculateScore(splits, [0, 1, 2]), 1, "One point = 1");
assert.deepEqual(Bravey.Text.calculateScore(splits, [0, 1, 2, 3]), 2, "Two points = 2");
});
QUnit.test("Text.entityTrim", function(assert) {
assert.deepEqual(Bravey.Text.entityTrim({
string: "hello",
position: 0
}), {
string: "hello",
position: 0
}, "No trim needed");
assert.deepEqual(Bravey.Text.entityTrim({
string: ", hello",
position: 0
}), {
string: "hello",
position: 2
}, "Trim left");
assert.deepEqual(Bravey.Text.entityTrim({
string: "hello , , ",
position: 0
}), {
string: "hello",
position: 0
}, "Trim right");
assert.deepEqual(Bravey.Text.entityTrim({
string: ", , ,hello , , ",
position: 0
}), {
string: "hello",
position: 5
}, "Trim both");
});
// Date
QUnit.test("Date.formatDate", function(assert) {
assert.strictEqual(TestTools.formatDate(1463138813392), "2016-05-13", "Dates are formatted correctly");
assert.strictEqual(TestTools.formatDate(1463138813392 + TestTools.DAY), "2016-05-14", "Dates are formatted correctly");
});
// File
QUnit.test("File.load", function(assert) {
var done1 = assert.async();
var done2 = assert.async();
Bravey.File.load("test-data/test.json", function(text) {
assert.deepEqual(text, "{\"loaded\":\"ok\"}", "Files are loaded successfully");
done1();
});
Bravey.File.load("test-data/notfoundtest.json", function(text) {
assert.deepEqual(text, undefined, "File not found returns undefined");
done2();
});
});
// Data
QUnit.test("Data.getEntityValue", function(assert) {
assert.deepEqual(Bravey.Data.getEntityValue({
result: false
}, "test"), undefined, "No match and no session = no data");
assert.deepEqual(Bravey.Data.getEntityValue({
result: {
entitiesIndes: {}
}
}, "test"), undefined, "Match with no entity and no session = no data");
assert.deepEqual(Bravey.Data.getEntityValue({
result: false,
sessionData: {
foo: "bar"
}
}, "test"), undefined, "No match and session with no data = no data");
assert.deepEqual(Bravey.Data.getEntityValue({
result: false,
sessionData: {
foo: "bar",
test: "found"
}
}, "test"), "found", "No match and session with data = session data");
assert.deepEqual(Bravey.Data.getEntityValue({
result: {
entitiesIndex: {}
},
sessionData: {
foo: "bar",
test: "found"
}
}, "test"), "found", "Match with no entity and session with data = session data");
assert.deepEqual(Bravey.Data.getEntityValue({
result: {
entitiesIndex: {
test: {
value: "found2"
}
}
},
sessionData: {
foo: "bar",
test: "found"
}
}, "test"), "found2", "Match with entity and session with data = entity data");
assert.deepEqual(Bravey.Data.getEntityValue({
result: {
entitiesIndex: {
test: {
value: "found2"
}
}
},
sessionData: {
foo: "bar",
test: "found"
}
}, "test", "found2"), "found", "Match with entity and session with data, default override = session data");
});
// NumberEntityRecognizer
QUnit.test("NumberEntityRecognizer", function(assert) {
var reg = new Bravey.NumberEntityRecognizer("test");
assert.deepEqual(reg.getEntities("these12 are not 12numbers but this 12 is a full number! y0u can b3t it that 24 is a number!"), [{
"position": 35,
"entity": "test",
"value": 12,
"string": "12"
}, {
"position": 76,
"entity": "test",
"value": 24,
"string": "24"
}], "Multiple numbers are matched");
assert.deepEqual(reg.getEntities("12"), [{
"entity": "test",
"position": 0,
"string": "12",
"value": 12
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asd 12"), [{
"entity": "test",
"position": 4,
"string": "12",
"value": 12
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("12 asd"), [{
"entity": "test",
"position": 0,
"string": "12",
"value": 12
}], "First entities are matched");
assert.deepEqual(reg.getEntities("12 34 48"), [{
"entity": "test",
"position": 0,
"string": "12",
"value": 12
}, {
"entity": "test",
"position": 3,
"string": "34",
"value": 34
}, {
"entity": "test",
"position": 6,
"string": "48",
"value": 48
}], "Consecutive entities are matched");
});
// EMailEntityRecognizer
QUnit.test("EMailEntityRecognizer", function(assert) {
var reg = new Bravey.EMailEntityRecognizer("test");
assert.deepEqual(reg.getEntities("this@is a test of how it.should@match.com the email@@ add@resses. a@b.c foo.bar@domain.z this one is name.surname@domain.cc"), [{
"entity": "test",
"position": 22,
"priority": 0,
"string": "it.should@match.com",
"value": "it.should@match.com"
}, {
"entity": "test",
"position": 101,
"priority": 0,
"string": "name.surname@domain.cc",
"value": "name.surname@domain.cc"
}], "Multiple addresses are matched");
assert.deepEqual(reg.getEntities("name.surname@domain.cc"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "name.surname@domain.cc",
"value": "name.surname@domain.cc"
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asd name.surname@domain.cc"), [{
"entity": "test",
"position": 4,
"priority": 0,
"string": "name.surname@domain.cc",
"value": "name.surname@domain.cc"
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("name.surname@domain.cc asd"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "name.surname@domain.cc",
"value": "name.surname@domain.cc"
}], "First entities are matched");
assert.deepEqual(reg.getEntities("name.surname@domain.cc name2.surname@domain.cc name.surname2@domain.cc"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "name.surname@domain.cc",
"value": "name.surname@domain.cc"
}, {
"entity": "test",
"position": 23,
"priority": 0,
"string": "name2.surname@domain.cc",
"value": "name2.surname@domain.cc"
}, {
"entity": "test",
"position": 47,
"priority": 0,
"string": "name.surname2@domain.cc",
"value": "name.surname2@domain.cc"
}], "Consecutive entities are matched");
});
// StringEntityRecognizer
QUnit.test("StringEntityRecognizer", function(assert) {
var reg = new Bravey.StringEntityRecognizer("test");
reg.addMatch("logo", "apple");
reg.addMatch("ny", "big apple");
reg.addMatch("fruit", "pineapple");
assert.deepEqual(reg.getEntities("This pineapple works for Apple in the Big Apple, did you know?"), [{
"entity": "test",
"position": 38,
"priority": 0,
"string": "big apple",
"value": "ny"
}, {
"entity": "test",
"position": 5,
"priority": 0,
"string": "pineapple",
"value": "fruit"
}, {
"entity": "test",
"position": 25,
"priority": 0,
"string": "apple",
"value": "logo"
}], "Multiple strings are matched");
assert.deepEqual(reg.getEntities("apple"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "apple",
"value": "logo"
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asd apple"), [{
"entity": "test",
"position": 4,
"priority": 0,
"string": "apple",
"value": "logo"
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("apple asd"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "apple",
"value": "logo"
}], "First entities are matched");
assert.deepEqual(reg.getEntities("apple big apple apple pineapple"), [{
"entity": "test",
"position": 6,
"priority": 0,
"string": "big apple",
"value": "ny"
}, {
"entity": "test",
"position": 22,
"priority": 0,
"string": "pineapple",
"value": "fruit"
}, {
"entity": "test",
"position": 0,
"priority": 0,
"string": "apple",
"value": "logo"
}, {
"entity": "test",
"position": 16,
"priority": 0,
"string": "apple",
"value": "logo"
}], "Consecutive entities are matched");
var reg = new Bravey.StringEntityRecognizer("test", 10);
reg.addMatch("logo", "apple");
reg.addMatch("ny", "big apple");
reg.addMatch("fruit", "pineapple");
assert.deepEqual(reg.getEntities("apple asd"), [{
"entity": "test",
"position": 0,
"priority": 10,
"string": "apple",
"value": "logo"
}], "Priority is kept");
});
// RegexEntityRecognizer
QUnit.test("RegexEntityRecognizer", function(assert) {
var reg = new Bravey.RegexEntityRecognizer("test");
reg.addMatch(new RegExp("\\b([0-9]+)\\b", "g"), function(match) {
return "the number is " + match[1]
});
reg.addMatch(new RegExp("\\btime is ([0-9]+)\\b", "g"), function(match) {
return "the time is " + match[1]
});
assert.deepEqual(
reg.getEntities("This is a number 12 but when the time is now, is when the time is 14 o'clock. this is spaced time is 12. This is dirty Timé is 45. Nowatime is 38"), [{
"entity": "test",
"position": 17,
"priority": 0,
"string": "12",
"value": "the number is 12"
}, {
"entity": "test",
"position": 58,
"priority": 0,
"string": "time is 14",
"value": "the time is 14"
}, {
"entity": "test",
"position": 93,
"priority": 0,
"string": "time is 12",
"value": "the time is 12"
}, {
"entity": "test",
"position": 119,
"priority": 0,
"string": "time is 45",
"value": "the time is 45"
}, {
"entity": "test",
"position": 143,
"priority": 0,
"string": "38",
"value": "the number is 38"
}], "Stacked regex are matched as cleaned text. Longest match first");
assert.deepEqual(reg.getEntities("12"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "12",
"value": "the number is 12"
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asd 12"), [{
"entity": "test",
"position": 4,
"priority": 0,
"string": "12",
"value": "the number is 12"
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("12 asd"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "12",
"value": "the number is 12"
}], "First entities are matched");
assert.deepEqual(reg.getEntities("21 28 35"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "21",
"value": "the number is 21"
}, {
"entity": "test",
"position": 3,
"priority": 0,
"string": "28",
"value": "the number is 28"
}, {
"entity": "test",
"position": 6,
"priority": 0,
"string": "35",
"value": "the number is 35"
}], "Consecutive entities are matched");
});
// Filter
QUnit.test("Filter.BasicFilter", function(assert) {
var filter = Bravey.Filter.BasicFilter;
assert.deepEqual(filter(["I", "am", "the", "king", "of", "the", "hill", "tomorrow", "will", "be", "mine"]), [
"king",
"hill",
"tomorrow",
"will",
"mine"
], "Short words are removed");
assert.deepEqual(filter(["one", "two", "is"]), [
"one",
"two",
"is"
], "Empty list returns the original list");
assert.deepEqual(filter(["I", "am", "the", "king", "of", "the", "hill"]), [
"I",
"am",
"the",
"king",
"of",
"the",
"hill"
], "Short filtered lists are kept");
assert.deepEqual(filter(["{greet}", "this", "{year}", "we", "will", "go", "to", "{location}", "tomorrow", "will", "be", "mine"]), [
"this",
"will",
"tomorrow",
"will",
"mine"
], "Entities are removed");
assert.deepEqual(filter(["{ignore}", "one", "two", "is", "{me}"]), [
"{ignore}",
"one",
"two",
"is",
"{me}"
], "Empty list returns the original list (with entities");
});
// English
QUnit.test("EN.Stemmer", function(assert) {
assert.deepEqual(Bravey.Language.EN.Stemmer("dog"), "dog", "Singulars are correctly stemmed");
assert.deepEqual(Bravey.Language.EN.Stemmer("dogs"), "dog", "Plurals is correctly stemmed");
assert.deepEqual(Bravey.Language.EN.Stemmer("takes"), "take", "Passives are correctly stemmed");
});
QUnit.test("EN.TimeEntityRecognizer", function(assert) {
var reg = new Bravey.Language.EN.TimeEntityRecognizer("test");
assert.deepEqual(reg.getEntities("quarter past 9"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "quarter past 9",
"value": "09:15:00"
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asf quarter past 9"), [{
"entity": "test",
"position": 4,
"priority": 0,
"string": "quarter past 9",
"value": "09:15:00"
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("quarter past 9 asd"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "quarter past 9",
"value": "09:15:00"
}], "First entities are matched");
assert.deepEqual(reg.getEntities("We'll see at 12 and 5 minutes, the 8:20 or at 3 o'clock. We can always meet at 8, half past 8 or a quarter past 9."), [{
"entity": "test",
"position": 10,
"priority": 0,
"string": "at 12 and 5 minutes",
"value": "12:05:00"
}, {
"entity": "test",
"position": 35,
"priority": 0,
"string": "8:20",
"value": "08:20:00"
}, {
"entity": "test",
"position": 43,
"priority": 0,
"string": "at 3 o'clock",
"value": "03:00:00"
}, {
"entity": "test",
"position": 76,
"priority": 0,
"string": "at 8",
"value": "08:00:00"
}, {
"entity": "test",
"position": 82,
"priority": 0,
"string": "half past 8",
"value": "08:30:00"
}, {
"entity": "test",
"position": 99,
"priority": 0,
"string": "quarter past 9",
"value": "09:15:00"
}], "Multiple tiles are matched");
assert.deepEqual(reg.getEntities("3, at 3, at 3pm, quarter past 6pm, 8 and 20 minutes in the afternoon, 3 o'clock, 12:20, half past 10pm"), [{
"entity": "test",
"position": 3,
"priority": 0,
"string": "at 3",
"value": "03:00:00"
}, {
"entity": "test",
"position": 9,
"priority": 0,
"string": "at 3pm",
"value": "15:00:00"
}, {
"entity": "test",
"position": 17,
"priority": 0,
"string": "quarter past 6pm",
"value": "18:15:00"
}, {
"entity": "test",
"position": 35,
"priority": 0,
"string": "8 and 20 minutes in the afternoon",
"value": "20:20:00"
}, {
"entity": "test",
"position": 70,
"priority": 0,
"string": "3 o'clock",
"value": "03:00:00"
}, {
"entity": "test",
"position": 81,
"priority": 0,
"string": "12:20",
"value": "12:20:00"
}, {
"entity": "test",
"position": 88,
"priority": 0,
"string": "half past 10pm",
"value": "22:30:00"
}],
"Multiple tiles are matched");
});
QUnit.test("EN.TimePeriodEntityRecognizer", function(assert) {
var date = new Date();
var now = (date.getHours() * Bravey.Date.HOUR) + (date.getMinutes() * Bravey.Date.MINUTE);
var reg = new Bravey.Language.EN.TimePeriodEntityRecognizer("test");
assert.deepEqual(reg.getEntities("in 20 minutes"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "in 20 minutes",
"value": {
"end": TestTools.formatTime(now + (20 * TestTools.MINUTE)),
"start": TestTools.formatTime(now)
}
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asf in 20 minutes"), [{
"entity": "test",
"position": 4,
"priority": 0,
"string": "in 20 minutes",
"value": {
"end": TestTools.formatTime(now + (20 * TestTools.MINUTE)),
"start": TestTools.formatTime(now)
}
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("in 20 minutes asd"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "in 20 minutes",
"value": {
"end": TestTools.formatTime(now + (20 * TestTools.MINUTE)),
"start": TestTools.formatTime(now)
}
}], "First entities are matched");
assert.deepEqual(reg.getEntities("We'll see together in the morning or this afternoon. I'll pass there during the morning or in the evening. We'll go in 20 minutes. In 2 hours will happen."), [{
"entity": "test",
"position": 19,
"priority": 0,
"string": "in the morning",
"value": {
"end": "12:00:00",
"start": "08:00:00"
}
}, {
"entity": "test",
"position": 37,
"priority": 0,
"string": "this afternoon",
"value": {
"end": "23:59:00",
"start": "15:00:00"
}
}, {
"entity": "test",
"position": 80,
"priority": 0,
"string": "morning",
"value": {
"end": "12:00:00",
"start": "08:00:00"
}
}, {
"entity": "test",
"position": 91,
"priority": 0,
"string": "in the evening",
"value": {
"end": "23:59:00",
"start": "12:00:00"
}
}, {
"entity": "test",
"position": 116,
"priority": 0,
"string": "in 20 minutes",
"value": {
"end": TestTools.formatTime(now + (20 * TestTools.MINUTE)),
"start": TestTools.formatTime(now)
}
}, {
"entity": "test",
"position": 131,
"priority": 0,
"string": "in 2 hours",
"value": {
"end": TestTools.formatTime(now + (2 * TestTools.HOUR)),
"start": TestTools.formatTime(now)
}
}], "Multiple time ranges are matched");
});
QUnit.test("EN.DateEntityRecognizer", function(assert) {
var reg = new Bravey.Language.EN.DateEntityRecognizer("test");
assert.deepEqual(reg.getEntities("12 november 2016"), [{
"entity": "test",
"position": 0,
"priority": 10,
"string": "12 november 2016",
"value": "2016-11-12"
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asf 12 november 2016"), [{
"entity": "test",
"position": 4,
"priority": 10,
"string": "12 november 2016",
"value": "2016-11-12"
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("12 november 2016 asd"), [{
"entity": "test",
"position": 0,
"priority": 10,
"string": "12 november 2016",
"value": "2016-11-12"
}], "First entities are matched");
assert.deepEqual(reg.getEntities("We're going to end this tomorrow or during today. We should finish for yesterday, you know. 1st of april we must prepare a joke! 12 november 2016 is a date, you know?"), [{
"entity": "test",
"position": 24,
"priority": 0,
"string": "tomorrow",
"value": TestTools.formatDate((new Date()).getTime() + TestTools.DAY)
}, {
"entity": "test",
"position": 43,
"priority": 0,
"string": "today",
"value": TestTools.formatDate((new Date()).getTime())
}, {
"entity": "test",
"position": 71,
"priority": 0,
"string": "yesterday",
"value": TestTools.formatDate((new Date()).getTime() - TestTools.DAY),
}, {
"entity": "test",
"position": 92,
"priority": 10,
"string": "1st of april",
"value": TestTools.getYear() + "-04-01"
}, {
"entity": "test",
"position": 129,
"priority": 10,
"string": "12 november 2016",
"value": "2016-11-12"
}],
"Multiple dates are matched"
);
assert.deepEqual(reg.getEntities("last February, last Feb, last January, last March 8th, last February 1ST, last February 15! 06/01/2014, 12/01/2014, 06/01/15, June 1, 2014, December 1, 2014"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "last february",
"value": TestTools.getLastDay(2, 1)
}, {
"entity": "test",
"position": 15,
"priority": 0,
"string": "last feb",
"value": TestTools.getLastDay(2, 1)
}, {
"entity": "test",
"position": 25,
"priority": 0,
"string": "last january",
"value": TestTools.getLastDay(1, 1)
}, {
"entity": "test",
"position": 39,
"priority": 0,
"string": "last march 8th",
"value": TestTools.getLastDay(3, 8)
}, {
"entity": "test",
"position": 55,
"priority": 0,
"string": "last february 1st",
"value": TestTools.getLastDay(2, 1)
}, {
"entity": "test",
"position": 74,
"priority": 0,
"string": "last february 15",
"value": TestTools.getLastDay(2, 15)
}, {
"entity": "test",
"position": 92,
"priority": 10,
"string": "06/01/2014",
"value": "2014-01-06"
}, {
"entity": "test",
"position": 104,
"priority": 10,
"string": "12/01/2014",
"value": "2014-01-12"
}, {
"entity": "test",
"position": 116,
"priority": 10,
"string": "06/01/15",
"value": "2015-01-06"
}, {
"entity": "test",
"position": 126,
"priority": 0,
"string": "june 1, 2014",
"value": "2014-06-01"
}, {
"entity": "test",
"position": 140,
"priority": 0,
"string": "december 1, 2014",
"value": "2014-12-01"
}], "Complex multiple date are matched");
});
QUnit.test("EN.NumberEntityRecognizer", function(assert) {
var reg = new Bravey.Language.EN.NumberEntityRecognizer("test");
assert.deepEqual(reg.getEntities("ten"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "ten",
"value": 10
}], "Single numbers are matched");
assert.deepEqual(reg.getEntities("two hundred fifteen"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "two hundred fifteen",
"value": 215
}], "two hundred fifteen -> 215");
assert.deepEqual(reg.getEntities("two hundred, fifteen"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "two hundred",
"value": 200
}, {
"entity": "test",
"position": 13,
"priority": 0,
"string": "fifteen",
"value": 15
}], "two hundred, fifteen -> 200, 15");
assert.deepEqual(reg.getEntities("215"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "215",
"value": 215
}], "215 -> 215");
assert.deepEqual(reg.getEntities("200 15"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "200",
"value": 200
}, {
"entity": "test",
"position": 4,
"priority": 0,
"string": "15",
"value": 15
}], "200 15 -> 200, 15");
assert.deepEqual(reg.getEntities("the last chievo game 2016 2017"), [{
"entity": "test",
"position": 21,
"priority": 0,
"string": "2016",
"value": 2016
}, {
"entity": "test",
"position": 26,
"priority": 0,
"string": "2017",
"value": 2017
}], "Numbers at end");
assert.deepEqual(reg.getEntities("there are 12 apples, thirteen pears and one million eight hundred twenty thousand six hundred fifteen peppers"), [{
"entity": "test",
"position": 10,
"priority": 0,
"string": "12",
"value": 12
}, {
"entity": "test",
"position": 21,
"priority": 0,
"string": "thirteen",
"value": 13
}, {
"entity": "test",
"position": 40,
"priority": 0,
"string": "one million eight hundred twenty thousand six hundred fifteen",
"value": 1820615
}], "Multiple numbers are matched (english numbers are still not matched.");
});
// Italian
QUnit.test("IT.Stemmer", function(assert) {
assert.deepEqual(Bravey.Language.IT.Stemmer("cani"), "can", "Singulars are correctly stemmed");
assert.deepEqual(Bravey.Language.IT.Stemmer("cane"), "can", "Pluralrs are correctly stemmed");
assert.deepEqual(Bravey.Language.IT.Stemmer("canini"), "canin", "Variants are correctly stemmed");
assert.deepEqual(Bravey.Language.IT.Stemmer("canoni"), "canon", "Variants are correctly stemmed");
assert.deepEqual(Bravey.Language.IT.Stemmer("prendono"), "prend", "Verbs are correctly stemmed");
assert.deepEqual(Bravey.Language.IT.Stemmer("prenderono"), "prend", "Verbs are correctly stemmed");
assert.deepEqual(Bravey.Language.IT.Stemmer("prenderanno"), "prend", "Verbs are correctly stemmed");
});
QUnit.test("Nlp.Fuzzy + Mixed Regex Recognizers", function(assert) {
var nlp = new Bravey.Nlp.Fuzzy("test");
var numberRegexp = new RegExp("\\b([0-9]+)\\b", "g");
var timeRegexp = new RegExp("\\btime is ([0-9]+)\\b", "g");
var dateEntity = new Bravey.Language.EN.DateEntityRecognizer("dateEntity");
nlp.addEntity(dateEntity);
TestTools.nlpAddDocument(assert, nlp, "We will meet at 12 january 2017", "mixmatch", {
fromFullSentence: true,
expandIntent: true
}, "we will meet at {dateEntity}");
TestTools.nlpAddDocument(assert, nlp, "See you 22 february 2016, ok?", "mixmatch", {
fromFullSentence: true,
expandIntent: true
}, "see you {dateEntity}, ok?");
});
QUnit.test("IT.TimeEntityRecognizer", function(assert) {
var reg = new Bravey.Language.IT.TimeEntityRecognizer("test");
assert.deepEqual(reg.getEntities("alle 3"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "alle 3",
"value": "03:00:00"
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asf alle 3"), [{
"entity": "test",
"position": 4,
"priority": 0,
"string": "alle 3",
"value": "03:00:00"
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("alle 3 asd"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "alle 3",
"value": "03:00:00"
}], "First entities are matched");
assert.deepEqual(reg.getEntities("Ci vediamo per le 12 e 5, le 8:20 oppure alle 3. Nel caso non ci sia possiamo fare alle 8, le 8 e mezza o le 9 e un quarto."), [{
"entity": "test",
"position": 11,
"priority": 0,
"string": "per le 12 e 5",
"value": "12:05:00"
}, {
"entity": "test",
"position": 26,
"priority": 0,
"string": "le 8:20",
"value": "08:20:00"
}, {
"entity": "test",
"position": 41,
"priority": 0,
"string": "alle 3",
"value": "03:00:00"
}, {
"entity": "test",
"position": 83,
"priority": 0,
"string": "alle 8",
"value": "08:00:00"
}, {
"entity": "test",
"position": 91,
"priority": 0,
"string": "le 8 e mezza",
"value": "08:30:00"
}, {
"entity": "test",
"position": 106,
"priority": 0,
"string": "le 9 e un quarto",
"value": "09:15:00"
}],
"Multiple times are matched"
);
assert.deepEqual(
reg.getEntities("la 1, le ore 3, le 3 meno un quarto, 3 e un quarto, 8:30, 8:30 di sera, 3, le 3, le 12 e 5 minuti, alle 3 e 20 di sera, le 8 e mezza, le 9 e un quarto"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "la 1",
"value": "01:00:00"
}, {
"entity": "test",
"position": 6,
"priority": 0,
"string": "le ore 3",
"value": "03:00:00"
}, {
"entity": "test",
"position": 16,
"priority": 0,
"string": "le 3 meno un quarto",
"value": "02:15:00"
}, {
"entity": "test",
"position": 37,
"priority": 0,
"string": "3 e un quarto",
"value": "03:15:00"
}, {
"entity": "test",
"position": 52,
"priority": 0,
"string": "8:30",
"value": "08:30:00"
}, {
"entity": "test",
"position": 58,
"priority": 0,
"string": "8:30 di sera",
"value": "20:30:00"
}, {
"entity": "test",
"position": 75,
"priority": 0,
"string": "le 3",
"value": "03:00:00"
}, {
"entity": "test",
"position": 81,
"priority": 0,
"string": "le 12 e 5",
"value": "12:05:00"
}, {
"entity": "test",
"position": 99,
"priority": 0,
"string": "alle 3 e 20 di sera",
"value": "15:20:00"
}, {
"entity": "test",
"position": 120,
"priority": 0,
"string": "le 8 e mezza",
"value": "08:30:00"
}, {
"entity": "test",
"position": 134,
"priority": 0,
"string": "le 9 e un quarto",
"value": "09:15:00"
}], "Multiple times are matched");
});
QUnit.test("IT.TimePeriodEntityRecognizer", function(assert) {
var date = new Date();
var now = (date.getHours() * Bravey.Date.HOUR) + (date.getMinutes() * Bravey.Date.MINUTE);
var reg = new Bravey.Language.IT.TimePeriodEntityRecognizer("test");
assert.deepEqual(reg.getEntities("in mattinata"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "in mattinata",
"value": {
"end": "12:00:00",
"start": "08:00:00"
}
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asf in mattinata"), [{
"entity": "test",
"position": 4,
"priority": 0,
"string": "in mattinata",
"value": {
"end": "12:00:00",
"start": "08:00:00"
}
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("in mattinata asd"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "in mattinata",
"value": {
"end": "12:00:00",
"start": "08:00:00"
}
}], "First entities are matched");
assert.deepEqual(reg.getEntities("ci vediamo di mattina o nel pomeriggio. Al massimo passo io in mattinata o stasera. Tra 20 minuti partiamo. Tra 2 ore e' il momento."), [{
"entity": "test",
"position": 11,
"priority": 0,
"string": "di mattina",
"value": {
"end": "12:00:00",
"start": "08:00:00"
}
}, {
"entity": "test",
"position": 24,
"priority": 0,
"string": "nel pomeriggio",
"value": {
"end": "23:59:00",
"start": "15:00:00"
}
}, {
"entity": "test",
"position": 60,
"priority": 0,
"string": "in mattinata",
"value": {
"end": "12:00:00",
"start": "08:00:00"
}
}, {
"entity": "test",
"position": 75,
"priority": 0,
"string": "stasera",
"value": {
"end": "23:59:00",
"start": "12:00:00"
}
}, {
"entity": "test",
"position": 84,
"priority": 0,
"string": "tra 20 minuti",
"value": {
"end": TestTools.formatTime(now + (20 * TestTools.MINUTE)),
"start": TestTools.formatTime(now)
}
}, {
"entity": "test",
"position": 108,
"priority": 0,
"string": "tra 2 ore",
"value": {
"end": TestTools.formatTime(now + (2 * TestTools.HOUR)),
"start": TestTools.formatTime(now)
}
}],
"Multiple time ranges are matched"
);
assert.deepEqual(reg.getEntities("tra 10 secondi, tra 10, tra 10 minuti, 10 minuti, in 5 ore, stasera, nel pomeriggio, di mattina"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "tra 10 secondi",
"value": {
"end": TestTools.formatTime(now + (10 * TestTools.SECOND)),
"start": TestTools.formatTime(now)
}
}, {
"entity": "test",
"position": 24,
"priority": 0,
"string": "tra 10 minuti",
"value": {
"end": TestTools.formatTime(now + (10 * TestTools.MINUTE)),
"start": TestTools.formatTime(now)
}
}, {
"entity": "test",
"position": 50,
"priority": 0,
"string": "in 5 ore",
"value": {
"end": TestTools.formatTime(now + (5 * TestTools.HOUR)),
"start": TestTools.formatTime(now)
}
}, {
"entity": "test",
"position": 60,
"priority": 0,
"string": "stasera",
"value": {
"end": "23:59:00",
"start": "12:00:00"
}
}, {
"entity": "test",
"position": 69,
"priority": 0,
"string": "nel pomeriggio",
"value": {
"end": "23:59:00",
"start": "15:00:00"
}
}, {
"entity": "test",
"position": 85,
"priority": 0,
"string": "di mattina",
"value": {
"end": "12:00:00",
"start": "08:00:00"
}
}], "Multiple time ranges are matched");
});
QUnit.test("IT.DateEntityRecognizer", function(assert) {
var reg = new Bravey.Language.IT.DateEntityRecognizer("test");
assert.deepEqual(reg.getEntities("25/04 dell'80"), [{
"entity": "test",
"position": 0,
"priority": 10,
"string": "25/04 dell'80",
"value": "1980-04-25"
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asf 25/04 dell'80"), [{
"entity": "test",
"position": 4,
"priority": 10,
"string": "25/04 dell'80",
"value": "1980-04-25"
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("25/04 dell'80 asd"), [{
"entity": "test",
"position": 0,
"priority": 10,
"string": "25/04 dell'80",
"value": "1980-04-25"
}], "First entities are matched");
assert.deepEqual(reg.getEntities("Rimaniamo che c'e' da fare quello per domani o entro la giornata di oggi. Andrebbe finito per ieri, lo sai. Il 3 di giugno abbiamo una consegna. Sono del 25/04 dell'80."), [{
"entity": "test",
"position": 34,
"priority": 0,
"string": "per domani",
"value": TestTools.formatDate((new Date()).getTime() + TestTools.DAY)
}, {
"entity": "test",
"position": 53,
"priority": 0,
"string": "la giornata di oggi",
"value": TestTools.formatDate((new Date()).getTime())
}, {
"entity": "test",
"position": 90,
"priority": 0,
"string": "per ieri",
"value": TestTools.formatDate((new Date()).getTime() - TestTools.DAY)
}, {
"entity": "test",
"position": 108,
"priority": 10,
"string": "il 3 di giugno",
"value": TestTools.getYear() + "-06-03"
}, {
"entity": "test",
"position": 154,
"priority": 10,
"string": "25/04 dell'80",
"value": "1980-04-25"
}], "Multiple dates are matched");
assert.deepEqual(reg.getEntities("lo scorso febbraio, lo scorso Feb, lo scorso gen, lo scorso 8 Marzo, lo scorso 1 febbraio, lo scorso 15 febbraio! 06/01/2014, 12/01/2014, 06/01/15, Giugno 1, 2014, Dicembre 1, 2014"), [{
"entity": "test",
"position": 0,
"priority": 5,
"string": "lo scorso febbraio",
"value": TestTools.getLastDay(2, 1)
}, {
"entity": "test",
"position": 20,
"priority": 5,
"string": "lo scorso feb",
"value": TestTools.getLastDay(2, 1)
}, {
"entity": "test",
"position": 35,
"priority": 5,
"string": "lo scorso gen",
"value": TestTools.getLastDay(1, 1)
}, {
"entity": "test",
"position": 50,
"priority": 10,
"string": "lo scorso 8 marzo",
"value": TestTools.getLastDay(3, 8)
}, {
"entity": "test",
"position": 69,
"priority": 10,
"string": "lo scorso 1 febbraio",
"value": TestTools.getLastDay(2, 1)
}, {
"entity": "test",
"position": 91,
"priority": 10,
"string": "lo scorso 15 febbraio",
"value": TestTools.getLastDay(2, 15)
}, {
"entity": "test",
"position": 114,
"priority": 10,
"string": "06/01/2014",
"value": "2014-01-06"
}, {
"entity": "test",
"position": 126,
"priority": 10,
"string": "12/01/2014",
"value": "2014-01-12"
}, {
"entity": "test",
"position": 138,
"priority": 10,
"string": "06/01/15",
"value": "2015-01-06"
}, {
"entity": "test",
"position": 148,
"priority": 5,
"string": "giugno 1, 2014",
"value": "2014-06-01"
}, {
"entity": "test",
"position": 164,
"priority": 5,
"string": "dicembre 1, 2014",
"value": "2014-12-01"
}], "Multiple dates are matched");
assert.deepEqual(reg.getEntities("2, il 2, il 3 giugno, 3 giugno, 3/06, 3/06/2000, 3/12/80, 8 di marzo, di marzo, nel 2/12/2001, 3 dic! 12 gen-2015, 3-2-1920"), [{
"entity": "test",
"position": 3,
"priority": 10,
"string": "il 2",
"value": TestTools.getLastDay(TestTools.getMonth(), 2)
}, {
"entity": "test",
"position": 9,
"priority": 10,
"string": "il 3 giugno",
"value": TestTools.getYear() + "-06-03"
}, {
"entity": "test",
"position": 22,
"priority": 10,
"string": "3 giugno",
"value": TestTools.getYear() + "-06-03"
}, {
"entity": "test",
"position": 32,
"priority": 10,
"string": "3/06",
"value": TestTools.getYear() + "-06-03"
}, {
"entity": "test",
"position": 38,
"priority": 10,
"string": "3/06/2000",
"value": "2000-06-03"
}, {
"entity": "test",
"position": 49,
"priority": 10,
"string": "3/12/80",
"value": "1980-12-03"
}, {
"entity": "test",
"position": 58,
"priority": 10,
"string": "8 di marzo",
"value": TestTools.getYear() + "-03-08"
}, {
"entity": "test",
"position": 70,
"priority": 05,
"string": "di marzo",
"value": TestTools.getYear() + "-03-01"
}, {
"entity": "test",
"position": 80,
"priority": 10,
"string": "nel 2/12/2001",
"value": "2001-12-02"
}, {
"entity": "test",
"position": 95,
"priority": 10,
"string": "3 dic",
"value": TestTools.getYear() + "-12-03"
}, {
"entity": "test",
"position": 102,
"priority": 10,
"string": "12 gen-2015",
"value": "2015-01-12"
}, {
"entity": "test",
"position": 115,
"priority": 10,
"string": "3-2-1920",
"value": "1920-02-03"
}], "Multiple dates are matched");
});
QUnit.test("IT.NumberEntityRecognizer", function(assert) {
var reg = new Bravey.Language.IT.NumberEntityRecognizer("test");
assert.deepEqual(reg.getEntities("dieci"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "dieci",
"value": 10
}], "Single numbers are matched");
assert.deepEqual(reg.getEntities("ci sono 12 mele, tredici pere e unmilioneottocentoventimilaseicentoquindici peperoni"), [{
"entity": "test",
"position": 8,
"priority": 0,
"string": "12",
"value": 12
}, {
"entity": "test",
"position": 17,
"priority": 0,
"string": "tredici",
"value": 13
}, {
"entity": "test",
"position": 32,
"priority": 0,
"string": "unmilioneottocentoventimilaseicentoquindici",
"value": 1820615
}], "Multiple numbers are matched");
});
// Portuguese
QUnit.test("PT.Stemmer", function(assert) {
assert.deepEqual(Bravey.Language.PT.Stemmer("químico"), "químic", "Singulars are correctly stemmed");
assert.deepEqual(Bravey.Language.PT.Stemmer("químicos"), "químic", "Pluralrs are correctly stemmed");
assert.deepEqual(Bravey.Language.PT.Stemmer("bobagem"), "bobag", "Variants are correctly stemmed");
assert.deepEqual(Bravey.Language.PT.Stemmer("bobagens"), "bobagens", "Variants are correctly stemmed");
assert.deepEqual(Bravey.Language.PT.Stemmer("namorar"), "namor", "Verbs are correctly stemmed");
assert.deepEqual(Bravey.Language.PT.Stemmer("cuidar"), "cuid", "Verbs are correctly stemmed");
assert.deepEqual(Bravey.Language.PT.Stemmer("respeitar"), "respeit", "Verbs are correctly stemmed");
});
QUnit.test("PT: Nlp.Fuzzy + Mixed Regex Recognizers", function(assert) {
var nlp = new Bravey.Nlp.Fuzzy("test");
var numberRegexp = new RegExp("\\b([0-9]+)\\b", "g");
var timeRegexp = new RegExp("\\ba hora é ([0-9]+)\\b", "g");
var dateEntity = new Bravey.Language.PT.DateEntityRecognizer("dateEntity");
nlp.addEntity(dateEntity);
TestTools.nlpAddDocument(assert, nlp, "Nos encontraremos em 12 de janeiro de 2017", "mixmatch", {
fromFullSentence: true,
expandIntent: true
}, "nos encontraremos em {dateEntity}");
TestTools.nlpAddDocument(assert, nlp, "Te vejo em 22 de fevereiro de 2016, ok?", "mixmatch", {
fromFullSentence: true,
expandIntent: true
}, "te vejo em {dateEntity}, ok?");
TestTools.nlpAddDocument(assert, nlp, "Nos encontraremos em 1° de dezembro de 2018", "mixmatch", {
fromFullSentence: true,
expandIntent: true
}, "nos encontraremos em {dateEntity}");
});
QUnit.test("PT.TimeEntityRecognizer", function(assert) {
var reg = new Bravey.Language.PT.TimeEntityRecognizer("test");
assert.deepEqual(reg.getEntities("às 3:00"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "as 3:00",
"value": "03:00:00"
}], "Single hour");
assert.deepEqual(reg.getEntities("às 3:30"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "as 3:30",
"value": "03:30:00"
}], "Hour with minutes");
assert.deepEqual(reg.getEntities("às 3:30:45"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "as 3:30:45",
"value": "03:30:45"
}], "Hour with minutes and seconds");
assert.deepEqual(reg.getEntities("às 3 horas"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "as 3 horas",
"value": "03:00:00"
}], "Single entities are matched");
assert.deepEqual(reg.getEntities("asdfg às 3 horas"), [{
"entity": "test",
"position": 6,
"priority": 0,
"string": "as 3 horas",
"value": "03:00:00"
}], "Last entities are matched");
assert.deepEqual(reg.getEntities("às 3 horas asdfg"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "as 3 horas",
"value": "03:00:00"
}], "First entities are matched");
assert.deepEqual(reg.getEntities("às 3 horas e 15 minutos"), [{
"entity": "test",
"position": 0,
"priority": 0,
"string": "as 3 horas e 15 minutos",
"value": "03:15:00"
}], "Hours and minutes are matched");
assert.deepEqual(reg.getEntities("às 3 horas, 15 minutos e 45 segundos"), [{