Commit d6d02768 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-07-04 20:02:05 by vbenzake] Empty log message

Original author: vbenzake
Date: 2004-07-04 20:02:05+00:00
parent 214cb809
...@@ -50,26 +50,21 @@ transform %%e1%% with %%p1%% --> ...@@ -50,26 +50,21 @@ transform %%e1%% with %%p1%% -->
</p> </p>
<p> <p>
They are syntactic sugar for : They are syntactic sugar for :</p>
<code> <![CDATA[flatten(select x from <_>[(x::t | _ )] <sample> <![CDATA[flatten(select x from <_>[(x::t | _ )*] in e)]]> </sample>
in e)]]> </code> and <p> and </p>
<code><![CDATA[ <sample><![CDATA[
select x from <_ a=x>_ in e select x from <_ a=x>_ in e]]>
]]> </sample>
</code>
</p>
</box>
<box title="Example" link="exsel">
</box>
<box title="Examples" link="exsel">
<p> <p>
<b> A first classical example </b> <b> The types </b>
</p> </p>
<p> Let us consider the following types representing a Bibliography </p>
<sample><![CDATA[ <sample><![CDATA[
type Biblio = <bibliography>[Heading Paper*] type Biblio = <bibliography>[Heading Paper*]
type Heading = <heading>[ PCDATA ] type Heading = <heading>[ PCDATA ]
...@@ -78,7 +73,10 @@ type Author = <author>[ PCDATA ] ...@@ -78,7 +73,10 @@ type Author = <author>[ PCDATA ]
type Title = <title>[ PCDATA ] type Title = <title>[ PCDATA ]
type Conference = <conference>[ PCDATA ] type Conference = <conference>[ PCDATA ]
type File = <file>[ PCDATA ] type File = <file>[ PCDATA ]
]]>
</sample>
<p> and some values </p>
<sample><![CDATA[
let bib : Biblio = let bib : Biblio =
<bibliography>[ <bibliography>[
<heading>"Alain Frisch's bibliography" <heading>"Alain Frisch's bibliography"
...@@ -108,67 +106,31 @@ let bib : Biblio = ...@@ -108,67 +106,31 @@ let bib : Biblio =
<file>"planx.ps.gz" <file>"planx.ps.gz"
] ]
] ]
]]>
</sample>
<p> <b>Projections</b> </p>
<p> All titles in the bibliography bib </p>
<sample><![CDATA[
let titles = [bib]/<paper>_/<title>_ let titles = [bib]/<paper>_/<title>_
let authors = [bib]/<paper>_/<author>_
let titles_concat = [bib]/<paper>_/<title>_/Char
let papers = [bib]/<paper>_
let tquery = select y from x in [bib]/<paper>_ ,
y in [x]/<title>_
let tryit = flatten(select [x] from x in [bib]/<paper>_/<title>_)
select y from x in [bib]/<paper>_ ,
y in [x]/<title>_,
z in [x]/<author>_
where z = <author>"Yoko Motohama"
select y from x in [bib]/<paper>_ ,
y in [x]/<title>_,
<author>"Yoko Motohama"in [x]/<author>_
]]> ]]>
</sample> </sample>
<p> Which yields to:</p>
<p> Which gives the following result </p>
<sample><![CDATA[ <sample><![CDATA[
val bib : Biblio = <bibliography>[
<heading>[ 'Alain Frisch\'s bibliography' ]
<paper>[
<author>[ 'Alain Frisch' ]
<author>[ 'Giuseppe Castagna' ]
<author>[ 'Veronique Benzaken' ]
<title>[ 'Semantic subtyping' ]
<conference>[ 'LICS 02' ]
<file>[ 'semsub.ps.gz' ]
]
<paper>[
<author>[ 'Mariangiola Dezani-Ciancaglini' ]
<author>[ 'Alain Frisch' ]
<author>[ 'Elio Giovannetti' ]
<author>[ 'Yoko Motohama' ]
<title>[ 'The Relevance of Semantic Subtyping' ]
<conference>[ 'ITRS\'02' ]
<file>[ 'itrs02.ps.gz' ]
]
<paper>[
<author>[ 'Veronique Benzaken' ]
<author>[ 'Giuseppe Castagna' ]
<author>[ 'Alain Frisch' ]
<title>[ 'CDuce: a white-paper' ]
<conference>[ 'PLANX-02' ]
<file>[ 'planx.ps.gz' ]
]
]
val titles : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ] val titles : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ]
<title>[ 'The Relevance of Semantic Subtyping' ] <title>[ 'The Relevance of Semantic Subtyping' ]
<title>[ 'CDuce: a white-paper' ] <title>[ 'CDuce: a white-paper' ]
] ]
Ok.
]]>
</sample>
<p> All authors in the bibliography bib </p>
<sample><![CDATA[
let authors = [bib]/<paper>_/<author>_
]]>
</sample>
<p> Yielding the result: </p>
<sample><![CDATA[
val authors : [ <author>[ Char* ]* ] = [ <author>[ 'Alain Frisch' ] val authors : [ <author>[ Char* ]* ] = [ <author>[ 'Alain Frisch' ]
<author>[ 'Giuseppe Castagna' ] <author>[ 'Giuseppe Castagna' ]
<author>[ 'Veronique Benzaken' ] <author>[ 'Veronique Benzaken' ]
...@@ -180,8 +142,16 @@ val authors : [ <author>[ Char* ]* ] = [ <author>[ 'Alain Frisch' ] ...@@ -180,8 +142,16 @@ val authors : [ <author>[ Char* ]* ] = [ <author>[ 'Alain Frisch' ]
<author>[ 'Giuseppe Castagna' ] <author>[ 'Giuseppe Castagna' ]
<author>[ 'Alain Frisch' ] <author>[ 'Alain Frisch' ]
] ]
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>
<sample> <![CDATA[
val tquery : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ] val tquery : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ]
<title>[ 'The Relevance of Semantic Subtyping' ] <title>[ 'The Relevance of Semantic Subtyping' ]
<title>[ 'CDuce: a white-paper' ] <title>[ 'CDuce: a white-paper' ]
] ]
val tryit : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ] ]]>
</sample>
<p> Now let's program the same query with the translation given previously thus eliminating the <code>y</code> variable </p>
<sample><![CDATA[
let withouty = flatten(select [x] from x in [bib]/<paper>_/<title>_)
]]>
</sample>
<p> Yielding: </p>
<sample><![CDATA[
val withouty : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ]
<title>[ 'The Relevance of Semantic Subtyping' ] <title>[ 'The Relevance of Semantic Subtyping' ]
<title>[ 'CDuce: a white-paper' ] <title>[ 'CDuce: a white-paper' ]
] ]
...@@ -222,27 +216,67 @@ val tryit : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ] ...@@ -222,27 +216,67 @@ val tryit : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ]
Ok. Ok.
]]> ]]>
</sample> </sample>
<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' ]
<book year=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
</p>
<p> <p>
<b>Formatted table generation</b> <b>Formatted table generation</b>
</p> </p>
...@@ -266,8 +300,8 @@ let bg ((Int , Int) -> String) ...@@ -266,8 +300,8 @@ let bg ((Int , Int) -> String)
Result: Result:
</p> </p>
<table border="1"><tr><td align="right" style="background:white">1</td><td align="right" style="background:lightblue">2</td><td align="right" style="background:white">3</td><td align="right" style="background:lightblue">4</td><td align="right" style="background:white">5</td><td align="right" style="background:lightblue">6</td><td align="right" style="background:white">7</td><td align="right" style="background:lightblue">8</td><td align="right" style="background:white">9</td><td align="right" style="background:lightblue">10</td></tr><tr><td align="right" style="background:yellow">2</td><td align="right" style="background:lightgreen">4</td><td align="right" style="background:yellow">6</td><td align="right" style="background:lightgreen">8</td><td align="right" style="background:yellow">10</td><td align="right" style="background:lightgreen">12</td><td align="right" style="background:yellow">14</td><td align="right" style="background:lightgreen">16</td><td align="right" style="background:yellow">18</td><td align="right" style="background:lightgreen">20</td></tr><tr><td align="right" style="background:white">3</td><td align="right" style="background:lightblue">6</td><td align="right" style="background:white">9</td><td align="right" style="background:lightblue">12</td><td align="right" style="background:white">15</td><td align="right" style="background:lightblue">18</td><td align="right" style="background:white">21</td><td align="right" style="background:lightblue">24</td><td align="right" style="background:white">27</td><td align="right" style="background:lightblue">30</td></tr><tr><td align="right" style="background:yellow">4</td><td align="right" style="background:lightgreen">8</td><td align="right" style="background:yellow">12</td><td align="right" style="background:lightgreen">16</td><td align="right" style="background:yellow">20</td><td align="right" style="background:lightgreen">24</td><td align="right" style="background:yellow">28</td><td align="right" style="background:lightgreen">32</td><td align="right" style="background:yellow">36</td><td align="right" style="background:lightgreen">40</td></tr><tr><td align="right" style="background:white">5</td><td align="right" style="background:lightblue">10</td><td align="right" style="background:white">15</td><td align="right" style="background:lightblue">20</td><td align="right" style="background:white">25</td><td align="right" style="background:lightblue">30</td><td align="right" style="background:white">35</td><td align="right" style="background:lightblue">40</td><td align="right" style="background:white">45</td><td align="right" style="background:lightblue">50</td></tr><tr><td align="right" style="background:yellow">6</td><td align="right" style="background:lightgreen">12</td><td align="right" style="background:yellow">18</td><td align="right" style="background:lightgreen">24</td><td align="right" style="background:yellow">30</td><td align="right" style="background:lightgreen">36</td><td align="right" style="background:yellow">42</td><td align="right" style="background:lightgreen">48</td><td align="right" style="background:yellow">54</td><td align="right" style="background:lightgreen">60</td></tr><tr><td align="right" style="background:white">7</td><td align="right" style="background:lightblue">14</td><td align="right" style="background:white">21</td><td align="right" style="background:lightblue">28</td><td align="right" style="background:white">35</td><td align="right" style="background:lightblue">42</td><td align="right" style="background:white">49</td><td align="right" style="background:lightblue">56</td><td align="right" style="background:white">63</td><td align="right" style="background:lightblue">70</td></tr><tr><td align="right" style="background:yellow">8</td><td align="right" style="background:lightgreen">16</td><td align="right" style="background:yellow">24</td><td align="right" style="background:lightgreen">32</td><td align="right" style="background:yellow">40</td><td align="right" style="background:lightgreen">48</td><td align="right" style="background:yellow">56</td><td align="right" style="background:lightgreen">64</td><td align="right" style="background:yellow">72</td><td align="right" style="background:lightgreen">80</td></tr><tr><td align="right" style="background:white">9</td><td align="right" style="background:lightblue">18</td><td align="right" style="background:white">27</td><td align="right" style="background:lightblue">36</td><td align="right" style="background:white">45</td><td align="right" style="background:lightblue">54</td><td align="right" style="background:white">63</td><td align="right" style="background:lightblue">72</td><td align="right" style="background:white">81</td><td align="right" style="background:lightblue">90</td></tr><tr><td align="right" style="background:yellow">10</td><td align="right" style="background:lightgreen">20</td><td align="right" style="background:yellow">30</td><td align="right" style="background:lightgreen">40</td><td align="right" style="background:yellow">50</td><td align="right" style="background:lightgreen">60</td><td align="right" style="background:yellow">70</td><td align="right" style="background:lightgreen">80</td><td align="right" style="background:yellow">90</td><td align="right" style="background:lightgreen">100</td></tr></table> <table border="1"><tr><td align="right" style="background:white">1</td><td align="right" style="background:lightblue">2</td><td align="right" style="background:white">3</td><td align="right" style="background:lightblue">4</td><td align="right" style="background:white">5</td><td align="right" style="background:lightblue">6</td><td align="right" style="background:white">7</td><td align="right" style="background:lightblue">8</td><td align="right" style="background:white">9</td><td align="right" style="background:lightblue">10</td></tr><tr><td align="right" style="background:yellow">2</td><td align="right" style="background:lightgreen">4</td><td align="right" style="background:yellow">6</td><td align="right" style="background:lightgreen">8</td><td align="right" style="background:yellow">10</td><td align="right" style="background:lightgreen">12</td><td align="right" style="background:yellow">14</td><td align="right" style="background:lightgreen">16</td><td align="right" style="background:yellow">18</td><td align="right" style="background:lightgreen">20</td></tr><tr><td align="right" style="background:white">3</td><td align="right" style="background:lightblue">6</td><td align="right" style="background:white">9</td><td align="right" style="background:lightblue">12</td><td align="right" style="background:white">15</td><td align="right" style="background:lightblue">18</td><td align="right" style="background:white">21</td><td align="right" style="background:lightblue">24</td><td align="right" style="background:white">27</td><td align="right" style="background:lightblue">30</td></tr><tr><td align="right" style="background:yellow">4</td><td align="right" style="background:lightgreen">8</td><td align="right" style="background:yellow">12</td><td align="right" style="background:lightgreen">16</td><td align="right" style="background:yellow">20</td><td align="right" style="background:lightgreen">24</td><td align="right" style="background:yellow">28</td><td align="right" style="background:lightgreen">32</td><td align="right" style="background:yellow">36</td><td align="right" style="background:lightgreen">40</td></tr><tr><td align="right" style="background:white">5</td><td align="right" style="background:lightblue">10</td><td align="right" style="background:white">15</td><td align="right" style="background:lightblue">20</td><td align="right" style="background:white">25</td><td align="right" style="background:lightblue">30</td><td align="right" style="background:white">35</td><td align="right" style="background:lightblue">40</td><td align="right" style="background:white">45</td><td align="right" style="background:lightblue">50</td></tr><tr><td align="right" style="background:yellow">6</td><td align="right" style="background:lightgreen">12</td><td align="right" style="background:yellow">18</td><td align="right" style="background:lightgreen">24</td><td align="right" style="background:yellow">30</td><td align="right" style="background:lightgreen">36</td><td align="right" style="background:yellow">42</td><td align="right" style="background:lightgreen">48</td><td align="right" style="background:yellow">54</td><td align="right" style="background:lightgreen">60</td></tr><tr><td align="right" style="background:white">7</td><td align="right" style="background:lightblue">14</td><td align="right" style="background:white">21</td><td align="right" style="background:lightblue">28</td><td align="right" style="background:white">35</td><td align="right" style="background:lightblue">42</td><td align="right" style="background:white">49</td><td align="right" style="background:lightblue">56</td><td align="right" style="background:white">63</td><td align="right" style="background:lightblue">70</td></tr><tr><td align="right" style="background:yellow">8</td><td align="right" style="background:lightgreen">16</td><td align="right" style="background:yellow">24</td><td align="right" style="background:lightgreen">32</td><td align="right" style="background:yellow">40</td><td align="right" style="background:lightgreen">48</td><td align="right" style="background:yellow">56</td><td align="right" style="background:lightgreen">64</td><td align="right" style="background:yellow">72</td><td align="right" style="background:lightgreen">80</td></tr><tr><td align="right" style="background:white">9</td><td align="right" style="background:lightblue">18</td><td align="right" style="background:white">27</td><td align="right" style="background:lightblue">36</td><td align="right" style="background:white">45</td><td align="right" style="background:lightblue">54</td><td align="right" style="background:white">63</td><td align="right" style="background:lightblue">72</td><td align="right" style="background:white">81</td><td align="right" style="background:lightblue">90</td></tr><tr><td align="right" style="background:yellow">10</td><td align="right" style="background:lightgreen">20</td><td align="right" style="background:yellow">30</td><td align="right" style="background:lightgreen">40</td><td align="right" style="background:yellow">50</td><td align="right" style="background:lightgreen">60</td><td align="right" style="background:yellow">70</td><td align="right" style="background:lightgreen">80</td><td align="right" style="background:yellow">90</td><td align="right" style="background:lightgreen">100</td></tr></table>
</box>
</box>
</page> </page>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment