Labs/Ubiquity/Parser 2 API Conversion Tutorial: Difference between revisions

Line 43: Line 43:


=== Specifying semantic roles ===
=== Specifying semantic roles ===
The biggest change in the Parser 2 API is that arguments are now specified using abstract ''semantic roles'' instead of language-specific markers. (See [[Labs/Ubiquity/Parser_2/Semantic_Roles|Semantic roles in Parser 2]] for further explanation of semantic roles and the rationale for this change.) Arguments which previously were specified in <code>takes</code>, direct objects, use the role "object". Arguments which were specified in <code>modifiers</code> are specified using different semantic roles, based on the grammatical function of the argument, instead of by its English preposition. For example, an argument introduced by "to" would now be marked with the role <code>goal</code>, and an argument introduced by "using" would be encoded as <code>instrument</code>. These arguments are then all specified together with their nountypes in an array as property <code>arguments</code>.
'''Parser 1 (old) API:'''
  CmdUtils.CreateCommand({
    ...
    takes: {query: noun_arb_text}
    modifiers: {'using': noun_type_searchengine}
    ...
'''Parser 2 (new) API:'''
  CmdUtils.CreateCommand({
    ...
    arguments: [ {role: 'object', nountype: noun_arb_text},
                {role: 'instrument', nountype: noun_type_searchengine} ],
    ...
Please refer to [[Labs/Ubiquity/Parser_2/Semantic_Roles|Semantic roles in Parser 2]] for a list of supported semantic roles with examples of their use.
In addition, the old-style (but rare) <code>DOType</code> and <code>DOLabel</code> specifications are also no longer supported.


=== Using semantic roles in <code>preview</code> and <code>execute</code> ===
=== Using semantic roles in <code>preview</code> and <code>execute</code> ===
308

edits