// joinPhrasalVerbPrepNounPrepNounPrepNouns.js
(function () {
/*global adventurejs A*/
var p = adventurejs.Parser.prototype;
/**
* <p>
* Search input for verb phrases in the format of
* "verb preposition noun preposition noun preposition noun".
* We compare the input string against entries in
* dictionary.verb_prep_noun_prep_noun_prep_nouns,
* which was populated by Verb definitions.
* If we find a set of words that match an entry,
* we save a record for use with future verb logic.
* </p>
* <p>
* For example:<br>
* <code class="property">"swing from tree to stalactite on vine"</code>
* is identified as
* <code class="property">"swing_from_to_on tree stalactite vine"</code>.
* </p>
* @memberOf adventurejs.Parser
* @method adventurejs.Parser#joinPhrasalVerbPrepNounPrepNounPrepNouns
* @param {String} input Player input.
* @returns {String}
*/
p.joinPhrasalVerbPrepNounPrepNounPrepNouns =
function Parser_joinPhrasalVerbPrepNounPrepNounPrepNouns(input) {
for (
var i = 0;
i < this.dictionary.verb_prep_noun_prep_noun_prep_nouns.length;
i++
) {
var verb_phrase =
this.dictionary.verb_prep_noun_prep_noun_prep_nouns[i][0];
var verb_id = this.dictionary.verb_prep_noun_prep_noun_prep_nouns[i][1];
var verb = verb_phrase.split(" ")[0];
var prep1 = verb_phrase.split(" ")[1];
var prep2 = verb_phrase.split(" ")[2];
var prep3 = verb_phrase.split(" ")[3];
/**
* Valid chars are alphanumeric, plus:
* " " spaces, used as delimeters
* "_" underscores, used to serialize compound names
* "," commas, stripped from input but then used with multiple search results
* "=" used with multiple search results
* "&" used with multiple search results
*/
var search =
verb +
" " +
prep1 +
" ([,_=&A-Za-z0-9]*) " +
prep2 +
" ([,_=&A-Za-z0-9]*) " +
prep3 +
" ([,_=&A-Za-z0-9]*)";
var regex = new RegExp(search, "g");
var replaced = input.replace(regex, verb_id + " $1" + " $2" + " $3");
if (replaced !== input) {
// save a record of the original input
this.input_history[0].input_verb = verb_id;
this.input_history[0].verb_phrase = verb_phrase;
this.input_history[0].verb_phrase_prepositions = `${prep1} ${prep2} ${prep3}`;
this.input_history[0].verb_phrasal_pattern =
"verb_prep_noun_prep_noun_prep_noun";
// this version replaces the verb with the verb phrase
input = replaced;
// this version replaces the verb with the verb id
// if (verb !== verb_id) {
// input = input.replace(verb, verb_id);
// }
break;
}
}
this.game.log(
"L1226",
"log",
"high",
"joinPhrasalVerbPrepNounPrepNounPrepNouns.js > return: " + input,
"Parser"
);
return input;
};
})();