1,007
edits
| Line 144: | Line 144: | ||
* {text:"javanese", data: "jv"} | * {text:"javanese", data: "jv"} | ||
(This is a bad example because we don't actually have Javanese implemented, but bear with me.) Meanwhile, | (This is a bad example because we don't actually have [http://en.wikipedia.org/wiki/Javanese_language Javanese] implemented, but bear with me.) Meanwhile, the type of the direct object, noun_arb_text, produces just one suggestion: | ||
{text:"hello, world"} | {text:"hello, world"} | ||
| Line 152: | Line 152: | ||
* Verb: Translate; Direct object: {text:"hello, world"}; To: {text:"japanese"} | * Verb: Translate; Direct object: {text:"hello, world"}; To: {text:"japanese"} | ||
* Verb: Translate; Direct object: {text:"hello, world"}; To: {text:"javanese"} | * Verb: Translate; Direct object: {text:"hello, world"}; To: {text:"javanese"} | ||
If you've written commands, you probably recognize these noun suggestions -- they are the objects that end up getting passed in to your <tt>.execute()</tt> and <tt>.preview()</tt> methods: | |||
<pre> | |||
CreateCommand({ | |||
name: "translate", | |||
execute: function( directObj, languages ) { | |||
var toLangCode = languages.to.data || this._getDefaultLang(); | |||
// assuming user picked first suggestion, languages.to.data has value "jp" | |||
var fromLang = languages.from.data || ""; | |||
translateTo( directObj.text, {to:toLangCode} ); | |||
// assuming user picked first suggestion, directObj.text has value "hello, world" | |||
// etc. | |||
</pre> | |||
There's no limit to how many arguments a verb can have, nor is there a limit on how many suggestions a noun_type can produce. If a PartiallyParsedSentence has three arguments, and each argument's noun_type returns three suggestions, then the algorithm must create a FullyParsedSentence for each possible ''combination'', so there are 3 x 3 x 3 = '''27''' FullyParsedSentences to instantiate. (Which will later be ranked, sorted, and trimmed down to just the top few.) This is a pathological edge case; in the vast majority of situations there is at most one noun_type returning multiple suggestions. Nevertheless, we have to handle this stuff, which is why the code for turning PartiallyParsed into FullyParsed is so complex. | |||
=== Filling missing arguments with the selection === | === Filling missing arguments with the selection === | ||
edits