Labs/Ubiquity/Parser Documentation: Difference between revisions

Jump to navigation Jump to search
Line 45: Line 45:
Each verb is scored against the input string, using the metric described in [https://wiki.mozilla.org/Labs/Ubiquity/Parser_Documentation#Scoring_the_Quality_of_the_Verb_Match Scoring the Quality of the Verb Match].  These scores will be used later to sort the suggestions in order from best to worst, but for now we only care whether a verb gets a score greater than zero.  Verbs that get a match quality score of 0 are discarded at this point, while anything with a positive number -- meaning it matches at all, no matter how tenuously -- continues to the next step.
Each verb is scored against the input string, using the metric described in [https://wiki.mozilla.org/Labs/Ubiquity/Parser_Documentation#Scoring_the_Quality_of_the_Verb_Match Scoring the Quality of the Verb Match].  These scores will be used later to sort the suggestions in order from best to worst, but for now we only care whether a verb gets a score greater than zero.  Verbs that get a match quality score of 0 are discarded at this point, while anything with a positive number -- meaning it matches at all, no matter how tenuously -- continues to the next step.


=== Meanwhile: Parsing the Arguments ===
=== the PartiallyParsedSentence object ===


(Also language-dependent)
The [https://ubiquity.mozilla.com/hg/ubiquity-firefox/file/71b710040206/ubiquity/modules/parser/parser.js#l477 NLParser.PartiallyParsedSentence object], defined in parser.js, represents a ''particular way of assigning'' input substrings to the arguments of a particular verb.
 
For example, the <tt>translate</tt> verb has these arguments:
 
* Direct object (the string to translate) which can be any string.
* "to", the language to translate to, which is noun_type_language so it can only be a language name.
* "from", the language to translate from, also noun_type_language.
 
So when given the following input:
 
trans hello world to ja
 
there are two PartiallyParsedSentences that can be created:
 
# Direct object is "hello world to ja".  "to" and "from" arguments undefined.
# Direct object is "hello world", "to" argument is "ja", "from" argument undefined.
 
The PartiallyParsedSentence class encapsulates the verb, a mapping of strings to arguments, and various logic for dealing with these things.  It also handles selection interpolation, about which more later.


=== Assigning input substrings to command arguments ===
=== Assigning input substrings to command arguments ===


To create PartiallyParsedSentences
[https://ubiquity.mozilla.com/hg/ubiquity-firefox/file/71b710040206/ubiquity/modules/parser/locale_en.js#l58 _recursiveParse() in locale_en.js]
 
This is language specific, because it depends on the grammar of the language.  In English, we expect prepositions to come before nouns -- that is, we expect the word "to" to come before ''the language that the user wants to translate to''.  So any substring that follows the word "to" could potentially be assigned to the "to" argument.


To further complicate this,


== Noun-First Parsing ==
== Noun-First Parsing ==
1,007

edits

Navigation menu