[Mulgara-svn] r136 - trunk/docs/site

pag at mulgara.org pag at mulgara.org
Tue Nov 21 20:20:04 UTC 2006


Author: pag
Date: 2006-11-21 14:20:04 -0600 (Tue, 21 Nov 2006)
New Revision: 136

Modified:
   trunk/docs/site/187.htm
Log:
Update the documentation on minus and exclude

Modified: trunk/docs/site/187.htm
===================================================================
--- trunk/docs/site/187.htm	2006-11-20 07:41:04 UTC (rev 135)
+++ trunk/docs/site/187.htm	2006-11-21 20:20:04 UTC (rev 136)
@@ -11,7 +11,7 @@
 <meta name="copyright" content="Copyright &copy; 2003, Kowari Project" />
 <meta name="robots" content="all" />
 <meta name="description" content="Mulgara Project Home" />
-<meta name="keywords" content="select, mulgara project, metadata, metastore, metadatabase, datastore, database, scaleable, scalable, transaction, java, open source,homepage" />
+<meta name="keywords" content="select mulgara, mulgara project, metadata, metastore, metadatabase, datastore, database, scaleable, scalable, transaction, java, open source, mulgara, homepage" />
 <meta name="location" content="Global" />
 <meta name="document-distribution" content="Global" />
 
@@ -20,7 +20,7 @@
 <meta http-equiv="language" content="English" />
 <meta http-equiv="window-target" content="_top" />
 
-<meta name="DC.Title" content="mulgara : semantic store" />
+<meta name="DC.Title" content="Mulgara : metastore" />
 <meta name="DC.Creator" content="Tom Adams" />
 <meta name="DC.Creator.Address" content="http://www.adams.id.au/tom/index.php" />
 <!--<meta name="DC.Contributor" content="Andrew Newman" />-->
@@ -29,9 +29,9 @@
 <meta name="DC.Date.Created" scheme="iso8601" content="2003-09-22" />
 <meta name="DC.Modified" scheme="iso8601" content="2003-09-22" />
 <meta name="DC.Language" scheme="rfc1766" content="en" />
-<meta name="DC.Rights" scheme="URI" content="http://www.kowari.org/about/index.php#copyright" />
+<meta name="DC.Rights" scheme="URI" content="http://mulgara.org/docs/legal.html" />
 <meta name="DC.Type" content="Text.Homepage.Personal" />
-<meta name="DC.Identifier" scheme="URI" content="http://mulgara.org/" />
+<meta name="DC.Identifier" scheme="URI" content="http://mulgara.org/index.php" />
 
 <meta name="Generator" content="AITPublish" />
 
@@ -52,7 +52,7 @@
 </tr>
 </table>
 <h2 class="heading2">select</h2>
-<p class="bodytext">Issues queries to Mulgara servers and displays the corresponding results. The command consists of a sequence of <code class="monospace"><a id="h217" class="documentlinktemplate" title="select Clause" href="187.htm#o188" target="_self">select</a></code>, <code class="monospace"><a id="h218" class="documentlinktemplate" title="from Clause" href="187.htm#o189" target="_self">from</a></code>, and <code class="monospace"><a id="h206" class="documentlinktemplate" title="where Clause" href="187.htm#o197" target="_self">where</a></code> clauses; and may optionally include <code class="monospace"><a id="h219" class="documentlinktemplate" title="order by Clause" href="187.htm#o190" target="_self">order by</a></code>, <code class="monospace"><a id="h220" class="documentlinktemplate" title="offset Clause" href="187.htm#o192" target="_self">offset</a></code> and <code class="monospace"><a id="h221" class="documentlinktemplate" title="limit Clause" href="187.htm#o191" target="_self">limit</a></code> clauses. With all clauses present, the general syntax is as follows:</p>
+<p class="bodytext">Issues queries to Mulgara<sup class="superscript">TM</sup> servers and displays the corresponding results. The command consists of a sequence of <code class="monospace"><a id="h217" class="documentlinktemplate" title="select Clause" href="187.htm#o188" target="_self">select</a></code>, <code class="monospace"><a id="h218" class="documentlinktemplate" title="from Clause" href="187.htm#o189" target="_self">from</a></code>, and <code class="monospace"><a id="h206" class="documentlinktemplate" title="where Clause" href="187.htm#o197" target="_self">where</a></code> clauses; and may optionally include <code class="monospace"><a id="h219" class="documentlinktemplate" title="order by Clause" href="187.htm#o190" target="_self">order by</a></code>, <code class="monospace"><a id="h220" class="documentlinktemplate" title="offset Clause" href="187.htm#o192" target="_self">offset</a></code> and <code class="monospace"><a id="h221" class="documentlinktemplate" title="limit Clause" href="187.htm#o191" target="_self">limit</a></code> clauses. With all clauses present, the general syntax is as follows:</p>
 <p class="commandtext">select columns from models where constraints order by variables limit count offset count;</p>
 <p class="bodytext">The purpose of the <code class="monospace">select</code> command is to find values for some set of variables that satisfy the specified constraints. All variable names start with a dollar sign (<code class="monospace">$)</code>, for example <code class="monospace">$x</code> or <code class="monospace">$title</code>.</p>
 <table cellpadding="0" cellspacing="0" border="0">
