Changes

Jump to: navigation, search

Labs/Ubiquity/Ubiquity Source Tip Author Tutorial

265 bytes added, 05:48, 25 September 2008
Introduction to Noun Types
Our example command only cares about the <code>.text</code> attribute of the input, because it simply wants plain text. Often, when the user invokes your command by typing a few short words into the input box, <code>.text</code>, <code>.html</code>, and <code>.summary</code> will all have exactly the same value, and <code>.data</code> will be null. Many, if not most, commands that you write will only care about the text value. Nevertheless, the other versions of the input data are provided to you in case they differ from <code>.text</code> and in case your command has a use for them.
=== Introduction to Noun Types ===
Notice that we specified the type of argument to expect by passing in an object &mdash; in this case, the predefined <code>noun_arb_text</code> object, which accepts any arbitrary text as a valid argument. If we had wanted to restrict the inputs that our command could take, we could have used a more specific noun-type object to restrict the scope of the argument: for instance, <code>noun_type_date</code> to accept only dates (like the "check-calendar" command) or <code>noun_type_language</code> to accept only names of languages (like the optional modifiers for the "translate" command).
The benefit of specifying a more restrictive noun-type is that it helps the Ubiquity parser generate better suggestions and auto-completions based on user-input. For instance, if the user has a date selected, commands that operate specifically on dates are more likely to be apropos than commands that take arbitrary text, so Ubiquity can suggest the date-specific commands first.
There are many types Here's an example of nouns that what a command could conceivably takenoun type looks like:<pre>var noun_type_foo = { _name: people"foo", dates suggest: function( text, placeshtml, tabscallback ) { }, etc. Many of these noun default: function() { }};</pre> Noun types with built-types aren't implemented yet, and most in implementations that can be used by any command include: * noun_arb_text (Arbitrary text)* noun_type_language (Name of the them currently have a lack-luster implementationhuman language, e. This is one of the areas where Ubiquity could use the greatest helpg. Noun-types enable creating compelling user experiences"English", "Japanese")* noun_type_url (A URL)* noun_type_contact (An email address from your address book)* noun_type_date (A date, in any format, or a word like "tomorrow")* noun_type_time (A time, with minimal amounts of code. It also allows for code-reuse across numerous commands.in any format)* noun_type_percentage* noun_type_address* noun_type_tab* noun_type_searchengine* noun_type_tag* noun_type_geolocation 
Once you are familiar with writing commands, you should check out the [http://hg.toolness.com/ubiquity-firefox/file/6caa9d66b3bb/ubiquity/chrome/content/nlparser/en/nountypes.js nountypes.js], which has the implementation for most of the noun-types. You can see what noun types are already available for your commands to use, what still needs to be written, and where the existing implementations could use improvement &mdash; and then come [[Labs/Ubiquity#Participation|get involved]] to help us improve them.
1,007
edits

Navigation menu