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

[r2005-04-27 16:23:32 by cmiachon] rewriting projections with the uses cases...

[r2005-04-27 16:23:32 by cmiachon] rewriting projections with the uses cases xquery types And adding many
examples of differents kind of projections.

Original author: cmiachon
Date: 2005-04-27 16:23:32+00:00
parent 49026a0f
......@@ -13,8 +13,8 @@ test it on the <a href="cgi-bin/cduce">online interpreter</a>.
<box title="Select from where" link="sel">
<b style="color:#FF0080">WE SHOULD REWRITE THIS SECSION TO
GET READY OF THE MANY TYPE DEFINITIONS. JUST USE THE ONE
<b style="color:#FF0080">WE SHOULD REWRITE THIS SECTION TO
GET READ OF THE MANY TYPE DEFINITIONS. JUST USE THE ONE
OF USE CASES</b>
......@@ -50,7 +50,7 @@ transform %%e1%% with %%p1%% ->
<box title="XPath-like expressions" link="xpath">
<p> XPath-like expressions are of two kind :
<code> %%e%%/%%t%% </code>, <code> %%e%%/@%%a%% </code>, and <code> %%e%%//%%t%% </code> where <code>%%e%%</code> is an expression, <code> %%t%% </code> a type, and <code> %%a%% </code> an attribute.
<code> %%e%%/%%t%% </code>, <code> %%e%%/@%%a%% </code>, (and <code> %%e%%//%%t%% </code>) where <code>%%e%%</code> is an expression, <code> %%t%% </code> a type, and <code> %%a%% </code> an attribute.
</p>
<p>
......@@ -60,137 +60,258 @@ They are syntactic sugar for :</p>
<sample><![CDATA[
select x from <_ a=x ..>_ in e]]>
</sample>
</box>
<box title="Examples" link="exsel">
<section title="Types and data for the examples">
<p> Let us consider the following types representing a Bibliography </p>
<p> Let us consider the following DTD and the CDuce types representing a Bibliography </p>
<sample><![CDATA[
type Biblio = <bibliography>[Heading Paper*]
type Heading = <heading>[ PCDATA ]
type Paper = <paper>[ Author+ Title Conference File ]
type Author = <author>[ PCDATA ]
type Title = <title>[ PCDATA ]
type Conference = <conference>[ PCDATA ]
type File = <file>[ PCDATA ]
<!ELEMENT bib (book* )>
<!ELEMENT book (title, (author+ | editor+ ), publisher, price )>
<!ATTLIST book year CDATA #REQUIRED >
<!ELEMENT author (last, first )>
<!ELEMENT editor (last, first, affiliation )>
<!ELEMENT title (#PCDATA )>
<!ELEMENT last (#PCDATA )>
<!ELEMENT first (#PCDATA )>
<!ELEMENT affiliation (#PCDATA )>
<!ELEMENT publisher (#PCDATA )>
<!ELEMENT price (#PCDATA )>
type bib = <bib>[book*]
type book = <book year=String>[title (author+ | editor+ ) publisher price ]
type author = <author>[last first ]
type editor = <editor>[last first affiliation ]
type title = <title>[PCDATA ]
type last = <last>[PCDATA]
type first = <first>[PCDATA]
type affiliation = <affiliation>[PCDATA]
type publisher = <publisher>[PCDATA]
type price = <price>[PCDATA]
]]>
</sample>
<p> and some values </p>
<sample><![CDATA[
let 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"
]
]
let biblio : bib =
<bib>[
<book year="1994">[
<title>['TCP/IP Illustrated']
<author>[
<last>['Stevens']
<first>['W.']]
<publisher>['Addison-Wesley']
<price>['65.95'] ]
<book year="1992">[
<title>['Advanced Programming in the Unix environment']
<author>[
<last>['Stevens']
<first>['W.']]
<publisher>['Addison-Wesley']
<price>['65.95'] ]
<book year="2000">[
<title>['Data on the Web']
<author>[
<last>['Abiteboul']
<first>['Serge']]
<author>[
<last>['Buneman']
<first>['Peter']]
<author>[
<last>['Suciu']
<first>['Dan']]
<publisher>['Morgan Kaufmann Publishers']
<price>['39.95'] ]
<book year="1999">[
<title>['The Economics of Technology and Content for Digital TV']
<editor>[
<last>['Gerbarg']
<first>['Darcy']
<affiliation>['CITI'] ]
<publisher>['Kluwer Academic Publishers']
<price>['129.95']]
]
]]>
</sample>
</section>
<section title="Projections">
<p> All titles in the bibliography bib </p>
<ul>
<li> All titles in the bibliography biblio
<sample><![CDATA[
let titles = [bib]/<paper>_/<title>_
let titles = [biblio]/book/title
]]>
</sample>
<p> Which yields to:</p>
<sample><![CDATA[
val titles : [ <title>[ Char* ]* ] = [ <title>[ 'Semantic subtyping' ]
<title>[ 'The Relevance of Semantic Subtyping' ]
<title>[ 'CDuce: a white-paper' ]
]
Ok.
val titles : [ title* ] = [ <title>[ 'TCP/IP Illustrated' ]
<title>[ 'Advanced Programming in the Unix environment' ]
<title>[ 'Data on the Web' ]
<title>[ 'The Economics of Technology and Content for Digital TV' ]
]
]]>
</sample>
<p> All authors in the bibliography bib </p>
</li>
<li>All authors in the bibliography biblio
<sample><![CDATA[
let authors = [bib]/<paper>_/<author>_
let authors = [biblio]/book/author
]]>
</sample>
<p> Yielding the result: </p>
<sample><![CDATA[
val authors : [ <author>[ Char* ]* ] = [ <author>[ 'Alain Frisch' ]
<author>[ 'Giuseppe Castagna' ]
<author>[ 'Veronique Benzaken' ]
<author>[ 'Mariangiola Dezani-Ciancaglini' ]
<author>[ 'Alain Frisch' ]
<author>[ 'Elio Giovannetti' ]
<author>[ 'Yoko Motohama' ]
<author>[ 'Veronique Benzaken' ]
<author>[ 'Giuseppe Castagna' ]
<author>[ 'Alain Frisch' ]
]
Ok.
val authors : [ author* ] = [ <author>[ <last>[ 'Stevens' ] <first>[ 'W.' ] ]
<author>[ <last>[ 'Stevens' ] <first>[ 'W.' ] ]
<author>[
<last>[ 'Abiteboul' ]
<first>[ 'Serge' ] ]
<author>[
<last>[ 'Buneman' ]
<first>[ 'Peter' ] ]
<author>[ <last>[ 'Suciu' ] <first>[ 'Dan' ] ]
]
]]>
</sample>
<p> All papers in the bibliography bib </p>
</li>
<li> All books having an editor in the bibliography biblio
<sample><![CDATA[
let papers = [bib]/<paper>_
let edibooks = [biblio]/<book year=_>[_* editor _*]
]]>
</sample>
<p> Yielding: </p>
<sample><![CDATA[
val papers : [ <paper>[ Author+ Title Conference File ]* ] = [ <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' ]
]
]
Ok.
val edibooks : [ <book year=String>[ title editor+ publisher price]* ] =
[ <book year="1999">[
<title>[ 'The Economics of Technology and Content for Digital TV']
<editor>[
<last>[ 'Gerbarg' ]
<first>[ 'Darcy' ]
<affiliation>[ 'CITI' ] ]
<publisher>[ 'Kluwer Academic Publishers' ]
<price>[ '129.95' ] ]
]
]]>
</sample>
</li>
<li> All books without authors.
<sample><![CDATA[
let edibooks2 = [biblio]/<book ..>[(Any\author)*]
]]>
</sample>
<p> Yielding: </p>
<sample><![CDATA[
val edibooks2 : [ <book year=String>[ title editor+ publisher price]* ] =
[ <book year="1999">[
<title>[ 'The Economics of Technology and Content for Digital TV']
<editor>[
<last>[ 'Gerbarg' ]
<first>[ 'Darcy' ]
<affiliation>[ 'CITI' ] ]
<publisher>[ 'Kluwer Academic Publishers' ]
<price>[ '129.95' ] ]
]
]]>
</sample>
</li>
<li> The year of books having a price of 65.95 in the bibliography biblio
<sample><![CDATA[
let books = [biblio]/<book ..>[_* <price>['65.95']]/@year
]]>
</sample>
<p> Yielding: </p>
<sample><![CDATA[
val books : [ String* ] = [ "1994" "1992" ]
]]>
</sample>
</li>
<li> All the authors and editors in biblio
<sample><![CDATA[
let aebooks = [biblio]/book/(author|editor)
]]>
</sample>
<p> Yielding: </p>
<sample><![CDATA[
val aebooks : [ (editor | author)* ] = [ <author>[
<last>[ 'Stevens' ]
<first>[ 'W.' ]
]
<author>[
<last>[ 'Stevens' ]
<first>[ 'W.' ]
]
<author>[
<last>[ 'Abiteboul' ]
<first>[ 'Serge' ]
]
<author>[
<last>[ 'Buneman' ]
<first>[ 'Peter' ]
]
<author>[
<last>[ 'Suciu' ]
<first>[ 'Dan' ]
]
<editor>[
<last>[ 'Gerbarg' ]
<first>[ 'Darcy' ]
<affiliation>[ 'CITI' ]
]
]
]]>
</sample>
</li>
</ul>
<p>
An interesting point in Cduce is the static typing of an expression. By example if we consider the third projection,
"All books having an editor in the bibliography", CDuce knows the type of the result of the value <code>%%edibooks%%</code>:
</p><sample><![CDATA[
val edibooks : [ <book year=String>[ title editor+ publisher price]* ] =
...
]]>
</sample>
<p>This type represents a book without author (see the book type in the type declaration in the top of this section).
Now if we want to know all authors of this list of books <code>%%edibooks%%</code>:
</p>
<sample><![CDATA[
let authorsofedibooks = edibooks/author
]]>
</sample>
<p>Yelding:</p>
<sample><![CDATA[
Warning at chars 24-39:
This projection always returns the empty sequence
val authorsofedibooks : [ ] = ""
]]>
</sample>
<p>
In fact the value <code>%%edibooks%%</code> must be a subtype of <![CDATA[[<_ ..>[Any* author Any*] *]]]>,
and here this is not the case.
If you want to be sure, test this:
</p>
<sample><![CDATA[
match edibooks with [<_ ..>[_* author _*] *] -> "this is a subtype" | _ -> "this is not a subtype" ;;
]]>
</sample>
<p>
An other projection should be convince you, is the query:
</p>
<sample><![CDATA[
let freebooks = [biblio]/book/<price>['0']
]]]>
</sample>
<p>Yelding:</p>
<sample><![CDATA[
val freebooks : [ <price>[ '0' ]* ] = ""
]]>
</sample>
<p>
this projection returns the empty sequence (<code>""</code>)</p>
</section>
<section title="Select_from_where">
<section title="Select_from_where">
<p>The same queries we wrote above can of course be programmed with the <code>select_from_where</code> construction </p>
<p> All the titles </p>
<sample><![CDATA[
......
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