<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mitcho.com &#187; nountypes</title>
	<atom:link href="http://mitcho.com/blog/tag/nountypes/feed/" rel="self" type="application/rss+xml" />
	<link>http://mitcho.com</link>
	<description></description>
	<lastBuildDate>Fri, 10 Feb 2012 23:24:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Exploring Command Chaining in Ubiquity: Part 1</title>
		<link>http://mitcho.com/blog/projects/exploring-command-chaining-in-ubiquity-part-1/</link>
		<comments>http://mitcho.com/blog/projects/exploring-command-chaining-in-ubiquity-part-1/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 20:35:37 +0000</pubDate>
		<dc:creator>mitcho</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mozilla Planet]]></category>
		<category><![CDATA[nountypes]]></category>
		<category><![CDATA[ubiquity]]></category>
		<category><![CDATA[verbs]]></category>

		<guid isPermaLink="false">http://mitcho.com/blog/?p=2760</guid>
		<description><![CDATA[Since the dawn of time people have been asking about command chaining in Ubiquity. If you have a translate command and an email command, it would be great to be able to, for example, translate hello to Spanish and email to Juanito. This is what we call command chaining or piping: in a single complex [...]
Related posts:<ol>
<li><a href='http://mitcho.com/blog/link/command-chaining-with-oni/' rel='bookmark' title='Command Chaining with Oni?'>Command Chaining with Oni?</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-commands-by-the-numbers/' rel='bookmark' title='Ubiquity Commands by The Numbers'>Ubiquity Commands by The Numbers</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-parser-the-next-generation-demo/' rel='bookmark' title='Ubiquity Parser: The Next Generation Demo'>Ubiquity Parser: The Next Generation Demo</a></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Since the <a href="http://labs.mozilla.com/2008/08/introducing-ubiquity/">dawn of time</a> people have been asking about command chaining in Ubiquity. If you have a <code>translate</code> command and an <code>email</code> command, it would be great to be able to, for example, <code>translate hello to Spanish and email to Juanito</code>. This is what we call <strong>command chaining</strong> or <strong><a href="http://en.wikipedia.org/wiki/Pipeline_(Unix)">piping</a></strong>: in a single complex query, specifying multiple (probably two) actions and using the first&#8217;s output as the second&#8217;s input.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<p>Today I hope to cover some of the technical considerations required in implementing command chaining in Ubiquity, and I will follow up soon with a blog post on the linguistic considerations required as well.</p>

<p><span id="more-2760"></span></p>

<h3>Technical considerations: hooking the pipes together</h3>

<p>I&#8217;d first like to lay out some technical challenges and questions. These can be broken into two different categories: (1) how the parse and display of suggestions is affected and (2) how the execution is affected.</p>

<h4>Matching inputs and outputs</h4>

<p>We&#8217;ll first consider how command chaining may affect the parsing. Ubiquity commands each specify the types of argument inputs that it expects using different <strong>noun types</strong>, such as <code>noun_arb_text</code> which accepts anything, <code>noun_type_number</code> which accepts numbers, or <code>noun_type_language</code>, which takes the name of a language. For example, the <code>translate</code> verb takes maximally three arguments: a <code>noun_arb_text</code> object, a <code>noun_type_language</code> goal (the language to translate into), and a <code>noun_type_language</code> source (the source language). In implementing command chaining, it will be necessary to identify the appropriate noun types for the <em>output</em> of a command.</p>

<p>The first question we must address here is <strong>&#8220;what is the chaining output of a command&#8221;?</strong> Is it the preview text? Some text output from the execution?</p>

<p><a href='http://www.flickr.com/photos/joemud/2851415655/'><img src="http://mitcho.com/blog/wp-content/uploads/2009/08/2851415655_1012a4cce0_o.jpg" alt="2851415655_1012a4cce0_o.jpg" border="0" width="650" height="226" /></a><br/><small><a href='http://www.flickr.com/photos/joemud/2851415655/'>Big fish eat da lil fish</a> by joemud, CC-SA-NC</small></p>

<p>To put this question into perspective, we note that Ubiquity commands can be broadly classified into two types: <strong>lookup</strong> and <strong>action execution</strong>. Here&#8217;s a classification which I believe to be exhaustive:<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup></p>

<table>
<tr><th>classification</th><th>preview</th><th>execution</th><th>example</th></tr>
<tr><td rowspan='4'>lookup</td><td rowspan='4'>data lookup</td><td>inserting result into page</td><td><code>translate</code></td></tr>
<tr><td>opening a website</td><td><code>weather</code>, most search commands</td></tr>
<tr><td>copying result to pasteboard</td><td><code>get email address</code></td></tr>
<tr><td>nothing</td><td><code></code></td></tr>
<tr><td>action</td><td>nothing (maybe a description<br/>of what the action will do)</td><td>an action which changes some state <br/>(in the browser or on the web)</td><td><code>quit firefox</code>, <code>email</code>, <code>twitter</code></td></tr>
</table>

<p>In light of this classification I believe we can say that lookup commands are much more likely to be the first verb in a command chain—conversely, chains such as <code>email hello to Blair and then do ...</code> or <code>twitter hello and then ...</code> are quite unlikely. What is much more likely is for the first verb to be a lookup function.</p>

<table>
<tr><th>first verb type</th><th>second verb type</th><th>example</th></tr>
<tr><td>lookup</td><td>action</td><td><code>translate this to Spanish and email to Aza</code></td>
<tr><td>lookup</td><td>lookup</td><td><code>translate this to English and then find it with Amazon</code></td>
<tr><td>action</td><td>action/lookup</td><td><i>no use case?</i></td>
</table>

<p>Thus in the same way that not all commands have a useful execution<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup> <strong>perhaps only lookup commands will have a chainable output: the results of the lookup.</strong> Even with this restriction, we will most likely need to implement a new &#8220;chainable output&#8221; method or getter in these commands. This means that commands will need to opt-in to become chainable, but I believe this is a necessary evil.</p>

<p>The second question we must address is <strong>&#8220;when do we establish the noun type of a command&#8217;s chainable output?&#8221;</strong> One unsung but crucial feature of the way Ubiquity works now is that suggestions&#8217; previews are not computed until that suggestion is selected (except for the first suggestion, which in most skins gets previewed immediately). Should we wait for all of the first verbs&#8217; chainable output to be computed and then run them through the <a href="http://mitcho.com/blog/projects/judging-noun-types/">noun type detection system</a>? Or should verbs with chainable output also <em>a priori</em> specify what noun types their output will be?</p>

<p>Both of these approaches have their problems. If we compute the chainable output of the first verb, run a noun type detection on it and <em>then</em> suggest the full combination if it matches what the second verb was expecting, this will have clear performance implications, not to mention that it could greatly complicate our <a href="https://wiki.mozilla.org/Labs/Ubiquity/Parser_2">parsing algorithm</a>. While the latter approach doesn&#8217;t have these performance implications, it does mean that it will have to list (by name or reference) the noun types that will match its output, meaning that if a command author is unaware of someone else&#8217;s noun type, that chain will be impossible, even if the chainable output itself does indeed match that noun type. The <em>a posteriori</em> approach would never have this issue. <strong>What other benefits or problems do you forsee with either of these approaches? Is there another approach which avoids these pitfalls?</strong></p>

<h4>(A)synchronous composability</h4>

<p>Once we have the noun types, parsing, and suggestions down, all that remains is to compute the previews and implement the composite execution. Since the Ubiquity command manager already wraps the preview and execute functions in a wrapper to facilitate localization, among other uses, it would be easy to make the command manager <a href="http://www.croczilla.com/blog/16">compose asynchronous processes pseudo-synchronously</a>. No major changes should be necessary to do the previews and executions, though, again, there will be a performance cost.</p>

<h3>Conclusion</h3>

<p>There are a number of technical questions which must be answered, mostly in the parsing/suggesting stage. The key questions to answer are:</p>

<ol>
<li>What is the chaining output of a command?</li>
<li>When do we establish the noun type of a command&#8217;s chainable output?</li>
</ol>

<p>I&#8217;ll make another post soon on the linguistic considerations necessary in making command chaining happen in a <a href="http://mitcho.com/blog/projects/how-natural-should-a-natural-interface-be/">natural</a> fashion.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>We&#8217;re going to limit our discussion here to this restriction that the two verbs are not simply two simultaneous commands, but two commands which operate successively on an input, i.e., that it is true piping. This for example rules out input such as <code>google dogs and translate cat to Spanish</code>, as the second command&#8217;s execution does not semantically depend on the first&#8217;s execution. This (hopefully uncontroversial) decision also affects the linguistic considerations to be made in my next post.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>If you know of a command which doesn&#8217;t neatly fit into &#8220;lookup&#8221; or &#8220;action&#8221;, please let me know.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>I believe we should mark these no-execution lookup commands visually so the user does not expect anything to happen if they execute it. This is <a href="http://ubiquity.mozilla.com/trac/ticket/651">trac #651</a>.&#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<p>Related posts:</p><ol>
<li><a href='http://mitcho.com/blog/link/command-chaining-with-oni/' rel='bookmark' title='Command Chaining with Oni?'>Command Chaining with Oni?</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-commands-by-the-numbers/' rel='bookmark' title='Ubiquity Commands by The Numbers'>Ubiquity Commands by The Numbers</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-parser-the-next-generation-demo/' rel='bookmark' title='Ubiquity Parser: The Next Generation Demo'>Ubiquity Parser: The Next Generation Demo</a></li>
</ol>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mitcho.com/blog/projects/exploring-command-chaining-in-ubiquity-part-1/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Nountype Quirks: Day 3: Geo Day</title>
		<link>http://mitcho.com/blog/projects/nountype-quirks-day-3/</link>
		<comments>http://mitcho.com/blog/projects/nountype-quirks-day-3/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 04:20:22 +0000</pubDate>
		<dc:creator>mitcho</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[Mozilla Planet]]></category>
		<category><![CDATA[nountypes]]></category>
		<category><![CDATA[scoring]]></category>
		<category><![CDATA[ubiquity]]></category>

		<guid isPermaLink="false">http://mitcho.com/blog/?p=2647</guid>
		<description><![CDATA[It&#8217;s time for one more installment of Nountype Quirks, where I review and tweak Ubiquity&#8217;s built-in nountypes. For an introduction to this effort, please read Judging Noun Types and my updates from Day 1 and Day 2. Today I ended up spending most of the day attempting to implement (but not yet completing) major improvements [...]
Related posts:<ol>
<li><a href='http://mitcho.com/blog/projects/nountype-quirks-day-2/' rel='bookmark' title='Nountype Quirks: Day 2'>Nountype Quirks: Day 2</a></li>
<li><a href='http://mitcho.com/blog/projects/nountype-quirks-day-1/' rel='bookmark' title='Nountype Quirks: Day 1'>Nountype Quirks: Day 1</a></li>
<li><a href='http://mitcho.com/blog/projects/judging-noun-types/' rel='bookmark' title='Judging Noun Types'>Judging Noun Types</a></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><style type='text/css'>
.scorebar {
  background-color:red;
  display:inline-block;
  height:0.5em;
  vertical-align:middle;
}
.scoretable td {
  font-size: 0.7em;
}
</style></p>

<p>It&#8217;s time for one more installment of Nountype Quirks, where I review and tweak <a href="http://ubiquity.mozilla.com">Ubiquity</a>&#8217;s built-in nountypes. For an introduction to this effort, please read <a href="http://mitcho.com/blog/projects/judging-noun-types/">Judging Noun Types</a> and my updates from <a href="http://mitcho.com/blog/projects/nountype-quirks-day-1/">Day 1</a> and <a href="http://mitcho.com/blog/projects/nountype-quirks-day-2/">Day 2</a>.</p>

<p>Today I ended up spending most of the day attempting to implement (but not yet completing) major improvements to the geolocation-related nountypes whose plans I lay out here.</p>

<p><em>Note: this blog post includes a number of graphs using HTML/CSS formatting. If you are reading this article through a feed reader or planet, I invite you to read it <a href="http://mitcho.com/blog/projects/nountype-quirks-day-3/">on my site</a>.</em><span id="more-2647"></span></p>

<h3><code>noun_type_geolocation</code></h3>

<p><code>noun_type_geolocation</code> is the nountype used by the <code>weather</code> command for its location argument in input like &#8220;weather near Chicago&#8221;. The neat feature of <code>noun_type_geolocation</code> is that it has a smart default value which uses Firefox&#8217;s geolocation system to give you your current location by default, so I can enter &#8220;weather&#8221; and get the suggestion &#8220;weather near Broomfield, Colorado&#8221; (not completely correct, but close enough for the weather). Otherwise, however, <code>noun_type_geolocation</code> does not do too hot&#8230; for any input you give it, it&#8217;ll just accept it with a score of 0.3, much like <code>noun_arb_text</code>. We could do better.</p>

<p>One issue with this <code>noun_type_geolocation</code> is a conceptual one. Is this nountype supposed to accept only municipalities? Countries? Or should it accept landmarks or addresses as well? Part of the issue is that it&#8217;s only used by one built-in command in Ubiquity now, <code>weather</code>. But to be called a general &#8220;geolocation&#8221; nountype, its output should not be specific to <code>weather</code>&#8217;s usage, which is to throw the result at the <a href="http://wunderground.com">Weather Underground</a> API.</p>

<p>I propose that we change this to be something like <code>noun_type_geo_town</code> and also make similar nountypes like <code>noun_type_geo_country</code>, <code>noun_type_geo_region</code>, going all the way down to <code>noun_type_address</code> (which already exists—see below). All of the nountypes in this family could use a geocoding API such as <a href="http://code.google.com/apis/maps/documentation/geocoding/index.html">Google&#8217;s</a> or <a href="http://developer.yahoo.com/maps/rest/V1/geocode.html">Yahoo&#8217;s</a>. Their <code>data</code> properties could include all of this geocoded geographic data (in English) and also the latitude/longitude coordinate data.</p>

<p>The <code>weather</code> command could then accept <code>noun_type_geo_town</code> but, as some municipalities are not in Weather Underground or, for some countries, it is only as granular as administrative districts, we could just display the results of the geocoding API but then give Weather Underground the geocoded latitude/longitude data.</p>

<h3><code>noun_type_async_address</code></h3>

<p><code>noun_type_async_address</code> attempts to do exactly what I&#8217;ve laid out above for the most granular level: that of geolocations with data all the way down to the street level. This is the nountype which is used for the built-in <code>map</code> command and uses the <a href="http://developer.yahoo.com/maps/rest/V1/geocode.html">Yahoo geocoding service</a> to accomplish this. Let&#8217;s see what kinds of results it returns:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='1'>mitcho</td><td>mitcho</td><td><span class='scorebar' style='width:250px'></span> 0.5</td></tr>
<tr><td rowspan='1'>grenada</td><td>grenada</td><td><span class='scorebar' style='width:450px'></span> 0.9</td></tr>
<tr><td>jono</td><td>jono</td><td><span class='scorebar' style='width:450px'></span> 0.9</td></tr>
<tr><td>mountain view</td><td>mountain view</td><td><span class='scorebar' style='width:450px'></span> 0.9</td></tr>
</table>

<p>Let&#8217;s lay out some immediate quirks:</p>

<ol>
<li>All scores are either 0.5 or 0.9. In general, if the Yahoo API returns some geocoded interpretation, it gets 0.9, but otherwise it accepts everything with 0.5.</li>
<li>The results that came back from the Yahoo service doesn&#8217;t add any useful information like the country or administrative region. Even the case stays lowercase.</li>
<li>Since when is Jono a location!? I&#8217;ll get back to this later.</li>
</ol>

<p>For starters, the Yahoo! Maps API terms of service dictate that we can&#8217;t use its geocoding service if we&#8217;re not also displaying Yahoo maps, so I rewrote it using the Google API which also had the advantage of offering JSON output.</p>

<p>One quirk of the Google Geocoding API, though, is that all of the resulting municipality names are only in English. Try for example queries for <a href="http://maps.google.com/maps/geo?q=Wien&amp;output=json&amp;oe=utf8&amp;sensor=false">Wien</a> or <a href="http://maps.google.com/maps/geo?q=%E6%9D%B1%E4%BA%AC&amp;output=json&amp;oe=utf8&amp;sensor=false">東京 (Tokyo)</a>. Since we want our suggestions to only add information to our input, not replace the input entirely (and especially not in another language), we&#8217;ll then only take results which have the input as an initial substring. On the other hand, if none of the results have the input as a proper prefix of the return value, we will take the geocoding information from the first result but with the original input as the display text. Such results will have a markedly lower score.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<p>As this is the <code>address</code> nountype, we&#8217;ll penalize results which do not have detailed information such as street address or town-level information. All of this is very easy to judge as every result from the API has a <a href="http://code.google.com/intl/ja/apis/maps/documentation/geocoding/index.html#GeocodingAccuracy">geocoding accuracy</a> value.</p>

<h3>The best laid plans of mice and men&#8230;</h3>

<p>I spent a good few hours this afternoon and evening <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/377daf3fe57a">attempting to implement</a> this new family of nountypes, including this new <code>nountype_geo_address</code>, but also <code>nountype_geo_subregion</code>, <code>nountype_geo_region</code>, and <code>nountype_geo_country</code>. Some of the quirks of the <code>weather</code> and <code>map</code> commands, however, have prevented me from completely replacing the legacy <code>noun_type_address</code> and <code>noun_type_geolocation</code> described above. I hope to continue this work again soon and actually make this transition, ideally before 0.5.2.</p>

<p>Look forward to one (or maybe two?) more episode(s) of Nountype Quirks where I hope to definitively explain, analyze, and tweak <code>matchScore</code>, the scoring algorithm which underlies the majority of the nountypes in Ubiquity. As always, I look forward to your comments and feedback.</p>

<h3>Bonus: Where&#8217;s Jono?</h3>

<p>It turns out that <code>noun_type_async_address</code> was recognizing &#8220;Jono&#8221; as an address because Jono is actually a location afterall! Not only that, but Jono is in Japan!!</p>

<p><img src="http://mitcho.com/blog/wp-content/uploads/2009/08/Picture-31.png" alt="Picture 3.png" border="0" width="594" height="525" /></p>

<p>You clearly <a href="http://jonoscript.files.wordpress.com/2009/06/ubiquity_japanese.png">can&#8217;t take Japan out of Jono</a>, but it turns out you can&#8217;t take Jono out of Japan either.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>If this crazy algorithm raises a red flag for anyone, you&#8217;re not alone&#8230; if you think of a more elegant solution, please let me know. This will no doubt be an issue when it comes to localizing the <code>address</code> nountype as well. I wish we could specify an output language for the Google Geocoding API&#8230; <img src='http://mitcho.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> &#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<p>Related posts:</p><ol>
<li><a href='http://mitcho.com/blog/projects/nountype-quirks-day-2/' rel='bookmark' title='Nountype Quirks: Day 2'>Nountype Quirks: Day 2</a></li>
<li><a href='http://mitcho.com/blog/projects/nountype-quirks-day-1/' rel='bookmark' title='Nountype Quirks: Day 1'>Nountype Quirks: Day 1</a></li>
<li><a href='http://mitcho.com/blog/projects/judging-noun-types/' rel='bookmark' title='Judging Noun Types'>Judging Noun Types</a></li>
</ol>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mitcho.com/blog/projects/nountype-quirks-day-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nountype Quirks: Day 2</title>
		<link>http://mitcho.com/blog/projects/nountype-quirks-day-2/</link>
		<comments>http://mitcho.com/blog/projects/nountype-quirks-day-2/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 22:44:52 +0000</pubDate>
		<dc:creator>mitcho</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[Mozilla Planet]]></category>
		<category><![CDATA[nountypes]]></category>
		<category><![CDATA[scoring]]></category>
		<category><![CDATA[ubiquity]]></category>

		<guid isPermaLink="false">http://mitcho.com/blog/?p=2635</guid>
		<description><![CDATA[Today I&#8217;m continuing the process of reviewing and tweaking all of the nountypes built-in to Ubiquity. For a more respectable introduction to this endeavor, please read my blog post from a couple days ago, Judging Noun Types and my status update from yesterday, Nountype Quirks: Day 1. Note: this blog post includes a number of [...]
Related posts:<ol>
<li><a href='http://mitcho.com/blog/projects/nountype-quirks-day-1/' rel='bookmark' title='Nountype Quirks: Day 1'>Nountype Quirks: Day 1</a></li>
<li><a href='http://mitcho.com/blog/projects/judging-noun-types/' rel='bookmark' title='Judging Noun Types'>Judging Noun Types</a></li>
<li><a href='http://mitcho.com/blog/projects/big-issues-and-small-issues-with-parser-2/' rel='bookmark' title='Big Issues and Small Issues with Parser 2'>Big Issues and Small Issues with Parser 2</a></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><style type='text/css'>
.scorebar {
  background-color:red;
  display:inline-block;
  height:0.5em;
  vertical-align:middle;
}
.scoretable td {
  font-size: 0.7em;
}
</style></p>

<p>Today I&#8217;m continuing the process of reviewing and tweaking all of the nountypes built-in to <a href="http://ubiquity.mozilla.com">Ubiquity</a>. For a more respectable introduction to this endeavor, please read my blog post from a couple days ago, <a href="http://mitcho.com/blog/projects/judging-noun-types/">Judging Noun Types</a> and my status update from yesterday, <a href="http://mitcho.com/blog/projects/nountype-quirks-day-1/">Nountype Quirks: Day 1</a>.</p>

<p><em>Note: this blog post includes a number of graphs using HTML/CSS formatting. If you are reading this article through a feed reader or planet, I invite you to read it <a href="http://mitcho.com/blog/projects/nountype-quirks-day-2/">on my site</a>.</em></p>

<p><span id="more-2635"></span></p>

<h3><code>noun_type_twitter_user</code></h3>

<p>Let&#8217;s begin again by considering the suggestions and scores that a variety of different inputs to this nountype return and see what quirks we find.</p>

<p>To test this nountype, I made sure I had logged into <a href="http://twitter.com">Twitter</a> once with the login <a href="http://twitter.com/mitchoyoshitaka/"><code>mitchoyoshitaka</code></a>.</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='2'>mitcho</td><td>mitchoyoshitaka</td><td><span class='scorebar' style='width:425px'></span> 0.85</td></tr>
<tr><td>mitcho</td><td><span class='scorebar' style='width:250px'></span> 0.5</td></tr>
<tr><td rowspan='2'>mitchoyoshi</td><td>mitchoyoshitaka</td><td><span class='scorebar' style='width:470px'></span> 0.94</td></tr>
<tr><td>mitcho</td><td><span class='scorebar' style='width:250px'></span> 0.5</td></tr>
<tr><td>test</td><td>test</td><td><span class='scorebar' style='width:250px'></span> 0.5</td></tr>
<tr><td>テスト</td><td><i>none</i></td><td></td></tr>
<tr><td>hello world</td><td><i>none</i></td><td></td></tr>
<tr><td>@test</td><td><i>none</i></td><td></td></tr>
</table>

<p><a href="http://mitcho.com/blog/projects/nountype-quirks-day-1/">As nountypes go</a>, this is looking pretty good. For usernames which look like logins we&#8217;ve saved before, we&#8217;re using <code>matchScore</code> to get decent differential scores.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> It&#8217;s even ruling out impossible twitter username strings, according to Twitter&#8217;s own restriction:</p>

<p><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/twitter-usernames.png" alt="twitter-usernames.png" border="0" width="574" height="75" /></p>

<p>One possible improvement we could make is to let @ strings be accepted. I <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/97871e3a453c">went ahead and made this improvement</a>. The initial @ will be stripped off and then will be checked as normal, but the final score will receive a slight boost using an <a href="http://en.wikipedia.org/wiki/nth_root"><i>n</i>th root</a> formula. The <code>twitter</code> command was also updated to deal with inputs with and without the initial @.</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='2'>mitcho</td><td>mitchoyoshitaka</td><td><span class='scorebar' style='width:425px'></span> 0.85</td></tr>
<tr><td>mitcho</td><td><span class='scorebar' style='width:250px'></span> 0.5</td></tr>
<tr><td rowspan='2'>@mitcho</td><td>@mitchoyoshitaka</td><td><span class='scorebar' style='width:440px'></span> 0.88</td></tr>
<tr><td>@mitcho</td><td><span class='scorebar' style='width:285px'></span> 0.57</td></tr>

<tr><td>test</td><td>test</td><td><span class='scorebar' style='width:250px'></span> 0.5</td></tr>
<tr><td>@test</td><td>@test</td><td><span class='scorebar' style='width:285px'></span> 0.57</td></tr>
</table>

<p>Although the <code>noun_type_twitter_user</code> nountype is currently most used by the built-in <code>twitter</code> command to specify the user&#8217;s username, in theory it could also be used for example in a command which pulls up another user&#8217;s tweets. With that in mind, perhaps in the future we could check the browser history and/or bookmarks for entries of the form <code>http://twitter.com/...</code> and suggest those as well (<a href="http://ubiquity.mozilla.com/trac/ticket/846">trac #846</a>).</p>

<h3><code>noun_type_number</code></h3>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='1'>text</td><td><i>none</i></td><td></td></tr>
<tr><td>0.5</td><td>0.5</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td>0.5.1</td><td><i>none</i></td><td></td></tr>
</table>

<p>This nountype has an incredibly simple job and does it with ease. I&#8217;m going to leave it alone.</p>

<h3><code>noun_type_date</code> and <code>noun_type_time</code></h3>

<p><code>noun_type_date</code> and <code>noun_type_time</code> both use the magical <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/parse">Date.parse</a> method to parse date- and time-like strings. Let&#8217;s first take a look at some of its suggestions:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th><code>date</code> suggestion</th><th><code>time</code> suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="250" height="15" /></th></tr>
<tr><td rowspan='1'>June 8th 5pm</td><td>2009-06-08</td><td>05:00 PM</td><td><span class='scorebar' style='width:250px'></span> 1</td></tr>
<tr><td rowspan='1'>5pm</td><td>2009-07-30</td><td>05:00 PM</td><td><span class='scorebar' style='width:250px'></span> 1</td></tr>
<tr><td rowspan='1'>5</td><td>2009-07-05</td><td>12:00 AM</td><td><span class='scorebar' style='width:250px'></span> 1</td></tr>
<tr><td rowspan='1'>June 8th</td><td>2009-06-08</td><td>12:00 AM</td><td><span class='scorebar' style='width:250px'></span> 1</td></tr>
<tr><td rowspan='1'>today</td><td>2009-07-30</td><td>12:00 AM</td><td><span class='scorebar' style='width:250px'></span> 1</td></tr>
<tr><td rowspan='1'>now</td><td>2009-07-30</td><td>02:40 PM</td><td><span class='scorebar' style='width:250px'></span> 1</td></tr>
<tr><td rowspan='1'>5pm is a good time</td><td><i>none</i></td><td><i>none</i></td><td></td></tr>
</table>

<p>The quirks in these outputs can be summed up into these two factors:</p>

<ol>
<li>There is no differential scoring at all.</li>
<li>Both nountypes parse the input with <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/parse">Date.parse</a> and then just spit out the date or time components of the result. Thus time-only inputs get the default date and date-only inputs get the default time with equal scores.</li>
</ol>

<p>I just rewrote both nountypes and also added a new <code>noun_type_date_time</code>. Here are some of the features of the new implementation:</p>

<ol>
<li>If the input only contains digits and spaces, it is marked down.</li>
<li>With the exception of the outputs &#8216;today&#8217; and &#8216;now&#8217;, if the resulting <code>Date</code> object&#8217;s date is today, its date suggestion is scored lower; equivalently for time being the default value, &#8220;12:00 AM&#8221;.</li>
<li>Scores (with the exception of &#8216;today&#8217; and &#8216;now&#8217;) which are shorter than the output string get a slight penalty. This factor reflects the intuition that a longer output than input means some generic information was added and thus there is less confidence in the output.</li>
</ol>

<p>Here&#8217;s what some of the inputs give now:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>

<tr><td rowspan='3'>June 8th 5pm</td><td><code>date</code>: 2009-06-08</td><td><span class='scorebar' style='width:350px'></span> 0.7</td></tr>
<tr><td><code>time</code>: 05:00 PM</td><td><span class='scorebar' style='width:350px'></span> 0.7</td></tr>
<tr><td><code>date_time</code>: 2009-06-08&#160;05:00 PM</td><td><span class='scorebar' style='width:430px'></span> 0.86</td></tr>

<tr><td rowspan='3'>5pm</td><td><code>date</code>: 2009-07-30</td><td><span class='scorebar' style='width:135px'></span> 0.27</td></tr>
<tr><td><code>time</code>: 05:00 PM</td><td><span class='scorebar' style='width:405px'></span> 0.81</td></tr>
<tr><td><code>date_time</code>: 2009-07-30&#160;05:00 PM</td><td><span class='scorebar' style='width:245px'></span> 0.49</td></tr>

<tr><td rowspan='3'>5</td><td><code>date</code>: 2009-07-05</td><td><span class='scorebar' style='width:265px'></span> 0.53</td></tr>
<tr><td><code>time</code>: 12:00 AM</td><td><span class='scorebar' style='width:95px'></span> 0.19</td></tr>
<tr><td><code>date_time</code>: 2009-07-05&#160;12:00 AM</td><td><span class='scorebar' style='width:170px'></span> 0.34</td></tr>

<tr><td rowspan='3'>June 8th</td><td><code>date</code>: 2009-06-08</td><td><span class='scorebar' style='width:475px'></span> 0.95</td></tr>
<tr><td><code>time</code>: 12:00 AM</td><td><span class='scorebar' style='width:175px'></span> 0.35</td></tr>
<tr><td><code>date_time</code>: 2009-06-08&#160;12:00 AM</td><td><span class='scorebar' style='width:170px'></span> 0.58</td></tr>

<tr><td rowspan='3'>today</td><td><code>date</code>: 2009-07-30</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td><code>time</code>: 12:00 AM</td><td><span class='scorebar' style='width:225px'></span> 0.45</td></tr>
<tr><td><code>date_time</code>: 2009-06-08&#160;12:00 AM</td><td><span class='scorebar' style='width:350px'></span> 0.7</td></tr>

<tr><td rowspan='3'>now</td><td><code>date</code>: 2009-07-30</td><td><span class='scorebar' style='width:350px'></span> 0.7</td></tr>
<tr><td><code>time</code>: 12:00 AM</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td><code>date_time</code>: 2009-06-08&#160;04:34 PM</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>

</table>

<p>In addition, looking to the future we&#8217;d <a href="http://mitcho.com/blog/projects/ubiquity-localization-whats-new-whats-next/">like to make nountypes localizable</a> as well, and these two nountypes in particular will surely require some good thinking and planning to make localizable.</p>

<h3><code>noun_type_email</code> and <code>noun_type_contact</code></h3>

<p><code>noun_type_email</code> and <code>noun_type_contact</code> are two closely related nountypes. <code>noun_type_email</code> simply validates email address-looking strings, while <code>noun_type_contact</code> will return the <code>noun_type_email</code> suggestions and additionally return contacts from GMail if available.</p>

<p>The first thing to note is that I&#8217;ve often found the GMail contact lookup to be finicky in my own use. Reading through the code, I discovered the solution: GMail must either be open in a tab or you must use the &#8220;stay signed in&#8221; option and close the GMail tab.<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> With this mystery solved, and <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/8478c7103753">some code cleanup done to this contact fetching</a>, let&#8217;s take a look at some example suggestions: (suggestions overlapping with <code>noun_type_email</code> are not listed here)</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='1'>aza@m</td><td>aza@mozilla.com</td><td><span class='scorebar' style='width:210px'></span> 0.42</td></tr>
<tr><td rowspan='1'>jono</td><td>jdicarlo@mozilla.com</td><td><span class='scorebar' style='width:140px'></span> 0.28</td></tr>
<tr><td rowspan='1'>jdicarlo</td><td>jdicarlo@mozilla.com</td><td><span class='scorebar' style='width:95px'></span> 0.19</td></tr>
</table>

<p>In general, we see that these scores all look pretty poor. In particular, though, note that the &#8220;jono&#8221; input yielded a higher score for the same suggestion than &#8220;jdicarlo&#8221;, even though &#8220;jdicarlo&#8221; is longer and thus, intuitively, has more informational content and should maybe do better. Digging into the code I realized why this is. It was computing the scores by comparing &#8220;jono&#8221; and &#8220;jdicarlo&#8221; not simply to &#8220;Jono DiCarlo&#8221; and &#8220;jdicarlo@mozilla.com&#8221; respectively, but to the combined string &#8220;Jono DiCarlo &lt;jdicarlo@mozilla.com&gt;&#8221;. Now with <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/0877848192f2">this change</a> in place, both the email address and name are analyzed individually and, due to the way nountype detection works in Parser 2, no duplicates are returned. Here are the updated results:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='1'>jono</td><td>jdicarlo@mozilla.com</td><td><span class='scorebar' style='width:415px'></span> 0.83</td></tr>
<tr><td rowspan='1'>jdicarlo</td><td>jdicarlo@mozilla.com</td><td><span class='scorebar' style='width:425px'></span> 0.85</td></tr>
</table>

<p>That&#8217;s much better!</p>

<p>Now let&#8217;s consider the suggestions from <code>noun_type_email</code>. Here are what they originally looked like:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='1'>bpung</td><td><i>none</i></td><td></td></tr>
<tr><td rowspan='1'>bpung@m</td><td>bpung@m</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td rowspan='1'>bpung@mozilla.com</td><td>bpung@mozilla.com</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
</table>

<p><code>noun_type_email</code> is based on <a href="http://blog.livedoor.jp/dankogai/archives/51190099.html">a very robust regular expression</a> for <a href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a>. Unfortunately this means that it completely rules out strings such as &#8220;bpung&#8221; which could be a proper prefix of an email address—something that I&#8217;ve advocated for avoiding before (see footnote 2 of <a href="http://mitcho.com/blog/projects/judging-noun-types/">Judging Noun Types</a>). Moreover, due to a quirk of how nountypes based on regular expressions are scored, all results are given the score of 1.</p>

<p>I <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/0d1803104c7d">just committed a change</a> so that this behavior is improved. The new version accepts strings which match the username part of the email address spec sans @ and domain, but with a great score penalty.<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup> Moreover, domains which do not have a final label (the <a href="http://en.wikipedia.org/wiki/top level domain">top level domain</a>) with more than one letter (unless it&#8217;s an IP address) or do not have any periods (.) in the domain will be penalized as well. Here&#8217;s what the same inputs produce now:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='1'>bpung</td><td>bpung</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td rowspan='1'>bpung@m</td><td>bpung@m</td><td><span class='scorebar' style='width:400px'></span> 0.8</td></tr>
<tr><td rowspan='1'>bpung@mozilla.com</td><td>bpung@mozilla.com</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
</table>

<h3>Same time, same channel</h3>

<p>I hope this post sheds light on the many changes I made together as well as the underlying thought process. If you don&#8217;t agree with any particular fix or analysis, please comment! I&#8217;ll be back again tomorrow with another installment of Nountype Quirks. Stay tuned!</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>Again, <code>matchScore</code> will be the subject of another blog post in the near future.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>Moreover, due to the way <code>noun_type_contact</code> caches the contact list internally, as long as GMail&#8217;s contacts are available once, you should be able to continue accessing those contacts&#8217; suggestions after logging out of GMail. There are also great performance benefits to this caching. The downside is that we currently have no way to know when to clear the cache, so even if you update your contacts in GMail, those new contacts won&#8217;t appear in Ubiquity until you restart Firefox.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>Perhaps this is a horrible idea, because if executed or previewed, any verb which uses these nountypes would have to deal with arguments which are not valid email addresses. In my mind, though, as long as it doesn&#8217;t actually cause any error, this should be okay. Keep in mind that, given the very low scores given to these suggestions, parses using it would most likely only show up if the verb which requires these nountypes was explicitly given and there are other arguments as well, for example in input like &#8220;email hello to bpung&#8221;. In such a situation, we would rather this suggestion not disappear until we type &#8220;@m&#8221;. If executed, the built-in email verb, for instance, will deal with this gracefully by simply putting the incomplete email address in the To field.&#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<p>Related posts:</p><ol>
<li><a href='http://mitcho.com/blog/projects/nountype-quirks-day-1/' rel='bookmark' title='Nountype Quirks: Day 1'>Nountype Quirks: Day 1</a></li>
<li><a href='http://mitcho.com/blog/projects/judging-noun-types/' rel='bookmark' title='Judging Noun Types'>Judging Noun Types</a></li>
<li><a href='http://mitcho.com/blog/projects/big-issues-and-small-issues-with-parser-2/' rel='bookmark' title='Big Issues and Small Issues with Parser 2'>Big Issues and Small Issues with Parser 2</a></li>
</ol>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mitcho.com/blog/projects/nountype-quirks-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nountype Quirks: Day 1</title>
		<link>http://mitcho.com/blog/projects/nountype-quirks-day-1/</link>
		<comments>http://mitcho.com/blog/projects/nountype-quirks-day-1/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 23:00:56 +0000</pubDate>
		<dc:creator>mitcho</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Mozilla Planet]]></category>
		<category><![CDATA[nountypes]]></category>
		<category><![CDATA[scoring]]></category>
		<category><![CDATA[ubiquity]]></category>

		<guid isPermaLink="false">http://mitcho.com/blog/?p=2598</guid>
		<description><![CDATA[Today I began the process of going through all of the nountypes built-in to Ubiquity using the principles and criteria I laid out yesterday—a task I&#8217;ve had in planning for a while now. As I explained yesterday, improved suggestions and scoring from the built-in nountypes could directly translate to better and smarter suggestions, resulting in [...]
Related posts:<ol>
<li><a href='http://mitcho.com/blog/projects/localizing-commands-for-ubiquity-0-5/' rel='bookmark' title='Localizing Commands for Ubiquity 0.5'>Localizing Commands for Ubiquity 0.5</a></li>
<li><a href='http://mitcho.com/blog/projects/judging-noun-types/' rel='bookmark' title='Judging Noun Types'>Judging Noun Types</a></li>
<li><a href='http://mitcho.com/blog/projects/a-demonstration-of-ubiquity-parser-2/' rel='bookmark' title='A Demonstration of Ubiquity Parser 2'>A Demonstration of Ubiquity Parser 2</a></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><style type='text/css'>
.scorebar {
  background-color:red;
  display:inline-block;
  height:0.5em;
  vertical-align:middle;
}
.scoretable td {
  font-size: 0.7em;
}
</style></p>

<p>Today I began the process of going through all of the nountypes built-in to <a href="http://ubiquity.mozilla.com">Ubiquity</a> using <a href="http://mitcho.com/blog/projects/judging-noun-types/">the principles and criteria I laid out yesterday</a>—a task I&#8217;ve had <a href="http://ubiquity.mozilla.com/trac/ticket/746">in planning</a> for a while now. As I explained yesterday, improved suggestions and scoring from the built-in nountypes could directly translate to better and smarter suggestions, resulting in a better experience for all users. Here I&#8217;ll document some of the nountype quirks I&#8217;ve discovered so far and what remedy has been implemented or is planned.</p>

<p><em>Note: this blog post includes a number of graphs using HTML/CSS formatting. If you are reading this article through a feed reader or planet, I invite you to read it <a href="http://mitcho.com/blog/projects/nountype-quirks-day-1/">on my site</a>.</em></p>

<p><span id="more-2598"></span></p>

<h3><code>noun_type_percentage</code></h3>

<p>Here&#8217;s what a few different inputs originally returned:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td>20</td><td>20%</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td>20%</td><td>20%</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td>0.2</td><td>20%</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td>0.2%</td><td>20%</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td>20.0</td><td>2000%</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td>2 hens in the garden</td><td>2%</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
</table>

<p>Let me highlight a couple obvious quirks:</p>

<ol>
<li>In certain cases, where the numerical expression includes a decimal and is less than one, it is interpreted as a proportional, rather than percent, value, e.g. &#8220;0.2&#8221; → &#8220;20%&#8221;. &#8220;0.2%&#8221; is not even an option. This is the case even when explicitly adding a % sign.</li>
<li>All suggestions, including those where the numeral was extracted from a long string of text (e.g. &#8220;2 hens in the garden&#8221;), get the same score of 1.</li>
</ol>

<p>I just <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/c3cd4af0f06a">committed a fix</a> so <code>noun_type_percentage</code> now&#8230;</p>

<ol>
<li>Counts the number of characters in the input which match <code>[\d.%]</code> and caps the score by (number of acceptable characters)/(length of input).</li>
<li>Strings which do not include &#8220;%&#8221; get a 10% penalty.</li>
<li>In the case of decimals less than 1 without a % sign, the proportion interpretation is also suggested (e.g. &#8220;0.2&#8221; → &#8220;20%&#8221;) in addition to the original suggestion (&#8220;0.2%&#8221;), but with a slight penalty.</li>
</ol>

<p>Here is what they now return:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td>20</td><td>20%</td><td><span class='scorebar' style='width:450px'></span> 0.9</td></tr>
<tr><td>20%</td><td>20%</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td rowspan='2'>0.2</td><td>0.2%</td><td><span class='scorebar' style='width:450px'></span> 0.9</td></tr>
<tr><td>20%</td><td><span class='scorebar' style='width:405px'></span> 0.81</td></tr>
<tr><td>0.2%</td><td>0.2%</td><td><span class='scorebar' style='width:500px'></span> 1</td></tr>
<tr><td>20.0</td><td>20%</td><td><span class='scorebar' style='width:450px'></span> 0.9</td></tr>
<tr><td>2 hens in the garden</td><td>2%</td><td><span class='scorebar' style='width:25px'></span> 0.05</td></tr>
</table>

<h3><code>noun_type_tag</code></h3>

<p>Here&#8217;s what a few different inputs originally returned. Keep in mind that currently in this test profile, the preexisting tags are &#8220;animal&#8221;, &#8220;help&#8221;, &#8220;test&#8221;, and &#8220;ubiquity&#8221;.</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td>animal</td><td>animal</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td>mineral</td><td>mineral</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td rowspan='2'>anim</td><td>animal</td><td><span class='scorebar' style='width:350px'></span> 0.7</td></tr>
<tr><td>anim</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td rowspan='2'>help, test, ubiq</td><td>help,test,ubiquity</td><td><span class='scorebar' style='width:350px'></span> 0.7</td></tr>
<tr><td>help,test,ubiq</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td rowspan='2'>google, yahoo, ubiq</td><td>google,yahoo,ubiquity</td><td><span class='scorebar' style='width:350px'></span> 0.7</td></tr>
<tr><td>google,yahoo,ubiq</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td>google, , yahoo</td><td>google,yahoo</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
</table>

<p>Here are a few of <code>noun_type_tag</code>&#8217;s quirks:</p>

<ol>
<li>There are only two scores ever given out: 0.3 and 0.7.</li>
<li>Only the last tag in the list and whether it exists or not is taken into account.</li>
<li>When the last tag is incomplete, the completion is suggested with a higher score, but if the last tag is <em>exactly</em> equal to an existing tag, it gets the lower score.</li>
</ol>

<p>Ideally, we want <code>noun_type_tag</code> to look at each of the tags given to it, with higher scores for when there are more preexisting tags and fewer new ones. Keep in mind, though, that we only have to suggest the completion of the very last tag as that may be one where the user hasn&#8217;t completed typing yet&#8230; for earlier tags, we can assume (safely or not) that the user placed the comma where they meant to. We can&#8217;t teach Ubiquity to read minds, after all.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<p>With this in mind, I <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/54e6a232ec3a">just made a change</a> to <code>noun_type_tag</code> which aims to follow these principles. The basic idea is that we start with a base score of 0.3 but then raise it via <a href="http://en.wikipedia.org/wiki/nth root"><i>n</i>th root</a> for every tag in the sequence which is preexisting. Here&#8217;s what the same inputs return now. Recall that the preexisting tags are &#8220;animal&#8221;, &#8220;help&#8221;, &#8220;test&#8221;, and &#8220;ubiquity&#8221;.</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td>animal</td><td>animal</td><td><span class='scorebar' style='width:275px'></span> 0.55</td></tr>
<tr><td>mineral</td><td>mineral</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td rowspan='2'>anim</td><td>animal</td><td><span class='scorebar' style='width:275px'></span> 0.55</td></tr>
<tr><td>anim</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td rowspan='2'>help, test, ubiq</td><td>help,test,ubiquity</td><td><span class='scorebar' style='width:430px'></span> 0.86</td></tr>
<tr><td>help,test,ubiq</td><td><span class='scorebar' style='width:370px'></span> 0.74</td></tr>
<tr><td rowspan='2'>google, yahoo, ubiq</td><td>google,yahoo,ubiquity</td><td><span class='scorebar' style='width:275px'></span> 0.55</td></tr>
<tr><td>google,yahoo,ubiq</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
<tr><td>google, , yahoo</td><td>google,yahoo</td><td><span class='scorebar' style='width:150px'></span> 0.3</td></tr>
</table>

<h3><code>noun_type_awesomebar</code></h3>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='4'>moz</td><td class="sugg">http://www.mozilla.com/</td><td class="score"><span style="width: 400px;" class="scorebar">&nbsp;</span> 0.8</td></tr>
<tr><td class="sugg">https://wiki.mozilla.org/Labs/Ubiquity/ Parser_2_API_Conversion_Tutorial</td><td class="score"><span style="width: 400px;" class="scorebar">&nbsp;</span> 0.8</td></tr>
<tr><td class="sugg">http://en-us.start3.mozilla.com/ firefox?client=firefox-a&#038;rls= org.mozilla:en-US:official</td><td class="score"><span style="width: 400px;" class="scorebar">&nbsp;</span> 0.8</td></tr>
<tr><td class="sugg">http://en-us.www.mozilla.com/en-US/firefox/about/</td><td class="score"><span style="width: 400px;" class="scorebar">&nbsp;</span> 0.8</td></tr>
</table>

<p>There are a couple quirks here:</p>

<ol>
<li>All suggestions are returned with the same scores.</li>
<li>The nountype returns the URL of the entry as the HTML-formatted result and the title as the text-formatted result, which clearly does not make sense. However, it&#8217;s not clear to me whether the title, URL, or some combination of both is what we should be returning as the suggestion text presented to the user.<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup></li>
</ol>

<p>I <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/cb98c72364db">just rewrote <code>noun_type_awesomebar</code></a> to actually do some differential scoring. This new version also presents the URL or title depending on whichever had a better match using the <code>matchScore</code> function.<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup></p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='4'>moz</td><td class="sugg">www.mozilla.com</td><td class="score"><span style="width: 350px;" class="scorebar">&nbsp;</span> 0.7</td></tr>
<tr><td class="sugg">https://wiki.mozilla.org/Labs/Ubiquity/ Parser_2_API_Conversion_Tutorial</td><td class="score"><span style="width: 315px;" class="scorebar">&nbsp;</span> 0.63</td></tr>
<tr><td class="sugg">http://en-us.start3.mozilla.com/ firefox?client=firefox-a&#038;rls= org.mozilla:en-US:official</td><td class="score"><span style="width: 305px;" class="scorebar">&nbsp;</span> 0.61</td></tr>
<tr><td class="sugg">http://en-us.www.mozilla.com/en-US/firefox/about/</td><td class="score"><span style="width: 300px;" class="scorebar">&nbsp;</span> 0.6</td></tr>
</table>

<h3><code>noun_type_url</code></h3>

<p>The purpose of <code>noun_type_url</code>&#8217;s suggest function is two-fold: first, to accept strings which may look like a URL and, second, to suggest URL&#8217;s from the history just like <code>noun_type_url</code>, but only based on URL matches and not title matches.<sup id="fnref:4"><a href="#fn:4" rel="footnote">4</a></sup> Here are a few sample inputs:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='5'>moz</td><td class="sugg">http://www.mozilla.com/</td><td class="score"><span style="width: 450px;" class="scorebar">&nbsp;</span> 0.9</td></tr>
<tr><td class="sugg">http://moz</td><td class="score"><span style="width: 250px;" class="scorebar">&nbsp;</span> 0.5</td></tr>
<tr><td class="sugg">https://wiki.mozilla.org/Labs/Ubiquity/ Parser_2_API_Conversion_Tutorial</td><td class="score"><span style="width: 450px;" class="scorebar">&nbsp;</span> 0.9</td></tr>
<tr><td class="sugg">http://en-us.start3.mozilla.com/ firefox?client=firefox-a&#038;rls= org.mozilla:en-US:official</td><td class="score"><span style="width: 450px;" class="scorebar">&nbsp;</span> 0.9</td></tr>
<tr><td class="sugg">http://en-us.www.mozilla.com/en-US/firefox/about/</td><td class="score"><span style="width: 450px;" class="scorebar">&nbsp;</span> 0.9</td></tr>

<tr><td rowspan='1'>test</td><td class="sugg">http://test</td><td class="score"><span style="width: 250px;" class="scorebar">&nbsp;</span> 0.5</td></tr>
<tr><td rowspan='1'>http://</td><td class="sugg">http://</td><td class="score"><span style="width: 250px;" class="scorebar">&nbsp;</span> 0.5</td></tr>
<tr><td rowspan='1'>http:</td><td class="sugg">http:</td><td class="score"><span style="width: 250px;" class="scorebar">&nbsp;</span> 0.5</td></tr>
<tr><td rowspan='1'>http</td><td class="sugg">http</td><td class="score"><span style="width: 250px;" class="scorebar">&nbsp;</span> 0.5</td></tr>
<tr><td rowspan='1'>_test</td><td class="sugg">http://_test</td><td class="score"><span style="width: 250px;" class="scorebar">&nbsp;</span> 0.5</td></tr>
<tr><td rowspan='1'>hello world!</td><td class="sugg">http://hello world!</td><td class="score"><span style="width: 250px;" class="scorebar">&nbsp;</span> 0.5</td></tr>
</table>

<p>Oh, where to begin!? Here are some initial quirks&#8230; it&#8217;s possible that you could think of more!</p>

<ol>
<li>There is no differential scoring&#8230; only 0.9 for suggestions from history and 0.5 for URL-like strings.</li>
<li>A number of invalid domain names are being accepted and turned into suggestions (&#8220;hello world!&#8221;, &#8220;_test&#8221;, etc.).</li>
<li>It&#8217;s trying to be smart by suggesting &#8220;http://&#8221; as a default <a href="http://en.wikipedia.org/wiki/URI scheme">URI scheme</a> but doing so even for prefixes (initial substrings) of the word &#8220;http&#8221; itself.</li>
</ol>

<p>With these thoughts in mind, I <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/rev/26f179661107">just took a first stab</a> at improving this situation. Here are some features of the new implementation:</p>

<ol>
<li>History entries are scored in the same way as in <code>noun_type_awesomebar</code>, using <code>matchScore</code>.</li>
<li>URLs without an explicit <a href="http://en.wikipedia.org/wiki/URI scheme">URI scheme</a> (like &#8220;http://&#8221;) get a 10% penalty.</li>
<li>&#8220;http://&#8221; is only suggested if one of a long list of common URI schemes are not detected.</li>
<li>It repairs schemes which are missing a slash or two, suggesting for example &#8220;http:hello.com&#8221; → &#8220;http://hello.com&#8221;.</li>
<li>It actually uses Firefox&#8217;s own <a href="https://developer.mozilla.org/en/nsIIDNService">IDNService</a> to check if the domain name is a valid <a href="http://en.wikipedia.org/wiki/internationalized domain name">internationalized domain name</a>. If it&#8217;s an IDN as opposed to LDH (&#8220;letters, digits, and hyphens&#8221;), it gets a 10% penalty. If it&#8217;s not even a valid IDN, it is ruled out (see last two example inputs below).</li>
<li>There are also penalties for only being a domain name with no path and for the domain not having any periods (.) in it.</li>
</ol>

<p>Here is what our suggestions now look like:</p>

<table style='border:0' class='scoretable'>
<tr><th>input</th><th>suggestion</th><th><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></th></tr>
<tr><td rowspan='5'>moz</td><td class="sugg">http://www.mozilla.com/</td><td class="score"><span style="width: 300px;" class="scorebar">&nbsp;</span> 0.6</td></tr>
<tr><td class="sugg">http://moz</td><td class="score"><span style="width: 325px;" class="scorebar">&nbsp;</span> 0.65</td></tr>
<tr><td class="sugg">https://wiki.mozilla.org/Labs/Ubiquity/ Parser_2_API_Conversion_Tutorial</td><td class="score"><span style="width: 315px;" class="scorebar">&nbsp;</span> 0.63</td></tr>
<tr><td class="sugg">http://en-us.start3.mozilla.com/ firefox?client=firefox-a&#038;rls= org.mozilla:en-US:official</td><td class="score"><span style="width: 305px;" class="scorebar">&nbsp;</span> 0.61</td></tr>
<tr><td class="sugg">http://en-us.www.mozilla.com/en-US/firefox/about/</td><td class="score"><span style="width: 300px;" class="scorebar">&nbsp;</span> 0.6</td></tr>

<tr><td rowspan='1'>test</td><td class="sugg">http://test</td><td class="score"><span style="width: 325px;" class="scorebar">&nbsp;</span> 0.65</td></tr>
<tr><td rowspan='2'>http://</td><td class="sugg">http://</td><td class="score"><span style="width: 500px;" class="scorebar">&nbsp;</span> 1</td></tr>
<tr><td class="sugg">shttp://</td><td class="score"><span style="width: 375px;" class="scorebar">&nbsp;</span> 0.75</td></tr>

<tr><td rowspan='2'>http:</td><td class="sugg">http://</td><td class="score"><span style="width: 450px;" class="scorebar">&nbsp;</span> 0.9</td></tr>
<tr><td class="sugg">shttp://</td><td class="score"><span style="width: 350px;" class="scorebar">&nbsp;</span> 0.7</td></tr>

<tr><td rowspan='4'>http</td><td class="sugg">http://</td><td class="score"><span style="width: 360px;" class="scorebar">&nbsp;</span> 0.72</td></tr>
<tr><td class="sugg">https://</td><td class="score"><span style="width: 355px;" class="scorebar">&nbsp;</span> 0.71</td></tr>
<tr><td class="sugg">shttp://</td><td class="score"><span style="width: 340px;" class="scorebar">&nbsp;</span> 0.68</td></tr>
<tr><td class="sugg">http://http</td><td class="score"><span style="width: 325px;" class="scorebar">&nbsp;</span> 0.65</td></tr>

<tr><td rowspan='1'>_test</td><td class="sugg"><i>none</i></td><td class="score">&nbsp;</td></tr>
<tr><td rowspan='1'>hello world!</td><td class="sugg"><i>none</i></td><td class="score">&nbsp;</td></tr></table>

<h3>See you tomorrow~</h3>

<p>Alright, enough nountype wrangling for one day. I&#8217;ll be back again tomorrow for another installment.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>If we could make assumptions about what tags look like, for example that they are always pretty short, or use certain character classes, we could use such factors as well to judge non-preexisting tags for &#8220;tagginess&#8221; but unfortunately it&#8217;s possible (though unlikely) that a user would prefer really long tag strings and of course Firefox allows tags in any unicode code range. The only strings we can immediately rule out as impossible are ones which are purely whitespace.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>It&#8217;s actually unclear whether the method we&#8217;re using (<a href="https://developer.mozilla.org/en/nsIAutoCompleteSearch"><code>nsIAutoCompleteSearch</code></a>) is actually searching titles or not&#8230; it currently looks like it&#8217;s only looking at the URL&#8217;s. Perhaps the title query is what we&#8217;re supposed to enter in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=507315">the mystery parameter</a>.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>I hope to discuss the <code>matchScore</code> function in a separate blog post later.&#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:4">
<p>While writing up this section I ran into a bug whereby when both <code>noun_type_awesomebar</code> and <code>noun_type_url</code> are active, only one of their async callbacks from <code>Utils.history.search</code> are returned. Thus, if lucky, only one of the nountypes will return the history results and if unlucky the parse query will not complete. Filed as <a href="http://ubiquity.mozilla.com/trac/ticket/845">trac #845</a>.&#160;<a href="#fnref:4" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<p>Related posts:</p><ol>
<li><a href='http://mitcho.com/blog/projects/localizing-commands-for-ubiquity-0-5/' rel='bookmark' title='Localizing Commands for Ubiquity 0.5'>Localizing Commands for Ubiquity 0.5</a></li>
<li><a href='http://mitcho.com/blog/projects/judging-noun-types/' rel='bookmark' title='Judging Noun Types'>Judging Noun Types</a></li>
<li><a href='http://mitcho.com/blog/projects/a-demonstration-of-ubiquity-parser-2/' rel='bookmark' title='A Demonstration of Ubiquity Parser 2'>A Demonstration of Ubiquity Parser 2</a></li>
</ol>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mitcho.com/blog/projects/nountype-quirks-day-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Judging Noun Types</title>
		<link>http://mitcho.com/blog/projects/judging-noun-types/</link>
		<comments>http://mitcho.com/blog/projects/judging-noun-types/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 06:39:11 +0000</pubDate>
		<dc:creator>mitcho</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Mozilla Planet]]></category>
		<category><![CDATA[nountypes]]></category>
		<category><![CDATA[scoring]]></category>
		<category><![CDATA[ubiquity]]></category>

		<guid isPermaLink="false">http://mitcho.com/blog/?p=2588</guid>
		<description><![CDATA[Introduction Different arguments are classified into different kinds of nouns in Ubiquity using noun types.1 For example, a string like &#8220;Spanish&#8221; could be construed as a language, while &#8220;14.3&#8221; should not be. These kinds of relations are then used by the parser to introduce, for example, language-related verbs (like translate) using the former argument, and [...]
Related posts:<ol>
<li><a href='http://mitcho.com/blog/observation/scoring-and-ranking-suggestions/' rel='bookmark' title='Scoring and Ranking Suggestions'>Scoring and Ranking Suggestions</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-localization-whats-new-whats-next/' rel='bookmark' title='Ubiquity Localization: What&#8217;s New, What&#8217;s Next'>Ubiquity Localization: What&#8217;s New, What&#8217;s Next</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-parser-the-next-generation-demo/' rel='bookmark' title='Ubiquity Parser: The Next Generation Demo'>Ubiquity Parser: The Next Generation Demo</a></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>

<p>Different arguments are classified into different kinds of nouns in Ubiquity using <em>noun types</em>.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> For example, a string like &#8220;Spanish&#8221; could be construed as a language, while &#8220;14.3&#8221; should not be. These kinds of relations are then used by the parser to introduce, for example, language-related verbs (like <code>translate</code>) using the former argument, and number-related verbs (like <code>zoom</code> or <code>calculate</code>) based on the latter. Ubiquity nountypes aren&#8217;t exclusive—a single string can count as valid for a number of different nountypes and in particular the &#8220;arbitrary text&#8221; nountype (<code>noun_arb_text</code>) will always accept any string given.</p>

<p>In addition to the <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/raw-file/tip/ubiquity/modules/nountypes.js">various built-in nountypes</a>, Ubiquity lets command authors <a href="https://wiki.mozilla.org/Labs/Ubiquity/Ubiquity_Source_Tip_Author_Tutorial#Writing_a_Noun_Type_Object">write their own nountypes</a> as well.</p>

<h3>The functions of a noun type</h3>

<p>Nountypes have two functions: the first is <strong>accepting and suggesting</strong> suggestions and the second is <strong>scoring</strong>.</p>

<p><span id="more-2588"></span></p>

<h4>Accepting and suggesting</h4>

<p>Nountypes don&#8217;t just have to accept the exact string they were given—they can also return suggestions which are based on that input. For example, the <code>noun_type_language</code> can take the input &#8220;span&#8221; and return &#8220;Spanish.&#8221; A nountype can return multiple suggestions which may or may not include the trivial suggestion, i.e. the original input as is. If there is no way that that input could possibly be part of an accepted value, it should return no suggestions, i.e. <code>[]</code>.<sup id="fnref:3"><a href="#fn:3" rel="footnote">2</a></sup></p>

<h4>Scoring</h4>

<p>Ubiquity 0.5 with Parser 2 introduced the notion of a nountype suggestion <em>score</em>. For example, two different nountypes can accept the same input, but with different scores. Scores range from 0 to 1 where 1 is a perfect or exact suggestion and 0.1 or so is a very very improbable suggestion.<sup id="fnref:2"><a href="#fn:2" rel="footnote">3</a></sup> These scores are used in the <a href="http://mitcho.com/blog/observation/scoring-for-optimization/">scoring of parses</a>. Because verbs specify certain nountypes for each of their arguments, the scores that individual nountypes return for each argument are a crucial component of the scoring algorithm and can even determine whether a parse is returned or not.</p>

<p>With this in mind, you may be tempted to make your nountype return a score of 1 on any input so your verb will show up in the suggestions highly. While this would work, it will only act to make your verb annoying and a poor Ubiquity citizen. Appropriate scores must be given to noun suggestions, with higher values reflecting confidence and lower values reflecting imprecision. <em>But how exactly do you figure out what&#8217;s an appropriate value?</em></p>

<h3>Judging nountypes with the Nountype Tuner</h3>

<p>The Nountype Tuner is a new tool I&#8217;ve been building to help both Ubiquity core developers and command authors to check their nountypes against others and to &#8220;tune&#8221; their behavior and scores. The nountype tuner will take your input and throw it against all of the nountypes referenced in your active verbs and display the suggestions returned with their scores. You can think of it as <a href="http://mitcho.com/blog/projects/changes-to-ubiquity-parser-2-and-the-playpen/">the Playpen</a>&#8217;s little sister.</p>

<p><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner.png" alt="tuner.png" border="0" width="650" height="646" /></p>

<p>The Nountype Tuner can be found at <a href='chrome://ubiquity/content/tuner.html'>chrome://ubiquity/content/tuner.html</a>, though I am pretty sure it is broken in Ubiquity 0.5 and 0.5.1. It has been fixed now and I will make sure it&#8217;s in good shape for 0.5.2.</p>

<p>The heart and soul of the Nountype Tuner is this scale:</p>

<p><center><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/tuner-top.png" alt="tuner-top.png" border="0" width="500" height="30" /></center></p>

<p>This scale tells you, <em>in plain English</em>, what different scores represent and correspond to, in two sets of vocabulary: &#8220;in terms of a guess&#8221; and &#8220;in terms of a match.&#8221; While still subjective, this scale helps developers just different input/output pairs and their scores. For example, &#8220;lian&#8221; → &#8220;http://lian&#8221; is given 0.5, so it&#8217;s an okay guess or a possible match&#8230; does that seem right to you? Or &#8220;lian&#8221; → &#8220;Italian&#8221; being between &#8220;okay&#8221; and &#8220;good.&#8221; Appropriate? We can look at such statements, decide how we feel about them, and tweak if necessary.</p>

<h3>Good nountype scores have roots</h3>

<p><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/roots.jpg" alt="roots.jpg" border="0" width="650" height="300" /></p>

<p><small>CC-BY <a href="http://www.flickr.com/photos/aaronescobar/2569091622/">Aaron Escobar</a></small></p>

<p>&#8230;not that kind of root, but more like <a href="http://en.wikipedia.org/wiki/Nth_root">this kind of root</a>&#8230; let me explain&#8230;</p>

<p>When comparing the scores that individual nountypes return for different inputs, we must compare those scores <em>within the same nountype&#8217;s family of suggestions</em> to see if higher scores truly correspond to higher confidence. For example, the language nountype should give the suggestion &#8220;French&#8221; for both the inputs &#8220;f&#8221; and &#8220;fren,&#8221; but the scores of these suggestions should be different—i.e. the score of &#8220;f&#8221; → &#8220;French&#8221; should be much lower than the score for &#8220;fren&#8221; → &#8220;French,&#8221; reflecting the additional informational value. We refer to this relation of the scores of successive prefixes of a single suggestion all returning that same suggestion as the <em>score curve</em> and in general it should be non-decreasing.<sup id="fnref:4"><a href="#fn:4" rel="footnote">4</a></sup></p>

<p>One could say the most trivial score function then is the linear one. For a series of converging prefixes of the same suggestion (&#8220;Dutch&#8221;), under a linear approach we could naively let the score be (length of the input)/(length of the suggestion), as below:</p>

<p><center></p>

<h4>the linear model</h4>

<table>
<tr><th>input</th><td>d</td><td>du</td><td>dut</td><td>dutc</td><td>dutch</td></tr>
<tr><th>output</th><td>Dutch</td><td>Dutch</td><td>Dutch</td><td>Dutch</td><td>Dutch</td></tr>
<tr><th>score</th><td>0.2</td><td>0.4</td><td>0.6</td><td>0.8</td><td>1</td></tr>
</table>

<p></center></p>

<p>This linear model is represented below by the black line.</p>

<p><center><img src="http://mitcho.com/blog/wp-content/uploads/2009/07/nth-roots.png" alt="nth-roots.png" border="0" width="299" height="262" /></center></p>

<p>The problem with the linear model is that earlier transitions (additional keystrokes) <em>add more information</em> than the later ones. Once we&#8217;ve entered &#8220;dutc,&#8221; after all, we would like to be <em>pretty darn sure</em> that we mean &#8220;Dutch,&#8221; so the score difference between &#8220;dutc&#8221; and &#8220;dutch&#8221; should be less than the score difference between, say, &#8220;d&#8221; and &#8220;du.&#8221; We want a score curve that looks more like the solid or dotted red lines above.</p>

<p>For this reason, <strong>I strongly advocate the incorporation of an <em>n</em>th-root in the score computation</strong>. <em>N</em>th-rooted score functions over [0,1] have the feature that they are increasing but also that earlier transitions affect the score more than later ones, which is exactly what we&#8217;d like to see. (The solid red line above is <code>x^1/2</code> and the dotted one is <code>x^1/3</code>.)<sup id="fnref:5"><a href="#fn:5" rel="footnote">5</a></sup></p>

<h3>Conclusion</h3>

<p>Properly tuning both the built-in nountypes and custom nountypes is crucial to producing more accurate and relevant parse suggestions. I&#8217;ll be using the principles and criteria laid out above, combined with the new Nountype Tuner, to <a href="http://ubiquity.mozilla.com/trac/ticket/746">tune the built-in nountypes (trac #746)</a> in the coming days in preparation for our <a href="http://tinyurl.com/lgekyh">0.5.2 release</a>. I invite you to use the Nountype Tuner in 0.5.2 to tune your custom nountypes as well.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>Or, as I often write them, &#8220;nountypes.&#8221;&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>Note that I didn&#8217;t just say &#8220;if the input is not an accepted value&#8230;&#8221; That&#8217;s because, based on the left-to-right nature of text input, an argument may later become a valid input of a certain nountype with a few more keystrokes. For example, if we had a URL nountype which accepted &#8220;http://mitcho.com&#8221; but not &#8220;http://mitcho&#8221;, any command which took this nountype would not show up in the suggestions while we were typing out &#8220;http://mitcho&#8221;&#8230; but would suddenly appear when we completed the &#8220;.com&#8221;. The best practice here is to suggest a valid value for the initial &#8220;http://mitcho&#8221;, like &#8220;http://mitcho.com&#8221;.<br/>(In reality, I should have said &#8220;initial-to-later nature&#8221; to be fair to right-to-left languages, but you get the idea. Speaking of which, serious consideration of Ubiquity in right-to-left languages is long overdue.)&#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>In reality, due to the way parses are scored and the fact that <code>noun_arb_text</code> accepts anything with score 0.3, a suggestion with score below 0.3 is probably not worth even giving out. Notable exceptions are for custom noun types which are used in commands which take multiple arguments&#8230; in these cases, even scores below 0.3 could add up and overtake a <code>noun_arb_text</code> parse, but it&#8217;s rare.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:4">
<p>The idea that successively longer inputs should yield successively higher scores only makes sense (1) when they are converging on the same suggestion output and (2) when these are truly suggestions, not just acceptances. For nountypes which accept the input verbatim, suggestion scores need not increase&#8230; for example &#8220;1&#8221; is just as good a &#8220;number&#8221; as &#8220;1234&#8221; is, so both of their respective suggestions, &#8220;1&#8221; and &#8220;1234&#8221; could be given the same score.&#160;<a href="#fnref:4" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:5">
<p>Unfortunately the Nountype Tuner currently only compares the suggestions of <em>one input</em> across a number of nountypes, not a number of inputs across the same nountype. In the future I&#8217;d like to make the Nountype Tuner be able to produce these sorts of score curves as well.&#160;<a href="#fnref:5" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<p>Related posts:</p><ol>
<li><a href='http://mitcho.com/blog/observation/scoring-and-ranking-suggestions/' rel='bookmark' title='Scoring and Ranking Suggestions'>Scoring and Ranking Suggestions</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-localization-whats-new-whats-next/' rel='bookmark' title='Ubiquity Localization: What&#8217;s New, What&#8217;s Next'>Ubiquity Localization: What&#8217;s New, What&#8217;s Next</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-parser-the-next-generation-demo/' rel='bookmark' title='Ubiquity Parser: The Next Generation Demo'>Ubiquity Parser: The Next Generation Demo</a></li>
</ol>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mitcho.com/blog/projects/judging-noun-types/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Ubiquity Commands by The Numbers</title>
		<link>http://mitcho.com/blog/projects/ubiquity-commands-by-the-numbers/</link>
		<comments>http://mitcho.com/blog/projects/ubiquity-commands-by-the-numbers/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 03:11:55 +0000</pubDate>
		<dc:creator>mitcho</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[herd]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[Mozilla Planet]]></category>
		<category><![CDATA[nountypes]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[ubiquity]]></category>
		<category><![CDATA[verbs]]></category>

		<guid isPermaLink="false">http://mitcho.com/blog/?p=1718</guid>
		<description><![CDATA[Recent work in the Ubiquity internationalization realm has focused on the upcoming Ubiquity parser which will bring some great new features to Ubiquity, including support for overlord verbs and semi-automatic localization of commands via semantic roles. It&#8217;s possible, though, that these new features will break backwards compatibility of the current command specification and noun types. [...]
Related posts:<ol>
<li><a href='http://mitcho.com/blog/projects/writing-commands-with-semantic-roles/' rel='bookmark' title='Writing commands with semantic roles'>Writing commands with semantic roles</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-parser-the-next-generation-demo/' rel='bookmark' title='Ubiquity Parser: The Next Generation Demo'>Ubiquity Parser: The Next Generation Demo</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-in-firefox-japanese/' rel='bookmark' title='Ubiquity in Firefox: Focus on Japanese'>Ubiquity in Firefox: Focus on Japanese</a></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Recent work in the Ubiquity internationalization realm has focused on the upcoming Ubiquity parser which will bring some great new features to Ubiquity, including support for <a href="http://jonoscript.wordpress.com/2009/01/24/overlord-verbs-a-proposal/">overlord verbs</a> and <a href="http://mitcho.com/blog/projects/writing-commands-with-semantic-roles/">semi-automatic localization of commands via semantic roles</a>. It&#8217;s possible, though, that these new features will break backwards compatibility of the current command specification and noun types. <a href="http://en.wikipedia.org/wiki/Creative destruction">Creative destruction</a> for the win.</p>

<p>As we look to <a href="http://groups.google.com/group/ubiquity-i18n/browse_thread/thread/22fa223f43ef6262">move forward</a> with incorporating <a href="http://mitcho.com/code/ubiquity/parser-demo/">the next generation parser</a> into Ubiquity proper, it thus becomes important to take a look at the current command ecosystem to see how possibly disruptive this move will be. To this end last night I wrote a quick perl script to scrape the commands cached on <a href="http://ubiquity.mozilla.com/herd/">the herd</a> and get some quantitative answers to my questions.</p>

<p><span id="more-1718"></span></p>

<p>(1577 different verbs were analyzed. None of these computations below are weighted by feed popularity.)</p>

<h3>Q: Are there a lot of commands which use more than one argument?</h3>

<p>A: The vast majority (>85%) of commands take one or no arguments, requiring no modifiers. Only those remaining 15% will require a switch to refer to different arguments by <a href="http://mitcho.com/blog/projects/writing-commands-with-semantic-roles/">semantic role</a>.</p>

<p><center><img src="http://mitcho.com/blog/wp-content/uploads/2009/03/herdcommands.png" alt="herdcommands.png" border="0" width="500" height="355" /></center></p>

<h3>Q: Do many commands introduce custom noun types?</h3>

<p>A: 147 different noun types (lumping anonymous inline objects as one type) were detected. The vast majority of all <code>takes</code> (direct object) arguments were of type <code>noun_arb_text</code>, although many <code>modifiers</code> arguments used custom noun types. The other standard (built-in) noun types are well represented as well, with <code>noun_type_language</code> coming in at second place. Here&#8217;s a chart with all the noun types which had more than one use.</p>

<div style='overflow-y: auto; max-height: 300px;'><center><img src="http://mitcho.com/blog/wp-content/uploads/2009/03/herdnountypes1.png" alt="herdnountypes.png" border="0" width="550" height="846" /></center></div>

<h3>Q: Are commands with <code>modifiers</code> using natural-language delimiters?</h3>

<p>A: Most of the modifiers detected were English prepositions such as &#8220;from&#8221;, &#8220;to&#8221;, &#8220;as&#8221;, &#8220;with&#8221;, but other words were also seen such as &#8220;title&#8221;, &#8220;type&#8221;, &#8220;username&#8221;, and &#8220;message&#8221; and even a handful of commands with symbols such as &#8220;@&#8221;, &#8220;>&#8221;, or &#8220;#&#8221;.</p>
<p>Related posts:</p><ol>
<li><a href='http://mitcho.com/blog/projects/writing-commands-with-semantic-roles/' rel='bookmark' title='Writing commands with semantic roles'>Writing commands with semantic roles</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-parser-the-next-generation-demo/' rel='bookmark' title='Ubiquity Parser: The Next Generation Demo'>Ubiquity Parser: The Next Generation Demo</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-in-firefox-japanese/' rel='bookmark' title='Ubiquity in Firefox: Focus on Japanese'>Ubiquity in Firefox: Focus on Japanese</a></li>
</ol>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mitcho.com/blog/projects/ubiquity-commands-by-the-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