@@ -86,12 +86,14 @@
 <p class="commandtext">... where $document &lt;dc:title&gt; $title and $document &lt;dc:creator&gt; $author <br />      and ($document &lt;dc:subject&gt; 'botany' or $document &lt;dc:subject&gt; 'zoology') ...</p>
 <a name="o1530"></a><h4 class="heading4">in Specifier</h4>
 <p class="bodytext">Constraints may optionally contain an <code class="monospace">in</code> specifier to resolve the constraint against the statements in a specified model, rather than the one specified in the <code class="monospace"><a id="h1303" class="documentlinktemplate" title="from Clause" href="187.htm#o189" target="_self">from</a></code> clause.</p>
+<p class="bodytext">The <code class="monospace">in</code> specifier may be used to specify views as well as models.</p>
+
 <p class="bodytext">The following example constrains the result by titles in the <code class="monospace">#books</code> model rather than the one specified in the <code class="monospace">from</code> clause.</p>
 <p class="commandtext">... where $document &lt;dc:title&gt; $title in &lt;rmi://mysite.com/server1#books&gt; ...</p>
-<a name="o1531"></a><h4 class="heading4">Assigning a Value to a Variable (mulgara:is)</h4>
-<p class="bodytext">Constraints may also assign a value to a variable rather then querying for it. The special property <code class="monospace">http://mulgara.org/mulgara#is </code>(or the aliased form <code class="monospace">&lt;mulgara:is&gt;</code>) can be used with a variable as its subject and a non-variable value as its object. This assigns the non-variable value to the variable.</p>
+<a name="o1531"></a><h4 class="heading4">Assigning a Value to a Variable (tucana:is)</h4>
+<p class="bodytext">Constraints may also assign a value to a variable rather then querying for it. The special property <code class="monospace">http://tucana.org/tucana#is </code>(or the aliased form <code class="monospace">&lt;tucana:is&gt;</code>) can be used with a variable as its subject and a non-variable value as its object. This assigns the non-variable value to the variable.</p>
 <p class="bodytext">The following example results in every document authored by Mendel about genetics, or by Mendeleev about chemistry.</p>
-<p class="commandtext">... where $document &lt;dc:title&gt; $title and $document &lt;dc:creator&gt; $author <br />      and $document &lt;dc:subject&gt; $subject <br />      and (($author &lt;mulgara:is&gt; 'Mendel'    and $subject &lt;mulgara:is&gt; 'genetics' ) <br />      or ($author &lt;mulgara:is&gt; 'Mendeleev' and $subject &lt;mulgara:is&gt; 'chemistry')) ...</p>
+<p class="commandtext">... where $document &lt;dc:title&gt; $title and $document &lt;dc:creator&gt; $author <br />      and $document &lt;dc:subject&gt; $subject <br />      and (($author &lt;tucana:is&gt; 'Mendel'    and $subject &lt;tucana:is&gt; 'genetics' ) <br />      or ($author &lt;tucana:is&gt; 'Mendeleev' and $subject &lt;tucana:is&gt; 'chemistry')) ...</p>
 <a name="o1532"></a><h4 class="heading4">Traversing a Graph (walk Function)</h4>
 <p class="bodytext">Traversing a graph allows a query to return values, based on a predicate, by following up or down a hierarchy of statements. In a schema language such as RDFS, these hierarchies are expressed as a sub-class or sub-property predicate. Traversing a graph is performed with the <code class="monospace">walk</code> function within a <code class="monospace"><a id="h1321" class="documentlinktemplate" title="where Clause" href="187.htm#o197" target="_self">where</a></code> clause.</p>
 <p class="bodytext">The syntax of the <code class="monospace">walk</code> function is either:</p>
@@ -140,64 +142,79 @@
 <p class="bodytext">Which produces:</p>
 <p class="commandtext">[ (&lt;marsupials&gt;, &lt;rdfs:subClassOf&gt;, &lt;<code class="monospace">vertebrates</code>&gt;)<br />  (&lt;kangaroos&gt;, &lt;rdfs:subClassOf&gt;, &lt;<code class="monospace">vertebrates</code>&gt;)<br />  (&lt;red-kangaroos&gt;, &lt;rdfs:subClassOf&gt;, &lt;<code class="monospace">vertebrates</code>&gt;)<br />  (&lt;placental-mammals&gt;, &lt;rdfs:subClassOf&gt;, &lt;<code class="monospace">vertebrates</code>&gt;)<br />  (&lt;elephants&gt;, &lt;rdfs:subClassOf&gt;, &lt;<code class="monospace">vertebrates</code>&gt;) ]</p>
 <p class="bodytext">Likewise, you can also make the subject in the <code class="monospace">trans</code> constraint a constant and the object a variable.</p>
+
+<a name="oxxminusxx"></a><h4 class="heading4">Graph Difference (minus) Function</h4>
+<p class="bodytext">The <code class="monospace">minus</code> function allows
+you to find the statements which differ between two graphs.</p>
+
+<p class="bodytext">For example, to find the statements which are different
+between the model &lt;rmi://localhost/server1#input&gt; and
+&lt;rmi://localhost/server1#output&gt;, we could issue a query like this:</p>
+
+<p class="commandtext">
+select $subject $predicate $object
+from &lt;rmi://localhost/server1#output&gt;
+where
+  $subject $predicate $object in &lt;rmi://localhost/server1#output&gt;
+  minus
+  $subject $predicate $object in &lt;rmi://localhost/server1#input&gt; ;
+</p>
+
+<p class="bodytext">The use of the <code class="monospace">in</code> specifier
+is not strictly necessary for the model named in <code
+class="monospace">from</code> clause, but it makes the query a bit more
+readable by providing symmetry.</p>
+
+<p class="bodytext">To count the number of statements that differ between the
+two models, we could do something like the following.  Note variables do not
+carry over into a <code class="monospace">count</code> function&#8217;s
+namespace, so the outer query could be anything.</p>
+
+<p class="commandtext">
+select count (
+    select $subject $predicate $object
+    from &lt;rmi://localhost/server1#output&gt;
+    where
+      $subject $predicate $object in &lt;rmi://localhost/server1#output&gt;
+      minus
+      $subject $predicate $object in &lt;rmi://localhost/server1#input&gt;
+)
+from &lt;rmi://localhost/server1#&gt;
+where
+  $s $p $o ;
+</p>
+
+
 <a name="o2768"></a><h4 class="heading4">exclude Function</h4>
-<p class="bodytext">The <code class="monospace">exclude</code> function allows you to select all statements whose properties are the inverse of a given constraint. Normal constraints match against the graph with the constraints you provide. Constraints enclosed in an <code class="monospace">exclude</code> function return the values in the graph that are not the constraints provided. This allows you to build queries to ask questions such as: &quot;find me all the known plants stored, with leaves that are not green&quot; or &quot;find me all the American states stored that are not Alabama&quot;.</p>
-<p class="bodytext">Using the following statements as an example:</p>
+<p class="bodytext">The <code class="monospace">exclude</code> function allows you to select all statements which do not match a given constraint. Normal constraints match against the graph with the constraints you provide. Constraints enclosed in an <code class="monospace">exclude</code> function return the values in the graph that are not the constraints provided.</p>
+<p class="bodytext">This function is almost never useful.  Consider using the <a href="#oxxminusxx">minus</a> operator instead.</p>
+<p class="bodytext">Using the following statements as an example for "finding all plants with leaves that are not green":</p>
 <p class="commandtext">[ (&lt;maple&gt;, &lt;leaves&gt;, 'green')<br />  (&lt;redMaple&gt;, &lt;leaves&gt;, 'red')<br />  (&lt;oak&gt;, &lt;leaves&gt;, 'green')<br />  (&lt;cactus&gt;, &lt;prickles&gt;, 'yellow') ]</p>
-<p class="bodytext">You wish to find all plants that do not have leaves. The following query:</p>
-<p class="commandtext">select $s $p $o<br />...<br />where exclude($s &lt;leaves&gt; $o) <br />and ($s $p $o);</p>
+<p class="bodytext">With a small model it is possible to query for all plants that do not have leaves. The following query:</p>
+<p class="commandtext">select $s<br />from ...<br />where exclude($s &lt;leaves&gt; $o) ;</p>
 <p class="bodytext">Returns:</p>
-<p class="commandtext">[ (&lt;cactus&gt;, &lt;prickles&gt;, 'yellow') ]</p>
-<p class="bodytext">Unless your model is very small, the <code class="monospace">exclude</code> function by itself is rarely useful. For example, the following query:</p>
-<p class="commandtext">select $s $p $o<br />...<br />where exclude($s &lt;leaves&gt; 'green')<br />and $s $p $o;</p>
-<p class="bodytext">Returns:</p>
-<p class="commandtext">[ (&lt;cactus&gt;, &lt;prickles&gt;, 'yellow')<br />  (&lt;redMaple), &lt;leaves&gt;, 'red' ]</p>
-<p class="bodytext">As this returns all statements that do not have the predicate <code class="monospace">&lt;leaves&gt;</code> and the object value 'green', if a statement exists where <em class="emphasis">either</em> of these columns do not match, it is returned. If you want to find all the things that have leaves that are not green you need to perform the following query:</p>
-<p class="commandtext">select $s<br />...<br />where $s &lt;urn:leaves&gt; $o <br />and exclude($s $p 'green');</p>
+<p class="commandtext">[ ( &lt;cactus&gt; ) ]</p>
+<p class="bodytext">However, more statements in the data mean that the results will need to be constrained more carefully.  Unfortunately this may cause the <code class="monospace">exclude</code> operator to miss some required statements.  For instance, if the following statements were also included:</p>
+<p class="commandtext">[ ( &lt;maple&gt; &lt;rdf:type&gt; &lt;plant&gt; )<br/> ( &lt;redMaple&gt; &lt;rdf:type&gt; &lt;plant&gt; )<br/> ( &lt;oak&gt; &lt;rdf:type&gt; &lt;plant&gt; )<br/> ( &lt;cactus&gt; &lt;rdf:type&gt; &lt;plant&gt; ) ]</p>
+<p class="bodytext">The following query would appear appropriate:</p>
+<p class="commandtext">select $s<br />from ...<br />where $s &lt;rdf:type&gt; &lt;plant&gt; <br/>and exclude($s &lt;leaves&gt; $o);</p>
+<p class="bodytext">However, this returns:</p>
+<p class="commandtext">[( &lt;maple&gt; )<br/> ( &lt;redMaple&gt; )<br/> ( &lt;oak&gt; )<br/> ( &lt;cactus&gt; ) ]</p>
+
 <p class="bodytext">To understand what this query is doing, examine each constraint individually:</p>
