vui-ad-hoc-alexa-recognizer
Version:
Provides natural language understanding/processing to enable easy implementation of chat bots and voice services. High performance run time in only 2 lines of code - 'require' to include it, and the call to process the text. These can run anywhere Node.js
874 lines (768 loc) • 110 kB
JavaScript
/*
@author Ilya Shubentsov
MIT License
Copyright (c) 2017 Ilya Shubentsov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
"use strict";
let path = require("path");
var soundex = require("./soundex.js");
var utilities = require("./utilities.js");
var parser = require("./parseutterance.js");
var recognizer = {};
/**
* Call to convert an array of objects and strings into an array of strings. Objects MUST have a "value" field which is
* a string (will be added to the return value) and MAY have a "synonyms" field which MUST be an array of strings.
* If exists, contents of "synonyms" will be added to the return value.
* @param arrayToConvert - array of strings and objects.
* @param useSynonyms - if true (default) will use synonyms when found. Else, will skip them.
* @returns {Array} - array of strings
* @private
*/
let _unfoldCustomValuesIntoStringArray = function(arrayToConvert, useSynonyms){
if(typeof useSynonyms === "undefined" || useSynonyms === null){
useSynonyms = true;
}
let returnValue = [];
for(let i = 0; i < arrayToConvert.length; i++){
if(typeof arrayToConvert[i] === "string"){
returnValue.push(arrayToConvert[i]);
}
else {
if(typeof arrayToConvert[i].value === "string"){
returnValue.push(arrayToConvert[i].value);
if(useSynonyms){
if(typeof arrayToConvert[i].synonyms !== "undefined" && Array.isArray(arrayToConvert[i].synonyms)){
for(let j = 0; j < arrayToConvert[i].synonyms.length; j++){
returnValue.push(arrayToConvert[i].synonyms[j]);
}
}
}
}
}
}
return returnValue;
};
/**
* Call to convert an array of objects and strings into a regular expression string.
* The array is first converted into an array of strings using _unfoldCustomValuesIntoStringArray.
* The resulting regular expression is such that it will match on any of the converted string values, possibly with
* extra white spaces at the end.
* @param arrayToConvert - array of strings and objects
* @param useSynonyms - if true (default) will use synonyms when found. Else, will skip them.
* @returns {string} - a string representing the regular expression
* @private
*/
let _makeReplacementRegExpString = function(arrayToConvert, useSynonyms){
if(typeof useSynonyms === "undefined" || useSynonyms === null){
useSynonyms = true;
}
let arrayToUse = _unfoldCustomValuesIntoStringArray(arrayToConvert, useSynonyms);
let returnValue = "((?:";
let appendBar = false;
for(let i = 0; i < arrayToUse.length; i++){
if(appendBar){
returnValue += "|";
}
else {
appendBar = true;
}
returnValue += "" + arrayToUse[i] + "\\s*";
}
returnValue += ")+)";
return returnValue;
};
/**
* Call to convert a regular expression string produced by _makeReplacementRegExpString into a regular expression
* string that will match on the entire string (i.e. includes ^ and $), match on any white spaces rather than just the
* specific ones supplied in the input, and will also allow common sentense ending punctuation, such as .!? at the end.
* @param arrayToConvert - array of strings and objects
* @param useSynonyms - if true (default) will use synonyms when found. Else, will skip them.
* @returns {string} - a string representing the regular expression
* @private
*/
let _makeFullRegExpString = function(arrayToConvert, useSynonyms){
if(typeof useSynonyms === "undefined" || useSynonyms === null){
useSynonyms = true;
}
let regExString = _makeReplacementRegExpString(arrayToConvert, useSynonyms);
// Now split regExString into non-white space parts and reconstruct the
// whole thing with any sequence of white spaces replaced with a white space
// reg exp.
let splitRegEx = regExString.split(/\s+/);
let reconstructedRegEx = "^\\s*";
for(let j = 0; j < splitRegEx.length; j++){
if(splitRegEx[j].length > 0){
if(j > 0){
reconstructedRegEx += "\\s+";
}
reconstructedRegEx += splitRegEx[j];
}
}
reconstructedRegEx += "\\s*[.?!]?\\s*$";
return reconstructedRegEx;
};
recognizer.Recognizer = class {
};
// The sections below are for the built in slots support
recognizer.builtInValues = {};
recognizer.builtInValues.NUMBER = require("./builtinslottypes/numbers.json");
let numbersWithAnd = recognizer.builtInValues.NUMBER.values.slice();
numbersWithAnd.push("and");
numbersWithAnd.push(",");
recognizer.builtInValues.NUMBER.replacementRegExpString = _makeReplacementRegExpString(numbersWithAnd);
recognizer.builtInValues.NUMBER.replacementRegExp = new RegExp(recognizer.builtInValues.NUMBER.replacementRegExpString, "ig");
recognizer.builtInValues.FOUR_DIGIT_NUMBER = {};
recognizer.builtInValues.FOUR_DIGIT_NUMBER.replacementRegExpString =
"(" +
"(?:(?:zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){4}" +
"|" +
"(?:" +
"(?:(?:zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){2}" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){1}\\s*){1}\\s*" +
")" +
"|" +
"(?:" +
"(?:(?:zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){1}" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){1}\\s*){1}\\s*" +
"(?:(?:zero|one|two|three|four|five|six|seven|eight|nine|[0-9])\\s*){1}" +
")" +
"|" +
"(?:" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){1}\\s*){1}\\s*" +
"(?:(?:zero|one|two|three|four|five|six|seven|eight|nine|[0-9])\\s*){2}" +
")" +
"|" +
"(?:" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen)\\s*){2}\\s*" +
")" +
"|" +
"(?:" +
"(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*thousand\\s*[,]{0,1}\\s*" +
"(?:(?:one|two|three|four|five|six|seven|eight|nine|[1-9])\\s*hundred\\s*){0,1}" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){0,1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){0,1}\\s*){0,1}\\s*" +
")" +
")\\s*";
recognizer.builtInValues.FOUR_DIGIT_NUMBER.replacementRegExp = new RegExp(recognizer.builtInValues.FOUR_DIGIT_NUMBER.replacementRegExpString, "ig");
recognizer.builtInValues.DATE = require("./builtinslottypes/dates.json");
{
let fullCalendarDateString1 =
"(?:January|February|March|April|May|June|July|August|September|October|November|December){0,1}\\s*" +
"(?:first|1st|second|2nd|third|3rd|fourth|4th|fifth|5th|sixth|6th|seventh|7th|eighth|8th|nineth|9th|tenth|10th|" +
"eleventh|11th|twelfth|12th|thirteenth|13th|fourteenth|14th|fifteenth|15th|sixteenth|16th|seventeenth|17th|eighteenth|18th|nineteenth|19th|twentieth|20th|" +
"twenty first|21st|twenty second|22nd|thwenty third|23rd|twenty fourth|24th|twenty fifth|25th|twenty sixth|26th|twenty seventh|27th|" +
"twenty eighth|28th|twenty ninth|29th|thirtieth|30th|thirty first|31st){0,1}\\s*" +
// Now the year, first as spelled out number, e.g. one thousand nine hundred forty five
"(?:" +
"(?:" +
"(?:one thousand|two thousand){0,1}\\s*(?:(?:one|two|three|four|five|six|seven|eight|nine)\\s*hundred){0,1}\\s*" + "(?:and\\s*){0,1}(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){0,1}\\s*(?:one|two|three|four|five|six|seven|eight|nine){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen)\\s*){0,1}\\s*"+
")" +
// then as two two digit numbers, e.g. nineteen forty five
"|" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){0,1}\\s*(?:one|two|three|four|five|six|seven|eight|nine){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen)\\s*){0,2}\\s*" +
// then as four digits, e.g. 1945
"|" +
"(?:(?:zero|one|two|three|four|five|six|seven|eight|nine|[0-9])\\s*){4}" +
")";
recognizer.builtInValues.DATE.values.push(fullCalendarDateString1);
}
recognizer.builtInValues.DATE.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.DATE.values);
recognizer.builtInValues.DATE.replacementRegExp = new RegExp(recognizer.builtInValues.DATE.replacementRegExpString, "ig");
recognizer.builtInValues.TIME = require("./builtinslottypes/times.json");
{
let hourOnlyString =
"\\s*(?:zero|oh|0|one|1|two|2|three|3|four|4|five|5|six|6|seven|7|eight|8|nine|9|ten|10|eleven|11|twelve|12|thirteen|13|fourteen|14|fifteen|15|sixteen|16|seventeen|17|eighteen|18|nineteen|19|twenty|20|twenty one|21|twenty two|22|twenty three|23){1}\\s*(?:o'clock|am|pm|a\\.m\\.|p\\.m\\.|in the morning|in the afternoon|in the evening|at night){0,1}\\s*";
recognizer.builtInValues.TIME.values.push(hourOnlyString);
let hourAndMinutesString1 =
"\\s*" +
"(?:zero|oh|0|one|1|two|2|three|3|four|4|five|5|six|6|seven|7|eight|8|nine|9|ten|10|eleven|11|twelve|12|thirteen|13|fourteen|14|fifteen|15|sixteen|16|seventeen|17|eighteen|18|nineteen|19|twenty|20|twenty one|21|twenty two|22|twenty three|23){1}\\s*" +
"(?:zero zero|zero oh|zero 0|oh oh|oh zero|oh 0|0 zero|0 oh|00|0 0|" +
"zero one|zero 1|oh one|oh 1|0 one|01|0 1|" +
"zero two|zero 2|oh two|oh 2|0 two|02|0 2|" +
"zero three|zero 3|oh three|oh 3|0 three|03|0 3|" +
"zero four|zero 4|oh four|oh 4|0 four|04|0 4|" +
"zero five|zero 5|oh five|oh 5|0 five|05|0 5|" +
"zero six|zero 6|oh six|oh 6|0 six|06|0 6|" +
"zero seven|zero 7|oh seven|oh 7|0 seven|07|0 7|" +
"zero eight|zero 8|oh eight|oh 8|0 eight|08|0 8|" +
"zero nine|zero 9|oh nine|oh 9|0 nine|09|0 9|" +
"ten|10|eleven|11|twelve|12|thirteen|13|fourteen|14|fifteen|15|sixteen|16|seventeen|17|eighteen|18|nineteen|19|" +
"twenty|20|twenty one|21|twenty two|22|twenty three|23|twenty four|24|twenty five|25|twenty six|26|twenty seven|27|twenty eight|28|twenty nine|29" +
"thirty|30|thirty one|31|thirty two|32|thirty three|33|thirty four|34|thirty five|35|thirty six|36|thirty seven|37|thirty eight|38|thirty nine|39" +
"forty|40|forty one|41|forty two|42|forty three|43|forty four|44|forty five|45|forty six|46|forty seven|47|forty eight|48|forty nine|49" +
"fifty|50|fifty one|51|fifty two|52|fifty three|53|fifty four|54|fifty five|55|fifty six|56|fifty seven|57|fifty eight|58|fifty nine|59" +
"){1}\\s*" +
"(?:o'clock|am|pm|a\\.m\\.|p\\.m\\.|in the morning|in the afternoon|in the evening|at night){0,1}" +
"\\s*";
recognizer.builtInValues.TIME.values.push(hourAndMinutesString1);
recognizer.builtInValues.TIME.values.push("(?:\\s*quarter (?:past|after) midnight\\s*)");
recognizer.builtInValues.TIME.values.push("(?:\\s*half (?:past|after) midnight\\s*)");
recognizer.builtInValues.TIME.values.push("(?:\\s*quarter (?:to|before) midnight\\s*)");
recognizer.builtInValues.TIME.values.push("(?:\\s*quarter (?:past|after) noon\\s*)");
recognizer.builtInValues.TIME.values.push("(?:\\s*half (?:past|after) noon\\s*)");
recognizer.builtInValues.TIME.values.push("(?:\\s*quarter (?:to|before) noon\\s*)");
recognizer.builtInValues.TIME.values.push("(?:\\s*quarter (?:past|after) (?:zero|oh|0|one|1|two|2|three|3|four|4|five|5|six|6|seven|7|eight|8|nine|9|ten|10|eleven|11|twelve|12|thirteen|13|fourteen|14|fifteen|15|sixteen|16|seventeen|17|eighteen|18|nineteen|19|twenty|20|twenty one|21|twenty two|22|twenty three|23)\\s*(?:o'clock|am|pm|a\\.m\\.|p\\.m\\.|in the morning|in the afternoon|in the evening|at night){0,1}\\s*)");
recognizer.builtInValues.TIME.values.push("(?:\\s*quarter (?:to|before) (?:one|1|two|2|three|3|four|4|five|5|six|6|seven|7|eight|8|nine|9|ten|10|eleven|11|twelve|12|thirteen|13|fourteen|14|fifteen|15|sixteen|16|seventeen|17|eighteen|18|nineteen|19|twenty|20|twenty one|21|twenty two|22|twenty three|23|twenty four|24)\\s*(?:o'clock|am|pm|a\\.m\\.|p\\.m\\.|in the morning|in the afternoon|in the evening|at night){0,1}\\s*)");
recognizer.builtInValues.TIME.values.push("(?:\\s*half (?:past|after) (?:zero|oh|0|one|1|two|2|three|3|four|4|five|5|six|6|seven|7|eight|8|nine|9|ten|10|eleven|11|twelve|12|thirteen|13|fourteen|14|fifteen|15|sixteen|16|seventeen|17|eighteen|18|nineteen|19|twenty|20|twenty one|21|twenty two|22|twenty three|23)\\s*(?:o'clock|am|pm|a\\.m\\.|p\\.m\\.|in the morning|in the afternoon|in the evening|at night){0,1}\\s*)");
let hourAndMinutesString2 =
"\\s*" +
"(?:one|1|two|2|three|3|four|4|five|5|six|6|seven|7|eight|8|nine|9|" +
"ten|10|eleven|11|twelve|12|thirteen|13|fourteen|14|fifteen|15|sixteen|16|seventeen|17|eighteen|18|nineteen|19|" +
"twenty|20|twenty one|21|twenty two|22|twenty three|23|twenty four|24|twenty five|25|twenty six|26|twenty seven|27|twenty eight|28|twenty nine|29" +
"thirty|30" +
"){1}\\s*" +
"(?:past|after|to|before)\\s*" +
"(?:zero|oh|0|one|1|two|2|three|3|four|4|five|5|six|6|seven|7|eight|8|nine|9|ten|10|eleven|11|twelve|12|thirteen|13|fourteen|14|fifteen|15|sixteen|16|seventeen|17|eighteen|18|nineteen|19|twenty|20|twenty one|21|twenty two|22|twenty three|23|twenty four|24){1}\\s*" +
"(?:o'clock|am|pm|a\\.m\\.|p\\.m\\.|in the morning|in the afternoon|in the evening|at night){0,1}" +
"\\s*";
recognizer.builtInValues.TIME.values.push(hourAndMinutesString2);
let hourString3 =
"\\s*" +
"(?:" +
"oh one hundred|zero one hundred|one hundred|oh 1 hundred|zero 1 hundred|1 hundred|oh 100|0100|100|" +
"oh two hundred|zero two hundred|two hundred|oh 2 hundred|zero 2 hundred|2 hundred|oh 200|0200|200|" +
"oh three hundred|zero three hundred|three hundred|oh 3 hundred|zero 3 hundred|3 hundred|oh 300|0300|300|" +
"oh four hundred|zero four hundred|four hundred|oh 4 hundred|zero 4 hundred|4 hundred|oh 400|0400|400|" +
"oh five hundred|zero five hundred|five hundred|oh 5 hundred|zero 5 hundred|5 hundred|oh 500|0500|500|" +
"oh six hundred|zero six hundred|six hundred|oh 6 hundred|zero 6 hundred|6 hundred|oh 600|0600|600|" +
"oh seven hundred|zero seven hundred|seven hundred|oh 7 hundred|zero 7 hundred|7 hundred|oh 700|0700|700|" +
"oh eight hundred|zero eight hundred|eight hundred|oh 8 hundred|zero 8 hundred|8 hundred|oh 800|0800|800|" +
"oh nine hundred|zero nine hundred|nine hundred|oh 9 hundred|zero 9 hundred|9 hundred|oh 900|0900|900|" +
"eleven hundred|11 hundred|11 100|1100|" +
"twelve hundred|12 hundred|12 100|1200|" +
"thirteen hundred|13 hundred|13 100|1300|" +
"fourteen hundred|14 hundred|14 100|1400|" +
"fifteen hundred|15 hundred|15 100|1500|" +
"sixteen hundred|16 hundred|16 100|1600|" +
"seventeen hundred|17 hundred|17 100|1700|" +
"eighteen hundred|18 hundred|18 100|1800|" +
"nineteen hundred|19 hundred|19 100|1900|" +
"twenty hundred|20 hundred|20 100|2000|" +
"twenty one hundred|21 hundred|21 100|2100|" +
"twenty two hundred|22 hundred|22 100|2200|" +
"twenty three hundred|23 hundred|23 100|2300|" +
"twenty four hundred|24 hundred|24 100|2400" +
"){1}\\s*(?:hours|hour){0,1}" +
"\\s*";
recognizer.builtInValues.TIME.values.push(hourString3);
}
recognizer.builtInValues.TIME.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.TIME.values);
recognizer.builtInValues.TIME.replacementRegExp = new RegExp(recognizer.builtInValues.TIME.replacementRegExpString, "ig");
recognizer.builtInValues.DURATION = {};
recognizer.builtInValues.DURATION.values = [];
{
let generalDurationString =
"\\s*" +
"(?:.+\\s*years{0,1}){0,1}\\s*" +
"(?:.+\\s*months{0,1}){0,1}\\s*" +
"(?:.+\\s*weeks{0,1}){0,1}\\s*" +
"(?:.+\\s*days{0,1}){0,1}\\s*" +
"(?:.+\\s*hours{0,1}){0,1}\\s*" +
"(?:.+\\s*minutes{0,1}){0,1}\\s*" +
"(?:.+\\s*seconds{0,1}){0,1}\\s*" +
"\\s*";
recognizer.builtInValues.DURATION.values.push(generalDurationString);
}
recognizer.builtInValues.DURATION.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.DURATION.values);
recognizer.builtInValues.DURATION.replacementRegExp = new RegExp(recognizer.builtInValues.DURATION.replacementRegExpString, "ig");
recognizer.builtInValues.US_STATE = require("./builtinslottypes/usstates.json");
recognizer.builtInValues.US_PRESIDENT = require("./builtinslottypes/uspresidents.json");
// have 3 sections - 3 digit area code, 3 digit exchange code, 4 digit subscriber number
recognizer.builtInValues.US_PHONE_NUMBER = {};
recognizer.builtInValues.US_PHONE_NUMBER.replacementRegExpString =
"(" +
// First, area code
"(?:[(]{0,1}\\s*)" + // Area code opening parenthesis, if any
"(?:"+
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){3}" +
"|" +
"(?:" +
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){1}" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){1}\\s*){1}\\s*" +
")" +
")" + // End of the numeric part of the area code
"(?:[-).]{0,1}\\s*)" +
// Second, the domain
"(?:"+
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){3}" +
"|" +
"(?:" +
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){1}" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){1}\\s*){1}\\s*" +
")" +
")" + // End of the numeric part of the domain
"(?:[-.]{0,1}\\s*)" +
// Third, subscriber number
"(?:"+
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){4}" +
"|" +
"(?:" +
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){2}" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){1}\\s*){1}\\s*" +
")" +
"|" +
"(?:" +
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9,])\\s*){1}" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){1}\\s*){1}\\s*" +
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9])\\s*){1}" +
")" +
"|" +
"(?:" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){1}\\s*){1}\\s*" +
"(?:(?:oh|o|zero|one|two|three|four|five|six|seven|eight|nine|[0-9])\\s*){2}" +
")" +
"|" +
"(?:" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen)\\s*){2}\\s*" +
")" +
"|" +
"(?:" +
"(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*thousand\\s*[,]{0,1}\\s*" +
"(?:(?:one|two|three|four|five|six|seven|eight|nine|[1-9])\\s*hundred\\s*){0,1}" +
"(?:(?:(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety){0,1}\\s*(?:one|two|three|four|five|six|seven|eight|nine|[1-9]){0,1}\\s*)|(?:ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen){0,1}\\s*){0,1}\\s*" +
")" +
")" + // End of the subscriber portion
")\\s*";
//console.log("recognizer.builtInValues.US_PHONE_NUMBER.replacementRegExpString:" + recognizer.builtInValues.US_PHONE_NUMBER.replacementRegExpString);
recognizer.builtInValues.US_PHONE_NUMBER.replacementRegExp = new RegExp(recognizer.builtInValues.US_PHONE_NUMBER.replacementRegExpString, "ig");
recognizer.builtInValues.Airline = require("./builtinslottypes/airlines.json");
recognizer.builtInValues.SportsTeam = require("./builtinslottypes/sportsteams.json");
recognizer.builtInValues.US_FIRST_NAME = require("./builtinslottypes/usfirstnames.json");
recognizer.builtInValues.US_FIRST_NAME.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.US_FIRST_NAME.values);
recognizer.builtInValues.US_FIRST_NAME.replacementRegExp = new RegExp(recognizer.builtInValues.US_FIRST_NAME.replacementRegExpString, "ig");
recognizer.builtInValues.Actor = require("./builtinslottypes/actors.json");
recognizer.builtInValues.Actor.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Actor.values);
recognizer.builtInValues.Artist = require("./builtinslottypes/artists.json");
recognizer.builtInValues.Artist.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Artist.values);
recognizer.builtInValues.Comic = require("./builtinslottypes/comics.json");
recognizer.builtInValues.Comic.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Comic.values);
recognizer.builtInValues.Dessert = require("./builtinslottypes/desserts.json");
recognizer.builtInValues.Dessert.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Dessert.values);
recognizer.builtInValues.LandmarksOrHistoricalBuildings = require("./builtinslottypes/landmarksorhistoricalbuildings.json");
recognizer.builtInValues.LandmarksOrHistoricalBuildings.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.LandmarksOrHistoricalBuildings.values);
recognizer.builtInValues.Landform = require("./builtinslottypes/landforms.json");
recognizer.builtInValues.Landform.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Landform.values);
recognizer.builtInValues.MovieSeries = require("./builtinslottypes/movieseries.json");
recognizer.builtInValues.MovieSeries.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MovieSeries.values);
recognizer.builtInValues.MovieTheater = require("./builtinslottypes/movietheaters.json");
recognizer.builtInValues.MovieTheater.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MovieTheater.values);
recognizer.builtInValues.MusicAlbum = require("./builtinslottypes/musicalbums.json");
recognizer.builtInValues.MusicAlbum.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MusicAlbum.values);
recognizer.builtInValues.Musician = require("./builtinslottypes/musicians.json");
recognizer.builtInValues.Musician.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Musician.values);
recognizer.builtInValues.MusicRecording = require("./builtinslottypes/musicrecordings.json");
recognizer.builtInValues.MusicRecording.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MusicRecording.values);
recognizer.builtInValues.MusicVenue = require("./builtinslottypes/musicvenues.json");
recognizer.builtInValues.MusicVenue.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MusicVenue.values);
recognizer.builtInValues.MusicVideo = require("./builtinslottypes/musicvideos.json");
recognizer.builtInValues.MusicVideo.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MusicVideo.values);
// Make a concatenated list of all the other person types and add those to the separate "person" list
recognizer.builtInValues.Person = require("./builtinslottypes/persons.json");
let scratchPerson = require("./builtinslottypes/actors.json");
recognizer.builtInValues.Person.values = recognizer.builtInValues.Person.values.concat(scratchPerson.values);
scratchPerson = require("./builtinslottypes/artists.json");
recognizer.builtInValues.Person.values = recognizer.builtInValues.Person.values.concat(scratchPerson.values);
scratchPerson = require("./builtinslottypes/athletes.json");
recognizer.builtInValues.Person.values = recognizer.builtInValues.Person.values.concat(scratchPerson.values);
scratchPerson = require("./builtinslottypes/authors.json");
recognizer.builtInValues.Person.values = recognizer.builtInValues.Person.values.concat(scratchPerson.values);
scratchPerson = require("./builtinslottypes/directors.json");
recognizer.builtInValues.Person.values = recognizer.builtInValues.Person.values.concat(scratchPerson.values);
scratchPerson = require("./builtinslottypes/musicians.json");
recognizer.builtInValues.Person.values = recognizer.builtInValues.Person.values.concat(scratchPerson.values);
scratchPerson = require("./builtinslottypes/professionals.json");
recognizer.builtInValues.Person.values = recognizer.builtInValues.Person.values.concat(scratchPerson.values);
recognizer.builtInValues.Person.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Person.values);
recognizer.builtInValues.MusicGroup = require("./builtinslottypes/musicgroups.json");
recognizer.builtInValues.MusicGroup.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MusicGroup.values);
recognizer.builtInValues.MusicEvent = require("./builtinslottypes/musicevents.json");
recognizer.builtInValues.MusicEvent.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MusicEvent.values);
recognizer.builtInValues.Movie = require("./builtinslottypes/movies.json");
recognizer.builtInValues.Movie.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Movie.values);
recognizer.builtInValues.MedicalOrganization = require("./builtinslottypes/medicalorganizations.json");
recognizer.builtInValues.MedicalOrganization.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.MedicalOrganization.values);
// Make a concatenated list of all the other organizations
recognizer.builtInValues.Organization = require("./builtinslottypes/medicalorganizations.json");
let scratchOrganization = require("./builtinslottypes/educationalorganizations.json");
recognizer.builtInValues.Organization.values = recognizer.builtInValues.Organization.values.concat(scratchOrganization.values);
recognizer.builtInValues.Organization.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Organization.values);
recognizer.builtInValues.LocalBusinessType = require("./builtinslottypes/localbusinesstypes.json");
recognizer.builtInValues.LocalBusinessType.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.LocalBusinessType.values);
recognizer.builtInValues.LocalBusiness = require("./builtinslottypes/localbusinesses.json");
recognizer.builtInValues.LocalBusiness.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.LocalBusiness.values);
let scratchGame = require("./builtinslottypes/videogames.json");
// Add video games to software games, but without adding duplicates
recognizer.builtInValues.SoftwareGame = require("./builtinslottypes/softwaregames.json");
for(let i = 0; i < scratchGame.length; i ++){
if(recognizer.builtInValues.SoftwareGame.indexOf(scratchGame[i]) < 0){
recognizer.builtInValues.SoftwareGame.push(scratchGame[i]);
}
}
recognizer.builtInValues.SoftwareGame.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.SoftwareGame.values);
scratchGame = require("./builtinslottypes/softwaregames.json");
// Add software games to video games, but without adding duplicates
recognizer.builtInValues.VideoGame = require("./builtinslottypes/videogames.json");
for(let i = 0; i < scratchGame.length; i ++){
if(recognizer.builtInValues.VideoGame.indexOf(scratchGame[i]) < 0){
recognizer.builtInValues.VideoGame.push(scratchGame[i]);
}
}
recognizer.builtInValues.VideoGame.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.VideoGame.values);
recognizer.builtInValues.Game = require("./builtinslottypes/games.json");
// Add software games to games, but without adding duplicates
scratchGame = require("./builtinslottypes/softwaregames.json");
for(let i = 0; i < scratchGame.length; i ++){
if(recognizer.builtInValues.Game.indexOf(scratchGame[i]) < 0){
recognizer.builtInValues.Game.push(scratchGame[i]);
}
}
// Add video games to games, but without adding duplicates
scratchGame = require("./builtinslottypes/videogames.json");
for(let i = 0; i < scratchGame.length; i ++){
if(recognizer.builtInValues.Game.indexOf(scratchGame[i]) < 0){
recognizer.builtInValues.Game.push(scratchGame[i]);
}
}
recognizer.builtInValues.Game.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Game.values);
recognizer.builtInValues.FoodEstablishment = require("./builtinslottypes/foodestablishments.json");
recognizer.builtInValues.FoodEstablishment.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.FoodEstablishment.values);
recognizer.builtInValues.FictionalCharacter = require("./builtinslottypes/fictionalcharacters.json");
recognizer.builtInValues.FictionalCharacter.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.FictionalCharacter.values);
recognizer.builtInValues.Festival = require("./builtinslottypes/festivals.json");
recognizer.builtInValues.Festival.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Festival.values);
recognizer.builtInValues.EducationalOrganization = require("./builtinslottypes/educationalorganizations.json");
recognizer.builtInValues.EducationalOrganization.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.EducationalOrganization.values);
recognizer.builtInValues.Director = require("./builtinslottypes/directors.json");
recognizer.builtInValues.Director.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Director.values);
recognizer.builtInValues.Corporation = require("./builtinslottypes/corporations.json");
let unusualCorporationCharacters = [];
for(let i = 0; i < recognizer.builtInValues.Corporation.values.length; i++){
let unusualCharactersRegExp = /[^\0-~]/ig;
let matchResult;
while(matchResult = unusualCharactersRegExp.exec(recognizer.builtInValues.Corporation.values[i].name)){ // eslint-disable-line no-cond-assign
// console.log("unusualCorporationCharacters search, got matchResult: ", JSON.stringify(matchResult));
for(let j = 0; j < matchResult.length; j++){
if(matchResult[j] !== null && unusualCorporationCharacters.indexOf(matchResult[j]) < 0){
unusualCorporationCharacters.push(matchResult[j]);
}
}
}
for(let k = 0; k < recognizer.builtInValues.Corporation.values[i].alternativeNames.length; k++){
while(matchResult = unusualCharactersRegExp.exec(recognizer.builtInValues.Corporation.values[i].alternativeNames[k])){ // eslint-disable-line no-cond-assign
// console.log("unusualCorporationCharacters search, got matchResult: ", JSON.stringify(matchResult));
for(let j = 0; j < matchResult.length; j++){
if(matchResult[j] !== null && unusualCorporationCharacters.indexOf(matchResult[j]) < 0){
// console.log("unusualCorporationCharacters search in alternativeNames, got matchResult: ", JSON.stringify(matchResult));
unusualCorporationCharacters.push(matchResult[j]);
}
}
}
}
for(let k = 0; k < recognizer.builtInValues.Corporation.values[i].priorNames.length; k++){
while(matchResult = unusualCharactersRegExp.exec(recognizer.builtInValues.Corporation.values[i].priorNames[k])){ // eslint-disable-line no-cond-assign
// console.log("unusualCorporationCharacters search, got matchResult: ", JSON.stringify(matchResult));
for(let j = 0; j < matchResult.length; j++){
if(matchResult[j] !== null && unusualCorporationCharacters.indexOf(matchResult[j]) < 0){
// console.log("unusualCorporationCharacters search in priorNames, got matchResult: ", JSON.stringify(matchResult));
unusualCorporationCharacters.push(matchResult[j]);
}
}
}
}
}
recognizer.builtInValues.Corporation.presentUnusualCharacters = unusualCorporationCharacters;
//console.log("unusualCorporationCharacters: ", JSON.stringify(unusualCorporationCharacters));
recognizer.builtInValues.Airport = require("./builtinslottypes/airports.json");
let unusualAirportCharacters = [];
for(let i = 0; i < recognizer.builtInValues.Airport.values.length; i++){
let unusualCharactersRegExp = /[^\0-~]/ig;
let matchResult;
while(matchResult = unusualCharactersRegExp.exec(recognizer.builtInValues.Airport.values[i].name)){ // eslint-disable-line no-cond-assign
// console.log("unusualAirportCharacters search, got matchResult: ", JSON.stringify(matchResult));
for(let j = 0; j < matchResult.length; j++){
if(matchResult[j] !== null && unusualAirportCharacters.indexOf(matchResult[j]) < 0){
unusualAirportCharacters.push(matchResult[j]);
}
}
}
for(let k = 0; k < recognizer.builtInValues.Airport.values[i].alternativeNames.length; k++){
while(matchResult = unusualCharactersRegExp.exec(recognizer.builtInValues.Airport.values[i].alternativeNames[k])){ // eslint-disable-line no-cond-assign
// console.log("unusualAirportCharacters search, got matchResult: ", JSON.stringify(matchResult));
for(let j = 0; j < matchResult.length; j++){
if(matchResult[j] !== null && unusualAirportCharacters.indexOf(matchResult[j]) < 0){
// console.log("unusualAirportCharacters search in alternativeNames, got matchResult: ", JSON.stringify(matchResult));
unusualAirportCharacters.push(matchResult[j]);
}
}
}
}
for(let k = 0; k < recognizer.builtInValues.Airport.values[i].priorNames.length; k++){
while(matchResult = unusualCharactersRegExp.exec(recognizer.builtInValues.Airport.values[i].priorNames[k])){ // eslint-disable-line no-cond-assign
// console.log("unusualAirportCharacters search, got matchResult: ", JSON.stringify(matchResult));
for(let j = 0; j < matchResult.length; j++){
if(matchResult[j] !== null && unusualAirportCharacters.indexOf(matchResult[j]) < 0){
// console.log("unusualAirportCharacters search in priorNames, got matchResult: ", JSON.stringify(matchResult));
unusualAirportCharacters.push(matchResult[j]);
}
}
}
}
}
recognizer.builtInValues.Airport.presentUnusualCharacters = unusualAirportCharacters;
//console.log("unusualAirportCharacters: ", JSON.stringify(unusualAirportCharacters));
recognizer.builtInValues.CivicStructure = require("./builtinslottypes/civicstructures.json");
recognizer.builtInValues.CivicStructure.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.CivicStructure.values);
recognizer.builtInValues.BroadcastChannel = require("./builtinslottypes/broadcastchannels.json");
recognizer.builtInValues.BroadcastChannel.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.BroadcastChannel.values);
recognizer.builtInValues.BookSeries = require("./builtinslottypes/bookseries.json");
recognizer.builtInValues.BookSeries.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.BookSeries.values);
recognizer.builtInValues.Book = require("./builtinslottypes/books.json");
recognizer.builtInValues.Book.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Book.values);
recognizer.builtInValues.Author = require("./builtinslottypes/authors.json");
recognizer.builtInValues.Author.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Author.values);
recognizer.builtInValues.Professional = require("./builtinslottypes/professionals.json");
recognizer.builtInValues.Professional.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Professional.values);
recognizer.builtInValues.Residence = require("./builtinslottypes/residences.json");
recognizer.builtInValues.Residence.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Residence.values);
recognizer.builtInValues.ScreeningEvent = require("./builtinslottypes/screeningevents.json");
recognizer.builtInValues.ScreeningEvent.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.ScreeningEvent.values);
recognizer.builtInValues.Service = require("./builtinslottypes/services.json");
recognizer.builtInValues.Service.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Service.values);
recognizer.builtInValues.SoftwareApplication = require("./builtinslottypes/softwareapplications.json");
recognizer.builtInValues.SoftwareApplication.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.SoftwareApplication.values);
recognizer.builtInValues.SportsEvent = require("./builtinslottypes/sportsevents.json");
recognizer.builtInValues.SportsEvent.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.SportsEvent.values);
recognizer.builtInValues.SocialMediaPlatform = require("./builtinslottypes/socialmediaplatforms.json");
recognizer.builtInValues.SocialMediaPlatform.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.SocialMediaPlatform.values);
recognizer.builtInValues.TVEpisode = require("./builtinslottypes/tvepisodes.json");
recognizer.builtInValues.TVEpisode.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.TVEpisode.values);
recognizer.builtInValues.TVSeason = require("./builtinslottypes/tvseasons.json");
recognizer.builtInValues.TVSeason.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.TVSeason.values);
recognizer.builtInValues.TVSeries = require("./builtinslottypes/tvseries.json");
recognizer.builtInValues.TVSeries.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.TVSeries.values);
recognizer.builtInValues.Athlete = require("./builtinslottypes/athletes.json");
recognizer.builtInValues.Athlete.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Athlete.values);
recognizer.builtInValues.AdministrativeArea = require("./builtinslottypes/administrativeareas.json");
recognizer.builtInValues.AdministrativeArea.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.AdministrativeArea.values);
recognizer.builtInValues.Month = {};
recognizer.builtInValues.Month.values = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
recognizer.builtInValues.Month.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Month.values);
recognizer.builtInValues.DayOfWeek = {};
recognizer.builtInValues.DayOfWeek.values = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
recognizer.builtInValues.DayOfWeek.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.DayOfWeek.values);
recognizer.builtInValues.Country = require("./builtinslottypes/countries.json");
recognizer.builtInValues.Country.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Country.values);
recognizer.builtInValues.Color = require("./builtinslottypes/colors.json");
recognizer.builtInValues.Color.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Color.values);
recognizer.builtInValues.Room = require("./builtinslottypes/rooms.json");
recognizer.builtInValues.Room.replacementRegExpString = _makeReplacementRegExpString(recognizer.builtInValues.Room.values);
/**
* This is the new version meant to be used with the parseutterance.js
*/
var _getReplacementRegExpStringGivenSlotType = function(slotType, config, slotFlags, matchStage){
if(typeof matchStage === "undefined"){
matchStage = "FINAL";
}
slotType = _getTranslatedSlotTypeForInternalLookup(slotType);
let simpleSlots = [
"TRANSCEND.US_FIRST_NAME", "TRANSCEND.Actor", "TRANSCEND.Artist", "TRANSCEND.Comic", "TRANSCEND.Dessert",
"TRANSCEND.LandmarksOrHistoricalBuildings", "TRANSCEND.Landform", "TRANSCEND.MovieSeries", "TRANSCEND.MovieTheater",
"TRANSCEND.MusicAlbum", "TRANSCEND.Musician", "TRANSCEND.MusicGroup", "TRANSCEND.MusicEvent", "TRANSCEND.Movie",
"TRANSCEND.MedicalOrganization", "TRANSCEND.LocalBusinessType", "TRANSCEND.LocalBusiness", "TRANSCEND.Game",
"TRANSCEND.FoodEstablishment", "TRANSCEND.FictionalCharacter", "TRANSCEND.Festival", "TRANSCEND.EducationalOrganization",
"TRANSCEND.Director", "TRANSCEND.CivicStructure", "TRANSCEND.BroadcastChannel",
"TRANSCEND.BookSeries", "TRANSCEND.Book", "TRANSCEND.Author", "TRANSCEND.Athlete",
"TRANSCEND.AdministrativeArea", "TRANSCEND.Country", "TRANSCEND.Color", "TRANSCEND.Room", "TRANSCEND.MusicRecording",
"TRANSCEND.MusicVenue", "TRANSCEND.MusicVideo", "TRANSCEND.Organization", "TRANSCEND.Person", "TRANSCEND.Professional",
"TRANSCEND.Residence", "TRANSCEND.ScreeningEvent", "TRANSCEND.Service", "TRANSCEND.SoftwareApplication", "TRANSCEND.SoftwareGame",
"TRANSCEND.SportsEvent", "TRANSCEND.SocialMediaPlatform", "TRANSCEND.TVEpisode", "TRANSCEND.TVSeason", "TRANSCEND.TVSeries", "TRANSCEND.VideoGame"
];
if(slotType === "TRANSCEND.NUMBER"){
// Ignore flags for now
if(matchStage === "FINAL"){
return recognizer.builtInValues.NUMBER.replacementRegExpString;
}
else {
return "((?:[-0-9a-zA-Z,.]|\\s)+)";
}
}
else if(slotType === "TRANSCEND.US_PHONE_NUMBER"){
// Ignore flags for now
if(matchStage === "FINAL"){
return recognizer.builtInValues.US_PHONE_NUMBER.replacementRegExpString;
}
else {
return "((?:[-0-9a-zA-Z.()]|\\s)+)";
}
}
else if(slotType === "TRANSCEND.FOUR_DIGIT_NUMBER"){
// Ignore flags for now
if(matchStage === "FINAL"){
return recognizer.builtInValues.FOUR_DIGIT_NUMBER.replacementRegExpString;
}
else {
return "((?:[0-9a-zA-Z,.]|\\s)+)";
}
}
else if(slotType === "TRANSCEND.US_PHONE_NUMBER"){
// Ignore flags for now
if(matchStage === "FINAL"){
return recognizer.builtInValues.US_PHONE_NUMBER.replacementRegExpString;
}
else {
return "((?:[0-9a-zA-Z,.]|\\s)+)";
}
}
else if(slotType === "TRANSCEND.US_STATE"){
if(matchStage === "FINAL"){
if(_hasFlag("EXCLUDE_NON_STATES", slotFlags)){
let states = [];
for(let i = 0; i < recognizer.builtInValues.US_STATE.values.length; i ++){
if(recognizer.builtInValues.US_STATE.values[i].isState){
states.push(recognizer.builtInValues.US_STATE.values[i].name);
}
}
let statesOnlyRegExpString = _makeReplacementRegExpString(states);
return statesOnlyRegExpString;
}
else {
let statesAndTerritories = [];
for(let i = 0; i < recognizer.builtInValues.US_STATE.values.length; i ++){
statesAndTerritories.push(recognizer.builtInValues.US_STATE.values[i].name);
}
let statesAndTerritoriesRegExpString = _makeReplacementRegExpString(statesAndTerritories);
return statesAndTerritoriesRegExpString;
}
}
else {
return "((?:[a-zA-Z.]|\\s)+)";
}
}
else if(slotType === "TRANSCEND.US_PRESIDENT"){
if(matchStage === "FINAL"){
let matchingStrings = [];
for(let i = 0; i < recognizer.builtInValues.US_PRESIDENT.values.length; i ++){
for(let j = 0; j < recognizer.builtInValues.US_PRESIDENT.values[i].matchingStrings.length; j ++){
matchingStrings.push(recognizer.builtInValues.US_PRESIDENT.values[i].matchingStrings[j]);
}
for(let j = 0; j < recognizer.builtInValues.US_PRESIDENT.values[i].ordinalMatchingStrings.length; j ++){
matchingStrings.push(recognizer.builtInValues.US_PRESIDENT.values[i].ordinalMatchingStrings[j]);
}
}
return _makeReplacementRegExpString(matchingStrings);
}
else {
return "((?:[0-9a-zA-Z.]|\\s)+)";
}
}
else if(slotType === "TRANSCEND.Airline"){
if(matchStage === "FINAL"){
// Ignore SOUNDEX_MATCH flag for now
let hasWildCardMatch = false;
let hasCountryFlag = false;
let countries = [];
let hasContinentFlag = false;
let continents = [];
let hasTypeFlag = false;
let types = [];
for(let i = 0; i < slotFlags.length; i++){
if(slotFlags[i].name === "COUNTRY"){
hasCountryFlag = true;
countries = slotFlags[i].parameters;
}
else if(slotFlags[i].name === "CONTINENT"){
hasContinentFlag = true;
continents = slotFlags[i].parameters;
}
else if(slotFlags[i].name === "TYPE"){
hasTypeFlag = true;
types = slotFlags[i].parameters;
}
else if(slotFlags[i].name === "INCLUDE_WILDCARD_MATCH"){
hasWildCardMatch = true;
}
}
if(hasWildCardMatch){
// numbers are used in cases of some names
return "((?:\\w|\\s|[0-9,_']|-)+)";
// return "((?:\\w|\\s|[0-9]|\-)+)";
}
else {
let allAirlines = [];
for(let i = 0; i < recognizer.builtInValues.Airline.values.length; i ++){
if(hasCountryFlag && countries.indexOf(recognizer.builtInValues.Airline.values[i].country) < 0){
continue;
}
if(hasContinentFlag && continents.indexOf(recognizer.builtInValues.Airline.values[i].continent) < 0){
continue;
}
if(hasTypeFlag && types.indexOf(recognizer.builtInValues.Airline.values[i].type) < 0){
continue;
}
allAirlines.push(recognizer.builtInValues.Airline.values[i].name);
}
let replacementRegExpString = _makeReplacementRegExpString(allAirlines);
return replacementRegExpString;
}
}
else {
return "((?:\\w|\\s|[0-9,_']|-)+)";
// return "(.+)";
}
}
else if(slotType === "TRANSCEND.SportsTeam"){
if(matchStage === "FINAL"){
// Ignore SOUNDEX_MATCH flag for now
let hasWildCardMatch = false;
let hasSportFlag = false;
let sports = [];
let hasLeagueFlag = false;
let leagues = [];
let hasIncludePriorNamesFlag = false;
for(let i = 0; i < slotFlags.length; i++){
if(slotFlags[i].name === "SPORT"){
hasSportFlag = true;
sports = slotFlags[i].parameters;
}
else if(slotFlags[i].name === "LEAGUE"){
hasLeagueFlag = true;
leagues = slotFlags[i].parameters;
}
else if(slotFlags[i].name === "INCLUDE_WILDCARD_MATCH"){
hasWildCardMatch = true;
}
else if(slotFlags[i].name === "INCLUDE_PRIOR_NAMES"){
hasWildCardMatch = true;
}
}
if(hasWildCardMatch){
// numbers are used in cases of some names
return "((?:\\w|\\s|[0-9,_']|-)+)";
// return "((?:\\w|\\s|[0-9]|\-)+)";
}
else {
let allSportsTeams = [];
for(let i = 0; i < recognizer.builtInValues.SportsTeam.values.length; i ++){
if(hasSportFlag && sports.indexOf(recognizer.builtInValues.SportsTeam.values[i].sport) < 0){
continue;
}
if(hasLeagueFlag && leagues.indexOf(recognizer.builtInValues.SportsTeam.values[i].league) < 0){
continue;
}
allSportsTeams.push(recognizer.builtInValues.SportsTeam.values[i].name);
if(typeof recognizer.builtInValues.SportsTeam.values[i].alternativeNames !== "undefined" && Array.isArray(recognizer.builtInValues.SportsTeam.values[i].alternativeNames)){
for(let j = 0; j < recognizer.builtInValues.SportsTeam.values[i].