val titles_concat : [ Char* ] = "Semantic subtypingThe Relevance of Semantic Sub\
Ok.
:typingCDuce: a white-paper"
]]>
</sample>
<p> All papers in the bibliography bib </p>
<sample><![CDATA[
let papers = [bib]/<paper>_
]]>
</sample>
<p> Yielding: </p>
<sample><![CDATA[
val papers : [ <paper>[ Author+ Title Conference File ]* ] = [ <paper>[
val papers : [ <paper>[ Author+ Title Conference File ]* ] = [ <paper>[
<author>[ 'Alain Frisch' ]
<author>[ 'Alain Frisch' ]
<author>[ 'Giuseppe Castagna' ]
<author>[ 'Giuseppe Castagna' ]
...
@@ -208,11 +178,35 @@ val papers : [ <paper>[ Author+ Title Conference File ]* ] = [ <paper>[
...
@@ -208,11 +178,35 @@ val papers : [ <paper>[ Author+ Title Conference File ]* ] = [ <paper>[
<file>[ 'planx.ps.gz' ]
<file>[ 'planx.ps.gz' ]
]
]
]
]
Ok.
]]>
</sample>
<p><b> The same queries with the <code>select_from_where</code> construction </b></p>
<p> All the titles </p>
<sample><![CDATA[
let tquery = select y
from x in [bib]/<paper>_ ,
y in [x]/<title>_
]]>
</sample>
<p> This query is programmed in a XQuery-like style largely relying on the projections. Note that <code>x</code> and <code>y</code> are CDuce's patterns. The result is:</p>
<p><b> Selections </b> select all titles whose at least one author is "Alain Frisch" or "Veronique Benzaken"</p>
<b> A pure pattern example </b>
<sample><![CDATA[
</p>
let sel = select y
from x in [bib]/<paper>_ ,
y in [x]/<title>_,
z in [x]/<author>_
where z = <author>"Alain Frisch" or z = <author>"Veronique Benzaken"
]]>
</sample>
<p> Which yields: </p>
<sample><![CDATA[
<sample><![CDATA[
<books-with-prices>
val sel : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ]
select <book-with-price>[t1
<title>[ 'Semantic subtyping' ]
<price-amazon>p2
<title>[ 'The Relevance of Semantic Subtyping' ]
<price-bn>p1 ]
<title>[ 'CDuce: a white-paper' ]
from <bib>[b::Book*] in [biblio],
<title>[ 'CDuce: a white-paper' ]
<bookyear=y\&(1991--*)>[t1&Title _* <price>p1] in b,
]
<reviews>[e::Entry*] in [amazon],
<entry>[t2&Title <price>p2 ;_] in e
Ok.
where t1=t2]]>
]]>
</sample>
</sample>
<p>Note that the corresponding semantics, as in SQL, is a multiset one
thus duplicates are not eliminated. To discard them, one has to use the <code>distinct_values</code> operator.
</p>
<p>
<b> A pure pattern example </b>
</p>
<sample><![CDATA[
let sel = select t
from <_>[(x::<paper>_ | _ )*] in [bib],
(<_>[(a::<author>_ | _)*] &<_>[(t::<title>_ | _)*]) in x,
(<author>"Alain Frisch" | <author>"Veronique Benzaken") in a
]]>
</sample>
<p>
This query computes exactly the same result:
</p>
<sample><![CDATA[
val sel : [ [ <title>[ Char* ] ]* ] = [ [ <title>[ 'Semantic subtyping' ] ]
[ <title>[ 'Semantic subtyping' ] ]
[ <title>[ 'The Relevance of Semantic Subtyping' ] ]
[ <title>[ 'CDuce: a white-paper' ] ]
[ <title>[ 'CDuce: a white-paper' ] ]
]
Ok.
]]>
</sample>
<p>
This pure pattern form of the same query yields (in general) better performance than the same one written in an XQuery-like programming style. However, the query optimiser automatically translates the latter into a pure pattern one