-<ol class="listnumber"><li class="listnumber"><code class="monospace">$s &lt;urn:leaves&gt; $o</code> returns all statements with the predicate <code class="monospace">&lt;leaves&gt;</code>:<p class="listcontinuecommandtext">$s          $o<br />&lt;maple&gt;     'green'<br />&lt;redMaple&gt;  'red'<br />&lt;oak&gt;       'green'</p>
-</li><li class="listnumber"><code class="monospace">exclude($s $p 'green')</code> returns all statements that do not have the object value 'green':<p class="listcontinuecommandtext">$s          $p<br />&lt;redMaple&gt;  &lt;leaves&gt;<br />&lt;cactus&gt;    &lt;prickles&gt;</p>
-</li></ol><p class="bodytext">Combining these two results (using <code class="monospace">and</code>), only one statement satisfies all constraints and the query returns the variable (<code class="monospace">$s</code>) in the <code class="monospace"><a id="h217_2" class="documentlinktemplate" title="select Clause" href="187.htm#o188" target="_self">select</a></code> clause:</p>
-<p class="commandtext">[ (&lt;redMaple&gt;) ]</p>
-<p class="bodytext">Rarely do graphs contain just one easily defined set of statement. Extending the base set of statements with overlapping predicates for our example:</p>
-<p class="commandtext">[ (&lt;maple&gt;, &lt;type&gt;, &lt;plant&gt;)<br />  (&lt;redMaple&gt;, &lt;type&gt;, &lt;plant&gt;)<br />  (&lt;oak&gt;, &lt;type&gt;, &lt;plant&gt;)<br />  (&lt;cactus&gt;, &lt;type&gt;, &lt;plant&gt;)<br />  (&lt;maple&gt;, &lt;leaves&gt;, 'green')<br />  (&lt;redMaple&gt;, &lt;leaves&gt;, 'red')<br />  (&lt;oak&gt;, &lt;leaves&gt;, 'green')<br />  (&lt;cactus&gt;, &lt;prickles&gt;, 'yellow') <br />  (&lt;binderRefill&gt;, &lt;leaves&gt;, '50') ]</p>
-<p class="bodytext">Using the previous query:</p>
-<p class="commandtext">select $s<br />...<br />where $s &lt;urn:leaves&gt; $o <br />and exclude($s $p 'green');</p>
-<p class="bodytext">Returns:</p>
-<p class="commandtext">[ (&lt;maple&gt;)<br />  (&lt;redMaple&gt;)<br />  (&lt;oak&gt;)<br />  (&lt;binderRefill&gt;) ]</p>
-<p class="bodytext">Examining each constraint individually again:</p>
-<ol class="listnumber"><li class="listnumber"><code class="monospace">$s &lt;urn:leaves&gt; $o</code> returns all statements with the predicate <code class="monospace">&lt;leaves&gt;</code>:<p class="listcontinuecommandtext">$s             $o<br />&lt;maple&gt;        'green'<br />&lt;redMaple&gt;     'red'<br />&lt;oak&gt;          'green'<br />&lt;binderRefill&gt; '50'</p>
-</li><li class="listnumber"><code class="monospace">exclude($s $p 'green')</code> returns all statements that do not have the object value 'green':<p class="listcontinuecommandtext">$s              $p<br />&lt;maple&gt;         &lt;type&gt;<br />&lt;redMaple&gt;      &lt;type&gt;<br />&lt;oak&gt;           &lt;type&gt;<br />&lt;cactus&gt;        &lt;type&gt;<br />&lt;redMaple&gt;      &lt;leaves&gt;<br />&lt;cactus&gt;        &lt;prickles&gt;<br />&lt;binderRefill&gt;  &lt;leaves&gt;</p>
-</li></ol><p class="bodytext">Combining the <code class="monospace">$s</code> column from each result of the constraints, leads to the result.</p>
-<p class="bodytext">You usually need to restrict the <code class="monospace">exclude</code> constraint. In the previous examples, you only want to query things that are plants and not the entire graph. It is also preferable that the results from these constraints exist as real statements in a graph. To restrict the constraints so they only return things in the graph, the variables must be bound to the relevant positions.</p>
-<p class="bodytext">For example, the following query:</p>
-<p class="commandtext"><code class="monospace">select $s $p $o<br />...<br />where $s &lt;urn:leaves&gt; $o <br />and exclude($s $p 'green') <br />and $s $p $o;</code></p>
-<p class="bodytext">Returns:</p>
-<p class="commandtext"><code class="monospace">[ (&lt;redMaple&gt;, &lt;leaves&gt;, 'red')<br />  (&lt;binderRefill&gt;, &lt;leaves&gt;, '50') ]</code></p>
-<p class="bodytext">Note that the query still has not restricted the type of the object. To only query plants, the following query:</p>
-<p class="commandtext"><code class="monospace">select $s $p $o<br />...<br />where $s &lt;urn:leaves&gt; $o <br />and exclude($s $p 'green') <br />and $s $p $o<br />and $s &lt;type&gt; &lt;plant&gt; ;</code></p>
-<p class="bodytext">Returns:</p>
-<p class="commandtext"><code class="monospace">[ (&lt;redMaple&gt;, &lt;leaves&gt;, 'red') ]</code></p>
-<a name="o2769"></a><h5 class="heading5">Standard Queries</h5>
-<p class="bodytext">The variable names used in the <code class="monospace">exclude</code> function are not bound by other constraints, including the <code class="monospace"><code class="monospace"><a id="h2772" class="documentlinktemplate" title="Assigning a Value to a Variable (mulgara:is)" href="187.htm#o1531" target="_self">&lt;mulgara:is&gt;</a></code></code> operation. All other operations match statements in the graph. So it is not the same thing as replacing positively matching values from the graph and assigning these values to the <code class="monospace">exclude</code> function. The variable names used in the <code class="monospace">exclude</code> function and other operations are only used to join the column values from the results of each constraint.</p>
-<p class="bodytext">For example, the query:</p>
-<p class="commandtext"><code class="monospace">select $s $p $o<br />...<br />where exclude($s $p 'green')<br />and $p &lt;mulgara:is&gt; &lt;leaves&gt;<br />and $s $p $o;</code></p>
-<p class="bodytext">Results in all the statements that do not have the object value 'green', combined with all the statements with the predicate <code class="monospace">&lt;leaves&gt;</code>:</p>
-<p class="commandtext"><code class="monospace">[ (&lt;redMaple&gt;, &lt;leaves&gt;, 'red')<br />  (&lt;binderRefill&gt;, &lt;leaves&gt;, '50') ]</code></p>
-<p class="bodytext">Note that this is not the same as:</p>
-<p class="commandtext"><code class="monospace">select $s $p $o<br />...<br />where exclude ($s &lt;urn:leaves&gt; 'green')<br />and $p &lt;mulgara:is&gt; &lt;leaves&gt;<br />and $s $p $o;</code></p>
-<p class="bodytext">Which returns:</p>
-<p class="commandtext"><code class="monospace">[ (&lt;maple&gt;, &lt;leaves&gt;, 'green')<br />  (&lt;oak&gt;, &lt;leaves&gt;, 'green') ]</code></p>
-<a name="o2770"></a><h5 class="heading5">exclude($s $p $o)</h5>
-<p class="bodytext"><code class="monospace">exclude</code> functions that only contain variables usually return no result. If joined to other constraints with <code class="monospace">and</code>, it will return no result. As stated above, this cannot be changed by using <code class="monospace"><a id="h2772_2" class="documentlinktemplate" title="Assigning a Value to a Variable (mulgara:is)" href="187.htm#o1531" target="_self">&lt;mulgara:is&gt;</a></code> or other constraints. The only exception to this is when the <code class="monospace">exclude</code> function is used in a subquery or aggregate function. See the next section on subqueries for more details.</p>
-<p class="bodytext">For example, the following query returns no result.</p>
-<p class="commandtext"><code class="monospace">select $s $p $o<br />...<br />where exclude ($s $p $o)<br />and $o &lt;mulgara:is&gt; 'green'<br />and $s $p $o;</code></p>
-<a name="o2771"></a><h5 class="heading5">Subqueries</h5>
-<p class="bodytext">Subqueries allow the results from one query to be used in another. That is, the values of the outer queries bind to the variables with the same name in the inner query. So a constraint such as <code class="monospace">exclude($s $p $o)</code>, which normally returns no result, could return results if used in a <code class="monospace"><code class="monospace"><a id="h211" class="documentlinktemplate" title="subquery Function" href="187.htm#o193" target="_self">subquery</a></code></code> or <code class="monospace"><a id="h733" class="documentlinktemplate" title="count Function" href="187.htm#o194" target="_self">count</a></code> function when any of the variables <code class="monospace">$s</code>, <code class="monospace">$p</code> or <code class="monospace">$o</code> are bound by the outer query.</p>
-<p class="bodytext">For example, the following query binds the <code class="monospace">$s</code> and <code class="monospace">$o</code> values of the internal query:</p>
-<p class="commandtext"><code class="monospace">select $s $o subquery(<br />  select $s2 $p2 $o2 <br />  ...<br />  where exclude($s $p2 $o) <br />  and $s $p2 $o2 <br />  and $s2 $p2 $o)<br />...<br />where $s &lt;urn:type&gt; $o ;</code></p>
-<p class="bodytext">The first result passes values to the internal <code class="monospace">subquery</code> where <code class="monospace">$s</code> is <code class="monospace">&lt;maple&gt;</code> and <code class="monospace">$o</code> is <code class="monospace">&lt;plant&gt;</code>. This causes the inner query to look like:</p>
-<p class="commandtext"><code class="monospace">select $s2 $p2 $o2 <br />...<br />where exclude(&lt;maple&gt; $p2 &lt;plant&gt;)<br />and &lt;maple&gt; $p2 $o2 <br />and $s2 $p2 &lt;plant&gt;</code></p>
+<ol class="listnumber">
+  <li class="listnumber"><code class="monospace">$s &lt;rdf:type&gt; &lt;plant&gt;</code> returns all statements referring to a type of plant:<p class="listcontinuecommandtext">$s          $p <br/>&lt;maple&gt;     &lt;plant&gt; <br/>&lt;redMaple&gt;  &lt;plant&gt; <br/>&lt;oak&gt;       &lt;plant&gt; <br/>&lt;cactus&gt;    &lt;plant&gt;</p>
+  </li>
+  <li class="listnumber"><code class="monospace">$s &lt;urn:leaves&gt; $o</code> (before the <code class="monospace">exclude</code> operator is applied) returns all statements which match the predicate <code class="monospace">&lt;leaves&gt;</code>:<p class="listcontinuecommandtext">$s          $o<br />&lt;maple&gt;     'green'<br />&lt;redMaple&gt;  'red'<br />&lt;oak&gt;       'green'</p>
+  </li>
+  <li class="listnumber"><code class="monospace">exclude($s &lt;urn:leaves&gt; $o)</code> returns all statements which do not match the predicate <code class="monospace">&lt;leaves&gt;</code>:<p class="listcontinuecommandtext">$s          $o <br/>&lt;maple&gt;     &lt;plant&gt; <br/>&lt;redMaple&gt;  &lt;plant&gt; <br/>&lt;oak&gt;       &lt;plant&gt; <br/>&lt;cactus&gt;    &lt;plant&gt; <br/>&lt;cactus&gt;    'yellow' </p>
+  </li>
+</ol>
+<p class="bodytext">Combining the two results (using <code class="monospace">and</code>), leads to all the subjects satisfng both constraints.  This is incorrect.  The required solution can be found if the <code class="monospace">minus</code> operator is used instead:</p>
+<p class="commandtext">select $s<br />from ...<br />where $s &lt;rdf:type&gt; &lt;plant&gt; <br/>minus $s &lt;leaves&gt; $o ;</p>
+<p class="bodytext">In this case the <code class="monospace">minus</code> operator will remove all statements matching the specified constraint, rather than joining to all statements which do not match the specified constraint (which is the operation of <code class="monospace">and exclude</code>). </p>
+
+
 <a name="o190"></a><h3 class="heading3">order by Clause</h3>
 <p class="bodytext">Optionally sorts the results of a <code class="monospace"><a id="h207_2" class="documentlinktemplate" title="select" href="187.htm" target="_self">select</a></code> command according to the variables specified.</p>
 <p class="bodytext">The following example sorts the results numerically by rating (assuming ratings can be parsed as numbers), then alphabetically by author for documents of equal rating.</p>
@@ -217,7 +234,7 @@
 <p class="bodytext">In the following example the value of <code class="monospace">$vcard</code> is bound to the inner query. The outer result set contains nested result sets for each subquery.</p>
 <p class="commandtext">select $vcard $fn <br />  subquery( select $title <br />    from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#TITLE&gt; $title<br />    order by $title )<br />  from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#FN&gt; $fn <br />    order by $fn;</p>
 <p class="bodytext">The above example produces the following XML output from a SOAP call:</p>
-<p class="commandtext">&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;answer xmlns=&quot;http://mulgara.org/tql#&quot;&gt;<br />  &lt;query&gt;<br />    &lt;variables&gt;<br />      &lt;vcard/&gt;<br />      &lt;fn/&gt;<br />      &lt;k0/&gt;<br />    &lt;/variables&gt;<br />    &lt;solution&gt;<br />      &lt;vcard resource=&quot;http://qqq.com/staff/superman&quot;/&gt;<br />      &lt;fn&gt;Superman&lt;/fn&gt;<br />      &lt;k0&gt;<br />        &lt;variables&gt;<br />          &lt;title/&gt;<br />        &lt;/variables&gt;<br />      &lt;/k0&gt;<br />    &lt;/solution&gt;<br />    &lt;solution&gt;<br />      &lt;vcard resource=&quot;http://qqq.com/staff/spiderman&quot;/&gt;<br />      &lt;fn&gt;Peter Parker&lt;/fn&gt;<br />      &lt;k0&gt;<br />        &lt;variables&gt;<br />          &lt;title/&gt;<br />        &lt;/variables&gt;<br />        &lt;solution&gt;<br />          &lt;title&gt;Super Hero&lt;/title&gt;<br />        &lt;/solution&gt;<br />        &lt;solution&gt;<br />          &lt;title&gt;PO2&lt;/title&gt;<br />        &lt;/solution&gt;<br />      &lt;/k0&gt;<br />    &lt;/solution&gt;<br />    &lt;solution&gt;<br />      &lt;vcard resource=&quot;http://qqq.com/staff/corky&quot;/&gt;<br />      &lt;fn&gt;Corky Crystal&lt;/fn&gt;<br />      &lt;k0&gt;<br />        &lt;variables&gt;<br />          &lt;title/&gt;<br />        &lt;/variables&gt;<br />        &lt;solution&gt;<br />          &lt;title&gt;Computer Officer Class 3&lt;/title&gt;<br />        &lt;/solution&gt;<br />      &lt;/k0&gt;<br />    &lt;/solution&gt;<br />  &lt;/query&gt;<br />&lt;/answer&gt;</p>
+<p class="commandtext">&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;answer xmlns=&quot;http://tucanatech.com/tql#&quot;&gt;<br />  &lt;query&gt;<br />    &lt;variables&gt;<br />      &lt;vcard/&gt;<br />      &lt;fn/&gt;<br />      &lt;k0/&gt;<br />    &lt;/variables&gt;<br />    &lt;solution&gt;<br />      &lt;vcard resource=&quot;http://qqq.com/staff/superman&quot;/&gt;<br />      &lt;fn&gt;Superman&lt;/fn&gt;<br />      &lt;k0&gt;<br />        &lt;variables&gt;<br />          &lt;title/&gt;<br />        &lt;/variables&gt;<br />      &lt;/k0&gt;<br />    &lt;/solution&gt;<br />    &lt;solution&gt;<br />      &lt;vcard resource=&quot;http://qqq.com/staff/spiderman&quot;/&gt;<br />      &lt;fn&gt;Peter Parker&lt;/fn&gt;<br />      &lt;k0&gt;<br />        &lt;variables&gt;<br />          &lt;title/&gt;<br />        &lt;/variables&gt;<br />        &lt;solution&gt;<br />          &lt;title&gt;Super Hero&lt;/title&gt;<br />        &lt;/solution&gt;<br />        &lt;solution&gt;<br />          &lt;title&gt;PO2&lt;/title&gt;<br />        &lt;/solution&gt;<br />      &lt;/k0&gt;<br />    &lt;/solution&gt;<br />    &lt;solution&gt;<br />      &lt;vcard resource=&quot;http://qqq.com/staff/corky&quot;/&gt;<br />      &lt;fn&gt;Corky Crystal&lt;/fn&gt;<br />      &lt;k0&gt;<br />        &lt;variables&gt;<br />          &lt;title/&gt;<br />        &lt;/variables&gt;<br />        &lt;solution&gt;<br />          &lt;title&gt;Computer Officer Class 3&lt;/title&gt;<br />        &lt;/solution&gt;<br />      &lt;/k0&gt;<br />    &lt;/solution&gt;<br />  &lt;/query&gt;<br />&lt;/answer&gt;</p>
 <a name="o194"></a><h3 class="heading3">count Function</h3>
 <p class="bodytext">Similar to <code class="monospace"><a id="h211_2" class="documentlinktemplate" title="subquery Function" href="187.htm#o193" target="_self">subquery</a></code> except that it only returns a dummy variable with value of the total row count of the inner query. See the <code class="monospace"><a id="h1320" class="documentlinktemplate" title="select Clause" href="187.htm#o188" target="_self">select</a></code><a id="h1320_2" class="documentlinktemplate" title="select Clause" href="187.htm#o188" target="_self"> clause section</a> for a description of dummy variables. For example:</p>
 <p class="commandtext">select $vcard $fn <br />  count( select $title from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#TITLE&gt; $title )<br />  from &lt;rmi://mysite.com/server1#vcard&gt; <br />  where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#FN&gt; $fn ;</p>
@@ -234,25 +251,25 @@
 </td>
 </tr>
 <tr align="left" valign="top">
-<td width="294"><p class="tablebodytext"><code class="monospace">http://mulgara.org/mulgara#occurs</code></p>
+<td width="294"><p class="tablebodytext"><code class="monospace">http://tucana.org/tucana#occurs</code></p>
 </td>
 <td width="156"><p class="tablebodytext">=</p>
 </td>
 </tr>
 <tr align="left" valign="top">
-<td width="294"><p class="tablebodytext"><code class="monospace">http://mulgara.org/mulgara#occursMoreThan</code></p>
+<td width="294"><p class="tablebodytext"><code class="monospace">http://tucana.org/tucana#occursMoreThan</code></p>
 </td>
 <td width="156"><p class="tablebodytext">&gt;</p>
 </td>
 </tr>
 <tr align="left" valign="top">
-<td width="294"><p class="tablebodytext"><code class="monospace">http://mulgara.org/mulgara#occursLessThan</code></p>
+<td width="294"><p class="tablebodytext"><code class="monospace">http://tucana.org/tucana#occursLessThan</code></p>
 </td>
 <td width="156"><p class="tablebodytext">&lt;</p>
 </td>
 </tr>
 <tr align="left" valign="top">
-<td width="294"><p class="tablebodytext"><code class="monospace">http://mulgara.org/mulgara#notOccurs</code></p>
+<td width="294"><p class="tablebodytext"><code class="monospace">http://tucana.org/tucana#notOccurs</code></p>
 </td>
 <td width="156"><p class="tablebodytext">?</p>
 </td>
@@ -260,33 +277,26 @@
 
 </table>
 <p class="bodytext">Expanding on the example shown in the <code class="monospace"><a id="h1323_2" class="documentlinktemplate" title="subquery Function" href="187.htm#o193" target="_self">subquery</a></code> and <code class="monospace"><a id="h733_2" class="documentlinktemplate" title="count Function" href="187.htm#o194" target="_self">count</a></code> sections, the following query restricts the result to those with a count of 1:</p>
-<p class="commandtext">select $vcard $fn <br />  count( select $title from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#TITLE&gt; $title )<br />  from &lt;rmi://mysite.com/server1#vcard&gt; <br />  where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#FN&gt; $fn <br />  having $k0 &lt;http://mulgara.org/mulgara#occurs&gt;<br />    '1.0'^^&lt;http://www.w3.org/2001/XMLSchema#double&gt; ;</p>
+<p class="commandtext">select $vcard $fn <br />  count( select $title from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#TITLE&gt; $title )<br />  from &lt;rmi://mysite.com/server1#vcard&gt; <br />  where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#FN&gt; $fn <br />  having $k0 &lt;http://tucana.org/tucana#occurs&gt;<br />    '1.0'^^&lt;http://www.w3.org/2001/XMLSchema#double&gt; ;</p>
 <p class="bodytext">The above example returns:</p>
 <p class="commandtext">vcard=http://qqq.com/staff/corky    fn=&quot;Corky Crystal&quot;    k0=&quot;1&quot;</p>
 <p class="bodytext">Similarly, to restrict the result to those with a count greater than 0 would be: </p>
-<p class="commandtext">select $vcard $fn <br />  count( select $title from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#TITLE&gt; $title )<br />  from &lt;rmi://mysite.com/server1#vcard&gt; <br />  where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#FN&gt; $fn <br />  having $k0 &lt;http://mulgara.org/mulgara#occursMoreThan&gt;<br />    '0.0'^^&lt;http://www.w3.org/2001/XMLSchema#double&gt; ;</p>
+<p class="commandtext">select $vcard $fn <br />  count( select $title from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#TITLE&gt; $title )<br />  from &lt;rmi://mysite.com/server1#vcard&gt; <br />  where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#FN&gt; $fn <br />  having $k0 &lt;http://tucana.org/tucana#occursMoreThan&gt;<br />    '0.0'^^&lt;http://www.w3.org/2001/XMLSchema#double&gt; ;</p>
 <p class="bodytext">The above example returns:</p>
 <p class="commandtext">vcard=http://qqq.com/staff/corky        fn=&quot;Corky Crystal&quot;    k0=&quot;1&quot;<br />vcard=http://qqq.com/staff/spiderman    fn=&quot;Peter Parker&quot;     k0=&quot;2&quot;</p>
 <p class="bodytext">The form of the constraint for the <code class="monospace">having</code> clause must be:</p>
 <p class="commandtext">$kx predicate value^^&lt;http://www.w3.org/2001/XMLSchema#double&gt;</p>
 <p class="bodytext">Where p<code class="monospace">redicate</code> is one of the predicates from the above table.</p>
 <p class="bodytext">Note that compound constraints for the <code class="monospace">having</code> clause are not allowed. For example, the following query is <em class="emphasis">not</em> legal:</p>
-<p class="commandtext">select $vcard $fn <br />  count( select $title from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#TITLE&gt; $title )<br />  from &lt;rmi://mysite.com/server1#vcard&gt; <br />  where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#FN&gt; $fn <br />  having $k0 &lt;http://mulgara.org/mulgara#occurs&gt;<br />    '0.0'^^&lt;http://www.w3.org/2001/XMLSchema#double&gt; <br />  or $k0 &lt;http://mulgara.org/mulgara#occurs&gt; <br />    '2.0'^^&lt;http://www.w3.org/2001/XMLSchema#double&gt; ;</p>
+<p class="commandtext">select $vcard $fn <br />  count( select $title from &lt;rmi://mysite.com/server1#vcard&gt; <br />    where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#TITLE&gt; $title )<br />  from &lt;rmi://mysite.com/server1#vcard&gt; <br />  where $vcard &lt;http://www.w3.org/2001/vcard-rdf/3.0#FN&gt; $fn <br />  having $k0 &lt;http://tucana.org/tucana#occurs&gt;<br />    '0.0'^^&lt;http://www.w3.org/2001/XMLSchema#double&gt; <br />  or $k0 &lt;http://tucana.org/tucana#occurs&gt; <br />    '2.0'^^&lt;http://www.w3.org/2001/XMLSchema#double&gt; ;</p>
 
-			
-    </td>
-		<td width=20>
-		</td>
-		<td align="left">
-		  <a href="http://www.opensource.org/docs/definition.php" title="Open Source Initiative" target="_blank"><img style="border:0;width:110px;height:95;" src="http://www.opensource.org/trademarks/opensource/web/opensource-110x95.png" alt="Open Source logo" /></a>
 
-
 </td>
 </tr>
 <tr valign="bottom">
 <td>
 <br>
-<p class="toc">&copy; 2001-2004 Tucana Technologies, Inc. Some rights reserved.</p>    <p class="toc">&copy; 2006 The Mulgara Project. Some rights reserved.<br>Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A copy of the license is included in the section entitled &quot;<a href="fdl.txt">GNU Free Documentation License</a>&quot;.</p>
+<p class="toc">&copy; 2001-2005 Northrop Grumman Corporation. Some rights reserved.</p>
 </td>
 </tr>
 </table>
@@ -294,3 +304,4 @@
 </html>
 
 
+




More information about the Mulgara-svn mailing list