// tokenizeVerbs.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Parser.prototype;
/**
* List of methods to be called during parse that perform
* regex operations on input in order to join phrasal verbs.
* @var AdventureJS.Parser#phrasal_patterns
* @type {Array}
*/
p.phrasal_patterns = [
"tokenizeTryGerunds",
"tokenizeTryToVerbs",
"tokenizeVerbGerunds",
"tokenizeVerbPrepNounPrepNounPrepNouns",
"tokenizeVerbNounPrepPrepNouns",
"tokenizeVerbNounPrepNounPrepNouns",
"tokenizeVerbPrepNounPrepNouns",
"tokenizeVerbPrepPrepPrepNouns",
"tokenizeVerbPrepPrepNouns",
"tokenizeVerbNounPrepNouns",
"tokenizeVerbNounPreps",
"tokenizeVerbPrepNouns",
];
/**
* <code>tokenizeVerbs</code> identifies phrasal or compound verb
* patterns such as "swing from tree to cliff on vine". This feature
* is mostly retired but for use in a small few instances such as
* aiding in identifying "plug in computer" vs "plug drain". An earlier
* version of the parser used this extensively to join phrasal verbs
* into distinct verbs such as "swing_from_to_on tree cliff vine",
* which worked well but ultimately proved to be inflexible.
* <br><br>
* The listed order of regex operations is important. We're calling them
* in order of longest to shortest, to ensure we don't accidentally
* catch partial phrases, like only finding "swing_from" out of
* "swing from tree to cliff on vine", and then not finding
* "swing_from_to_on", which is a distinct pattern.
* @memberOf AdventureJS.Parser
* @method AdventureJS.Parser#tokenizeVerbs
* @param {String} input Player input.
* @returns {String}
*/
p.tokenizeVerbs = function Parser_tokenizeVerbs(input) {
this.game.log(
"L1556",
"log",
"high",
`[tokenizeVerbs.js] tokenizeVerbs() receive: ${input}`,
"Parser"
);
// join phrasal verbs
if (1 < input.split(" ").length) {
for (let i = 0; i < this.phrasal_patterns.length; i++) {
let phrasal_input = this[this.phrasal_patterns[i]](input);
// this version returns the original input
// if (phrasal_input !== input) return input;
// this version returns the modified input
if (phrasal_input !== input) return phrasal_input;
}
}
this.game.log(
"L1557",
"log",
"high",
`[tokenizeVerbs.js] tokenizeVerbs() return:\n${input}`,
"Parser"
);
return input;
};
})();