Changes

Jump to: navigation, search

Labs/Ubiquity/Ubiquity Source Tip Author Tutorial

242 bytes added, 02:43, 22 June 2009
Introduction to Noun Types
== Introduction to Noun Types ==
Notice that we specified the type Noun types specify what ''kind'' 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 input your command could take, we could have used a more specific noun-type object to restrict the scope of the argument: can accept 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 each one of languages (like the optional modifiers for the "translate" command)its arguments.
The benefit of specifying a more restrictive noun-type is that it helps For the Ubiquity parser generate better suggestions and auto-completions based on user-input. For instance"echo" command, if we wanted the user has a date selected, commands that operate specifically on dates are more likely object-role argument to be apropos than commands that take arbitrary accept any textwhatsoever, so Ubiquity can suggest for its nountype we passed in the predefined <code>noun_arb_text</code> object. This object accepts any arbitrary text as a valid argument and passes it to the date-specific commands firstcommand unchanged.
HereThis is OK for very simple commands, like echoing back the user's an input. But for commands that take structured data, you will want to use more specific nountypes. For example of what , if a command can take a noun type looks date (like:<pre>var noun_type_foo = { _name: the "foocheck calendar"command), suggestyou would want to use <code>noun_type_date</code> as the nountype of the argument. <code>noun_type_date</code> provides several benefits to your command: function it does all of the date parsing for you; it suggests dates that the user might want to enter ( textfor instance, htmlit defaults to today's date). And, callback ) { }it lets the parser know that your command takes a date. This is useful because when the user selects a date on a page and invokes Ubiquity, default: function() { }};</pre>your command -- along with "check calendar" -- will be one of the top suggestions.
Noun You can write your own noun types with -- we'll get into that later. For now, let's take a look at the built-in implementations nountypes that your command can be used by any command use. These include:
* noun_arb_text (Arbitrary text)
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.
 
Here's an example of what a noun type looks like:
<pre>
var noun_type_foo = {
_name: "foo",
suggest: function( text, html, callback ) {
},
default: function() {
}
};
</pre>
== Insert Email: Commands with Specific Argument Types ==
1,007
edits

Navigation menu