You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
464 lines
38 KiB
464 lines
38 KiB
|
|
<H1>RDF Query Specification</H1><H1>December 3, 1998</H1>
|
|
|
|
<!doctype html public '-//W3C//DTD HTML 4.0 Transitional//EN' 'http://www.w3.org/TR/REC-html40-971218/loose.dtd'><HTML><HEAD><meta name='GENERATOR' content='XML/XH/Lark'><link rel='STYLESHEET' type='text/css' href='xml.css'><TITLE>RDF Query Specification</TITLE></HEAD><BODY BGCOLOR='#ffffff'>
|
|
|
|
<H2>Authors</H2>
|
|
<DD>Ashok Malhotra
|
|
(IBM)
|
|
<A HREF='mailto:petsa@us.ibm.com'><petsa@us.ibm.com></A></DD>
|
|
<DD>Neel Sundaresan
|
|
(IBM)
|
|
<A HREF='mailto:neel@almaden.ibm.com'><neel@almaden.ibm.com></A></DD>
|
|
</dl>
|
|
|
|
<H2>Abstract</H2>
|
|
<P>This paper presents syntax and facilities for RDF Query. RDF query
|
|
is a declarative syntax for selecting RDF resources that meet
|
|
specified criteria.
|
|
</P>
|
|
<H2>Status</H2>
|
|
<P>This is a technical contribution to the W3C Query Languages Workshop, Dec 3 and 4, 1998.
|
|
</P>
|
|
|
|
|
|
|
|
|
|
<h2>Table of Contents</h2>1. <A HREF='#Intro'>Introduction</A><BR>
|
|
2. <A HREF='#Concepts'>Concepts</A><BR>
|
|
3. <A HREF='#Examples'>Examples</A><BR>
|
|
3.1 <A HREF='#Example1'>Selecting all resources from a collection</A><BR>
|
|
3.2 <A HREF='#Example2'>Selecting all resources with a given property</A><BR>
|
|
3.3 <A HREF='#Example3'>Selecting all resources which satisfy a given condition</A><BR>
|
|
3.4 <A HREF='#Example8'>Complex conditions</A><BR>
|
|
3.5 <A HREF='#Example7'>Nested Queries</A><BR>
|
|
3.6 <A HREF='#Example6'>Projection</A><BR>
|
|
3.7 <A HREF='#Example10'>Aggregation</A><BR>
|
|
3.8 <A HREF='#Example11'>Composing Results</A><BR>
|
|
3.9 <A HREF='#Example12'>Grouping By Property Values</A><BR>
|
|
3.10 <A HREF='#Example13'>Sorting Results</A><BR>
|
|
3.11 <A HREF='#Example14'>Quantification</A><BR>
|
|
4. <A HREF='#Inference'>Vocabulary-Specific Inference</A><BR>
|
|
5. <A HREF='#DTD'>A DTD For RDF Query</A><BR>
|
|
6. <A HREF='#biblio'>References</A><BR>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2><A NAME='Intro'>1. Introduction</a></h2>
|
|
<P>One of the major contributions of the Relational data model, introduced
|
|
a little over 25 years ago by <A href='#Codd'>[Codd]</A> was was an
|
|
accompanying, declarative query language. In contrast to earlier
|
|
query languages, <A href='#SQL'>[SQL]</A> lets you specify what should be retrieved rather
|
|
than how it should be retrieved. This freed the user from knowing how
|
|
the data was stored. SQL also established the major components of a
|
|
query language: a source over which the query executes; a selection
|
|
condition; a specification for what has to be returned and constructs
|
|
to control how it should be presented.</P>
|
|
<P><A href='#RDF-Syntax'>[RDF]</A> is the W3C's recommended framework for
|
|
metadata. In fact, the underlying data model is a semantic network
|
|
model that has surfaced several times, over the years, in slightly different forms for data and
|
|
knowledge representation <A href='#Findler'>[Findler]</A><A href='#KL1'>[Brachman]</A><A href='#Chen'>[Chen]</A>. In this paper we present a declarative query language for RDF.
|
|
We hope this will be useful for other RDF-based
|
|
efforts such as <A href='#P3P'>[P3P]</A>.</P>
|
|
<P>RDF Query needs to be more complex than SQL since the RDF
|
|
data model is more complex than the Relational data model.
|
|
Specifically, while a relational query executes over one or more
|
|
tables each containing tuples with the same structure, an RDF query
|
|
executes over a RDF container that may contain resources of different
|
|
types each with different properties. Values of properties, rather
|
|
than being merely data, can be resources themselves. Finally,
|
|
property values can be RDF containers.</P>
|
|
<P>At IBM we use RDF in the "Grand Central" family of intelligent search
|
|
engines, of which <A href='#jCentral'>[jCentral]</A> which searches for Java related resources is an example. These search engines
|
|
extract metadata about websites and encode it as a collection of RDF
|
|
structures which are then queried in response to user requests.
|
|
The query facilities are implemented using a number of embedded Java
|
|
functions. This paper is our attempt to abstract
|
|
those facilities and encode them in a XML-style, declarative syntax.</P>
|
|
|
|
|
|
|
|
<H2><A NAME='Concepts'>2. Concepts</a></h2>
|
|
|
|
<P>An RDF Query (rdfquery) operates on a source container of resources and
|
|
returns a result container of resources. The result container
|
|
is always a subset of the source container and may be empty. Thus, RDF queries
|
|
provide closure; they start with a container of RDF resources and they
|
|
return a container of RDF resources. The result container can be the
|
|
source for another RDF query.</P>
|
|
<P>
|
|
Note that RDF queries are expressed using RDF descriptions (metadata).
|
|
Since RDF has an XML syntax, and RDF
|
|
Query is an RDF vocabulary, RDF Query also has an XML syntax. We use
|
|
the name space rdfq for tag names used in RDF Query specifications.
|
|
</P>
|
|
|
|
<P>
|
|
RDF defines three kinds of resources and their descriptions:
|
|
<UL>
|
|
<LI>RDF descriptions that describe resources that are defined
|
|
elsewhere. These descriptions use the "about" attribute to describe
|
|
these resources.</LI>
|
|
<LI>RDF descriptions that describe resources inline. These resources
|
|
may by proxies for real resources. These descriptions use the "id"
|
|
attribute.</LI>
|
|
<LI>RDF descriptions that are reified. These descriptions use the
|
|
bagID attributes.</LI>
|
|
</UL>
|
|
|
|
The RDF query language must be able to describe queries over these
|
|
kinds of resources and their descriptions.
|
|
</P>
|
|
<P>A rdfquery must specify a source collection and may specify a
|
|
property name or a condition. If a property name or condition is not specified
|
|
the query returns all resources in the source collection. If a
|
|
property name is specified, the query returns all resources in the
|
|
source collection whose have the named property. If a condition is specified,
|
|
the query returns all resources in the source collection for whom the
|
|
condition evalutes <code>True</code>. Instead of returning the qualifying
|
|
resources, rdfquery also allows us to create new resources from the qualifying
|
|
resources with fewer properties. This enables us to build views on the source containers.</P>
|
|
<P>The latest <A href='#RDF-Syntax'>[RDF]</A> specification says at the end
|
|
of section 2.1 "Property values can be other resources or they can be
|
|
atomic; that is, simple strings or other primitive datatypes defined
|
|
by XML." As far as we know, there are no primitive datatypes defined
|
|
in XML except strings. However, there is ongoing work to do so.
|
|
See <A href='#DCD'>[DCD]</A>.
|
|
We shall assume that primitive datatypes will be added to XML and RDF
|
|
and thus we can define a richer set of query primitives than are possible
|
|
with only strings. In this paper we use tags such as
|
|
<code>rdf:Integer</code> to identify such datatypes.</P>
|
|
|
|
|
|
|
|
|
|
<H2><A NAME='Examples'>3. Examples</a></h2>
|
|
|
|
|
|
|
|
<H3><A NAME='Example1'>3.1 Selecting all resources from a collection</a></h3>
|
|
<P>
|
|
Consider a collection of RDF resources. These resources may be
|
|
identified by their URIs, IDs, or bagIDs.
|
|
Since no property or condition is specified, the following query selects all resources in a explicitly specified collection of
|
|
resources.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfquery><BR> <rdfq:From><BR> <rdf:Bag><BR> <li resource="http://www.research.ibm.com/people/ashok/paper1.html"/><BR> <li resource="http://www.research.ibm.com/people/ashok/paper3.html"/><BR> <li resource="http://www.research.ibm.com/people/neel/paper1.html"/><BR> <li resource="http://www.research.ibm.com/people/neel/paper7.html"/><BR> </rdf:Bag><BR> </rdfq:From><BR></rdfquery><BR></font></code></td></tr></table><p>
|
|
</P>
|
|
<P>
|
|
If there is only one resource to be selected from, the <code>rdf:Bag</code> may
|
|
be omitted and the resource specified as an attribute of the <code>rdfq:From</code>
|
|
element directly.
|
|
</P>
|
|
<P>
|
|
In the more common case, the query will specify a container that contains
|
|
the resources. We introduce an
|
|
attribute of <code>rdfq:From</code> called <code>eachResource</code> (similar
|
|
to aboutEach in RDF) to query all the resources in a container.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><BR><rdfquery><BR> <rdfq:From eachResource="papers"/><BR></rdfquery><BR></font></code></td></tr></table><p>
|
|
where the resources could be collected elsewhere in a container as
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><BR><BR> <rdf:Bag bagID="papers"><BR> <li resource="http://www.research.ibm.com/people/ashok/paper1.html"/><BR> <li resource="http://www.research.ibm.com/people/ashok/paper3.html"/><BR> <li resource="http://www.research.ibm.com/people/neel/paper1.html"/><BR> <li resource="http://www.research.ibm.com/people/neel/paper7.html"/><BR> </rdf:Bag><BR><BR></font></code></td></tr></table><p>
|
|
</P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example2'>3.2 Selecting all resources with a given property</a></h3>
|
|
<P>The following query selects all resources in the collection that
|
|
have the property "ResearchPapers".
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><BR><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"/><BR> <rdfq:Select><BR> <rdfq:Property name="ResearchPapers"/><BR> </rdfq:Select><BR> </rdfq:From><BR></rdfq:rdfquery><BR></font></code></td></tr></table><p>
|
|
</P>
|
|
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example3'>3.3 Selecting all resources which satisfy a given condition</a></h3>
|
|
<P>The following query selects all resources in the collection
|
|
that have a property named <code>Project</code> whose value is
|
|
the string "WebTechnologies". Here we assume the String data type is defined in RDF.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"/><BR> <rdfq:Select><BR> <rdfq:Condition><BR> <rdfq:equals><BR> <rdfq:Property name="Project" /><BR> <rdf:String>WebTechnologies</rdf:String><BR> </rdfq:equals><BR> </rdfq:Condition><BR> </rfq:Select><BR> </rdfq:From><BR></rdfq:rdfquery></font></code></td></tr></table><p> </P>
|
|
<P>The value of the <code>Project</code> property may be a text string or it
|
|
may be a reified property with <code>predicate</code> equal to
|
|
<code>Project</code>
|
|
and <code>object</code> equal to <code>WebTechnologies</code>.
|
|
<EM> The query will select
|
|
instances where the property is represented in either of these
|
|
forms.</EM></P>
|
|
<P>If the resource does not have the given property, the condition
|
|
evaluates <code>false</code>.</P>
|
|
<P>Clearly, we need to be able to test on conditions other than
|
|
<code>equals</code>. The following query selects resources from a
|
|
collection of people in IBM Research
|
|
where the value of the <code>age</code> property is greater
|
|
than 50.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/"><BR> <rdfq:Select><BR> <rdfq:Condition><BR> <rdfq:greaterThan><BR> <rdfq:Property name="Age" /><BR> <rdf:Integer>50</rdf:Integer><BR> </rdfq:greaterThan><BR> </rdfq:Condition><BR> </rdfq:Select> <BR> </rdfq:From><BR></rdfq:rdfquery></font></code></td></tr></table><p> </P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example8'>3.4 Complex conditions</a></h3>
|
|
<P>Complex conditions can be specified by using boolean operators in
|
|
the <code>Select</code> tag.
|
|
The following query selects all people resources in IBM Research who report
|
|
to departments where the budget is greater than a million dollars <code>and</code> the
|
|
department size is less than 10 people.
|
|
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people"><BR> <rdfq:Select><BR> <rdfq:Condition><BR> <rdfq:and><BR> <rdfq:greaterThan><BR> <rdfq:Property name="Budget" /><BR> <rdf:Integer>1000000</rdf:Integer> <BR> </rdfq:greaterThan><BR> <rdfq:lessthan><BR> <rdfq:Property name="Size" /><BR> <rdf:Integer>10</rdf:Integer><BR> </rdfq:lessthan><BR> </rdfq:Condition><BR> </rdfq:Select><BR> </rdfq:From><BR></rdfq:rdfquery><BR></font></code></td></tr></table><p> </P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example7'>3.5 Nested Queries</a></h3>
|
|
<P>If the value of the property is a RDF resource (inline or external)
|
|
then the selection criterion may include constraints on the properties
|
|
of the value resource.
|
|
The following query selects all people in IBM Research who report to resources
|
|
(departments) where the budget is over 1 million dollars.
|
|
The syntax should be read as follows: find the resources in the source
|
|
collection which have the <code>BelongTo</code> property; apply the
|
|
condition to each of these resources; add those resources for whom the
|
|
condition returns <code>True</code> to the result set.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/"><BR> <rdfq:Select><BR> <rdfq:Property name="BelongTo" /><BR> <rdfq:Select><BR> <rdfq:Condition><BR> <rdfq:greaterThan><BR> <rdfq:Property name="Budget" /><BR> <rdf:Integer>1000000</rdf:Integer><BR> </rdfq:greaterThan><BR> </rdfq:Condition><BR> </rdfq:Select><BR> </rdfq:Select><BR> </rdfq:From><BR></rdfq:rdfquery></font></code></td></tr></table><p> </P>
|
|
<P>
|
|
Note that for every navigation across a property a new rdfq:Property
|
|
element needs to be
|
|
introduced. An abbreviation syntax makes this less complex.
|
|
This abbreviation is similar to a path-expression.
|
|
One possible abbreviation is to use rdf:Seq.
|
|
Suppose a property named "ResearchPaper" has a
|
|
value which is an RDF description with a property named "Conference" whose
|
|
value is an RDF description with a property named "Venue" whose value
|
|
is an RDF description with a property named "Country". Now suppose
|
|
that one wants
|
|
to query, based upon all the publications that Neel has, those that
|
|
were in foreign conferences. One could write this query,
|
|
using the RDF abbreviation syntax, as:
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"/><BR> <rdfq:Select><BR> <rdfq:Condition><BR> <rdfq:not><BR> <rdfq:equal><BR> <rdfq:Property><BR> <rdfq:Seq><BR> <li>ResearchPapers</li><BR> <li>Conference</li><BR> <li>Venue</li><BR> <li>Country</li><BR> </rdfq:Seq><BR> </rdfq:Property><BR> <rdf:String>U.S.A.</rdf:String><BR> </rdfq:equal><BR> </rdfq:not><BR> </rdfq:Condition><BR> </rdfq:Select><BR> </rdfq:rdfquery><BR></font></code></td></tr></table><p>
|
|
</P>
|
|
<P>An alternate linear syntax would use the / operator to indicate
|
|
navigating over properties. This is similar to its use in
|
|
<A href='#XQL'>[XQL Proposal]</A>. Alternately the .. operator may be used to
|
|
indicate navigation as in <A href='#OQL'>[OQL]</A>.
|
|
Using the / operator, the navigation over
|
|
ResearchPapers, Conference, Venue and Country would be expressed as
|
|
ResearchPapers/Conference/Venue/Country. We introduce a new attribute for
|
|
<code>rdfq:Property</code> called <code>path</code>. to indicate a path
|
|
expression. With this, the above example
|
|
could be written as:
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"/><BR> <rdfq:Select><BR> <rdfq:Condition><BR> <rdfq:not><BR> <rdfq:equal><BR> <rdfq:Property path="ResearchPapers/Conference/Venue/Country"/><BR> <rdf:String>U.S.A.</rdf:String><BR> </rdfq:equal><BR> </rdfq:not><BR> </rdfq:Condition><BR> </rdfq:Select><BR> </rdfq:rdfquery><BR></font></code></td></tr></table><p></P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example6'>3.6 Projection</a></h3>
|
|
<P>Sometimes it is useful, on selecting a set of resources that
|
|
satisfy a condition, to build proxy sets of resources with only some of the
|
|
properties. This requires building an inline RDF description
|
|
or container with only the selected properties. To describe this we
|
|
introduce an attribute of the <code>Select</code> clause called
|
|
<code>properties</code>. A longer syntax for the same function in RDF form can be
|
|
achieved by adding a <code>properties</code> element (or RDF property) to
|
|
<code>rdfq:Select</code> and whose value can be an <code>rdf:Bag</code>
|
|
listing all the properties on which the projection is done. We prefer
|
|
the abbreviated syntax. The following example selects from a set of
|
|
people in IBM Research, those whose project is
|
|
"WebTechnologies" and builds a description with properties "fullname"
|
|
(name of the person) and "experience" (number of years in the project).
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/"/><BR> <rdfq:Select properties="fullname experience"><BR> <rdfq:Property name="WebTechnologies/><BR> </rfq:Select><BR> </rdfq:From><BR></rdfq:rdfquery></font></code></td></tr></table><p> </P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example10'>3.7 Aggregation</a></h3>
|
|
<P>Aggregation operations can be applied to RDF objects that are
|
|
containers. Specifically, we may want to to evaluate an aggregate
|
|
function on the result sets of a rdfquery. To specify this we
|
|
add an attribute called <code>aggregate</code> to the
|
|
<code>rdfq:Select</code> element. The value of this attribute can only be
|
|
the name of an aggregate function such as <code>count</code>, <code>min</code>, or
|
|
<code>max</code>.
|
|
Let us modify the previous query to find the count of all papers
|
|
written by Neel in foreign conferences. In the example <code>count</code>
|
|
is applied to all resources in the source container that satisfy the
|
|
condition. The "*" means apply to all. In a later example,
|
|
<code>count</code> is applied to a specific property.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"/><BR> <rdfq:Select properties="count(*)"><BR> <rdfq:Condition><BR> <rdfq:not><BR> <rdfq:equal><BR> <rdfq:Property path="ResearchPapers/Conference/Venue/Country"/><BR> <rdf:String>U.S.A.</rdf:String><BR> </rdfq:equal><BR> </rdfq:not><BR> </rdfq:Condition><BR> </rdfq:Select><BR> </rdfq:rdfquery><BR></font></code></td></tr></table><p> </P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example11'>3.8 Composing Results</a></h3>
|
|
<P>Sometimes we would like to perform algebraic set operations on the
|
|
result sets. We support three kinds of operations: Union, Intersection,
|
|
and Difference.
|
|
For instance to find all papers written by Neel and all papers written
|
|
by Ashok.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:Union><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"><BR> <rdfq:Select><BR> <rdfq:Property name="ResearchPapers"/> <BR> </rdfq:Select><BR> </rdfq:From><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/Ashok"><BR> <rdfq:Select><BR> <rdfq:Property name="ResearchPapers"/> <BR> </rdfq:Select><BR> </rdfq:From><BR> </rdfq:Union><BR></rdfq:rdfquery><BR></font></code></td></tr></table><p> </P>
|
|
<P>
|
|
Duplicate elimination in the result RDF structures depends on the
|
|
notion of equality of property values. If that is clearly specified,
|
|
we can have the Union operator eliminate all duplicate occurrences of
|
|
papers (this would eliminate all papers jointly authored by Neel and
|
|
Ashok from occuring twice).
|
|
</P>
|
|
<DT><B>Aliasing</B></DT>
|
|
<P>
|
|
Set operations are allowed only on RDF structures that have the
|
|
same set of properties, i.e. properties with the same names. In order
|
|
to allow for equivalent properties with different names, aliases are
|
|
suppoerted. Suppose Ashok refers to his papers as "ResearchPapers" on his
|
|
web site, and Neel refers to his papers as "Publications" and we want
|
|
to perform a union on these. We introduce an alias for the property
|
|
name "Publications". We can also alias both the property names and
|
|
give them a new name, such as "articles", in the union.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:Union><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"><BR> <rdfq:Select><BR> <rdfq:Property name="ResearchPapers" /> <BR> </rdfq:Select><BR> </rdfq:From><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/Ashok"><BR> <rdfq:Select><BR> <rdfq:Property name="Publications" alias="ResearchPapers"/> <BR> </rdfq:Select><BR> </rdfq:From><BR> </rdfq:Union><BR></rdfq:rdfquery><BR></font></code></td></tr></table><p> </P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example12'>3.9 Grouping By Property Values</a></h3>
|
|
<P>When doing aggregate operations one might want to build containers
|
|
(collections) grouped by property values before performing aggregations.
|
|
Suppose one would like to count the number of papers
|
|
published by Neel every year. The result will be an RDF Description
|
|
that will provide a description of "http://www.research.ibm.com/people/neel" as container with each
|
|
member in the container describing two properties
|
|
"ResearchPapers/Conference/Year", and "count". This can be expressed as below.
|
|
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"><BR> <rdfq:Select properties = "ResearchPapers/Conference/Year<BR> count(ResearchPapers/Conference/Year)"><BR> <rdfq:Group><BR> <rdfq:Property path="ResearchPapers/Conference/Year"/> <BR> </rdfq:Group> <BR> </rdfq:Select><BR> </rdfq:From><BR></rdfq:rdfquery><BR></font></code></td></tr></table><p>
|
|
</P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example13'>3.10 Sorting Results</a></h3>
|
|
<P>Since the result of a query can be an RDF object which could possibly be an RDF container
|
|
we may want to sort the results based upon property values and return an RDF sequence.
|
|
We introduce a tag <code>rdfq:Order</code> for this purpose. To order by multiple properties this will contain
|
|
an rdf:Seq with the sequence in which the ordering is to be done.
|
|
To select all papers written by Neel, ordered by the year of
|
|
publication and within the same year by month we would write:
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="http://www.research.ibm.com/people/neel"><BR> <rdfq:Select><BR> <rdfq:Property name="ResearchPapers"/><BR> </rdfq:Select><BR> <rdfq:Order><BR> <rdf:Seq><BR> <rdfq:Property path="ResearchPapers/Year"/><BR> <rdfq:Property path="ResearchPapers/Month"/><BR> <rdf:Seq><BR> </rdfq:Order><BR> </rdfq:From><BR></rdfq:rdfquery><BR></font></code></td></tr></table><p>
|
|
</P>
|
|
|
|
|
|
|
|
|
|
<H3><A NAME='Example14'>3.11 Quantification</a></h3>
|
|
<P>To support queries based upon <EM>for all</EM> and <EM>there
|
|
exists</EM> quantification we introduce <code>rdfq:quantifier</code> and <code>exists</code> and
|
|
<code>forAll</code> attributes. These are used to test whether any or
|
|
all members of a collection meet a given condition. Since quantifiers
|
|
are boolean conditions, they can occur anywhere a condition clause can occur.
|
|
We also introduce a variable <code>var</code> which ranges over all the
|
|
members of the collection. The body of the quantifier has two
|
|
expression elements: the first evaluates to a collection ,the
|
|
second, which is a <code>rdfq:Condition</code>, evaluates a boolean
|
|
condition over the first element. Thus, "for each x in S : cond(x)" translates to
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><BR><BR> <rdfq:quantifier type="forAll" var="x"><BR> <...> [ evaluates to a collection ]<BR> <rdfq:Condition>...</rdfq:Condition><BR> </rdfq:quantifier><BR><BR></font></code></td></tr></table><p></P>
|
|
<P>
|
|
The <code>var</code> can be referenced in the condition body using <code>var-ref</code>.
|
|
In the following example, we want to pick from a set of researchers those that have at least one
|
|
publication in 1998. The first child element of the quantifier
|
|
searches for a property "ResearchPapers" and that returns a
|
|
collection. The predicate (second child element of the quantifier) is applied to each member in this
|
|
collection by referring to the member through <code>var-ref</code>. In the
|
|
example the predicate is applied to the "Year" property of the each
|
|
selected element. The predicate checks if the value is "1998". In
|
|
this simple example the <code>var</code> and <code>var-ref</code> may appear extraneous
|
|
but they are necessary to express nested queries and complex
|
|
conditions with quantification.
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><rdfq:rdfquery><BR> <rdfq:From eachResource="Almaden_Researchers"><BR> <rdfq:Select><BR> <rdfq:Condition><BR> <rdfq:Quantifier type="exists" var="x"><BR> <rdfq:Property path="ResearchPapers"/><BR> <rdfq:equals><BR> <rdfq:Property var-ref="x" name="Year"/><BR> <rdf:Integer>1998</rdf:Integer><BR> </rdfq:equals><BR> </rdfq:Condition> <BR> </rdfq:Quantifier> <BR> <rdfq:Condition><BR> </rdfq:Select><BR> </rdfq:From><BR></rdfq:rdfquery><BR></font></code></td></tr></table><p>
|
|
</P>
|
|
|
|
|
|
|
|
|
|
<H2><A NAME='Inference'>4. Vocabulary-Specific Inference</a></h2>
|
|
<P>RDF Query can be enriched by a number of vocabulary-specific
|
|
abbreviations and inferences. The use of <code>alias</code> for similar
|
|
resources in different containers has already
|
|
been discussed in "<A href='#Example8'>3.4 Complex conditions</A>".
|
|
Another vocabulary-specific abbreviation is a single name for a
|
|
chain of properties. For example "foreignPapers" may be used to
|
|
refer to the chain ResearchPapers/Conference/Venue/Country where
|
|
the value of the property is not <code>U.S.A</code>.</P>
|
|
<P>This is a fruitful area that needs more work.</P>
|
|
|
|
|
|
|
|
<H2><A NAME='DTD'>5. A DTD For RDF Query</a></h2>
|
|
<P>
|
|
</p><table cellpadding='5' border='1' bgcolor='#80ffff' width='100%'><tr><td><code><font><!ENTITY % setOps "(rdfq:Union | rdfq:Intersection | rdfq:Difference)"><BR><BR><!ELEMENT rdfq:rdfquery (%setOps; | rdfq:From)> <BR><BR><!ELEMENT rdfq:From (rdf:Bag? rdfq:Select? rdfq:Order? #PCDATA) ><BR><!ATTLIST rdfq:From<BR> eachResource HREF #IMPLIED> <BR><BR><!ELEMENT Select <BR> ( rdfq:Property | (rdfq:Condition, rdfq:Group? ) Select? ) ><BR><!ATTLIST Select<BR> properties NMTOKENS #IMPLIED><BR><BR><!ELEMENT rdfq:Property EMPTY><BR><!ATTLIST rdfq:Property<BR> resource HREF #IMPLIED<BR> name CDATA #IMPLIED<BR> path CDATA #IMPLIED [ one of name and path should be there ]<BR> var-ref NMTOKEN #IMPLIED<BR>><BR><BR><!ELEMENT rdfq:Condition (equals | greaterThan | lessThan |<BR>rdfq:Quantifier | ... ) ><BR><BR><!ELEMENT rdfq:Quantifier (rdfq:Property rdfq:Condition) ><BR><!ATTLIST rdfq:Quantifier <BR> type NMTOKEN #REQUIRED [ should be "exists" or "forAll" ]<BR> var NMTOKEN #IMPLIED><BR><!ELEMENT equals ANY><BR><!ELEMENT greaterThan ANY><BR><!ELEMENT lessThan ANY><BR> ...<BR><BR><!ELEMENT rdfq:Order (rdf:Seq | rdfq:Property)><BR><BR></font></code></td></tr></table><p>
|
|
</P>
|
|
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
|
|
<H2><A NAME='biblio'>6. References</a></h2>
|
|
<DL>
|
|
<dt><a name='KL1'>Brachman</a></dt><dd>
|
|
R.J. Brachman and J.G. Smolze, An Overview of the KL-ONE Knowledge
|
|
Representation System.<EM>Cognitive Science</EM>,
|
|
Vol. 9, No. 2, 1985, pp. 171-216
|
|
<dt><a name='Chen'>Chen</a></dt><dd>
|
|
P. P-S. Chen, The Entity-Relationship Model: Toward a Unified View of Data.
|
|
<EM>ACM Transactions on Database Systems</EM>, Vol. 1 No. 1 1973, pp. 9-36</DD>
|
|
</DD>
|
|
<dt><a name='Codd'>Codd</a></dt><dd>
|
|
E.F. Codd, A Relational Model of Data for Large Shared Data Banks.
|
|
<EM>Communications of the ACM</EM>, Vol. 13, No. 6, 1970, pp. 377-387
|
|
</DD>
|
|
<dt><a name='DCD'>DCD</a></dt><dd>
|
|
Document Content Description (DCD) Submission to W3C. See
|
|
<A HREF='http://www.w3.org/TR/NOTE-dcd'>http://www.w3.org/TR/NOTE-dcd</A>.
|
|
</DD>
|
|
<dt><a name='Findler'>Findler</a></dt><dd>
|
|
N.V. Findler (ed.), Associative Networks: Representation and Use of
|
|
Knowledge by Computers, N.Y. Academic, 1979.</DD>
|
|
<dt><a name='P3P'>P3P</a></dt><dd>
|
|
Platform for Privacy Preferences: P3P Project. See
|
|
<A HREF='http://www.w3.org/P3P'>http://www.w3.org/P3P</A>.
|
|
</DD>
|
|
<dt><a name='OQL'>OQL</a></dt><dd>
|
|
Object Query Language. See
|
|
The Object Database Standard, ODMG 2.0, R.G.G. Cattell (ed.),
|
|
Morgan Kaufmann, 1997.
|
|
</DD>
|
|
<dt><a name='SQL'>SQL</a></dt><dd>
|
|
SQL Standard. See
|
|
<A HREF='http://www.jcc.com/sql_stnd.html'>http://www.jcc.com/sql_stnd.html</A>.
|
|
</DD>
|
|
<dt><a name='RDF-Syntax'>RDF</a></dt><dd>
|
|
RDF Model and Syntax. See
|
|
<A HREF='http://www.w3.org/PICS/Member/NG/WD-rdf-syntax'>http://www.w3.org/PICS/Member/NG/WD-rdf-syntax</A>.
|
|
</DD>
|
|
<dt><a name='Unicode'>Unicode</a></dt><dd>
|
|
Unicode Standard. See "The Unicode Standard, Version 2.0", Reading
|
|
Mass., Addison-Wesley Developers Press, 1996
|
|
</DD>
|
|
<dt><a name='XML-Data'>XML-Data</a></dt><dd>
|
|
XML-Data. See
|
|
<A HREF='http://www.w3.org/TR/1998/NOTE-XML-data-0105/'>http://www.w3.org/TR/1998/NOTE-XML-data-0105/</A>.
|
|
</DD>
|
|
<dt><a name='XNames'>XML Namespaces</a></dt><dd>
|
|
Namespaces in XML.
|
|
See
|
|
<A HREF='http://www.w3.org/TR/WD-xml-names'>http://www.w3.org/TR/WD-xml-names</A>.
|
|
</DD>
|
|
<dt><a name='XQL'>XQL Proposal</a></dt><dd>
|
|
XQL Proposal from Microsoft.
|
|
</DD>
|
|
<dt><a name='jCentral'>jCentral</a></dt><dd>
|
|
See
|
|
<A HREF='http://www.ibm.com/java'>http://www.ibm.com/java</A>.
|
|
</DD>
|
|
</DL>
|
|
|
|
|
|
|