1,007
edits
Changes
→Introduction to Noun Types
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 — and then come [[Labs/Ubiquity#Participation|get involved]] to help us improve them.
=== Regexps as Noun Types ===
If none of the nountypes above is what you're looking for, there are several ways to define your own. The simplest is to use a regular expression. Suppose that (for whatever odd reason) you wanted your command to accept only arguments that begin with the letter N. The following regexp matches words that start with N:
<pre>
/^[nN]/
</pre>
You could use it as a noun type, like so:
<pre>
arguments: [{role: "object",
nountype: /^[nN]/,
label: "word that starts with n"}]
</pre>
(Note that you do ''not'' put quotes around the regexp.)
A regexp nountype will reject input that doesn't match, but it doesn't know how to help the user by suggesting appropriate input.
=== Lists as Noun Types ===
=== Writing a Noun Type Object ===
The most involved way of creating a custom nountype is to write an object that implements a <code>suggest()</code> method (and, optionally, a <code>default()</code> method.)
Here's an example of what a noun type looks like: