RE: A Comparison of RDF Query Languages

Hi,

Since you seemed to have skipped RDF Gateway in your testing, here's how
you'd handle your use cases in RDF Gateway's query language RDFQL. All
use cases are successfully handled.

The script can be run with the personal edition of RDF Gateway which is
available for free download from our site:

	http://www.intellidimension.com

--Geoff Chappell



========================================================================
===
import "/std/ns.rql";
import "/std/rdfs.rql";

session.namespaces["ex"] =
"http://www.aifb.uni-karlsruhe.de/WBS/pha/rdf-query/sample.rdf#";
session.namespaces["top"] =
"http://daml.umbc.edu/ontologies/topic-ont#";

var url =
"http://www.aifb.uni-karlsruhe.de/WBS/pha/rdf-query/queries/sample.rdf";

var ds = new datasource();
ds.insert(new datasource("inet?parsetype=rdf&url=" +
server.urlencode(url), session.namespaces["ex"]));


select ?p ?s ?o using #ds where {?p ?s ?o};


//1. Return the names of the authors of publication X.
select ?n using #ds where {[ex:author] [ex:Paper] ?a} and {?li ?a ?i}
and {[ex:name] ?i ?n};


//2. Return the name and, if known, the e-mail of the author of
publication X.
select ?n ?e using #ds where {[ex:author] [ex:Paper] ?a} and {?li ?a ?i}
and {[ex:name] ?i ?n}
	and switch(?i)
	(
		case {[ex:email] ?i ?em}:
			?e = ?em
		default:
			?e= ''
	);


//3.Return the labels of all topics that and (union) the titles of all
publications
select ?l using #ds rulebase rdfs where ({[rdf:type] ?s [top:Topic]} and
{[rdfs:label] ?s ?l})
		or
		({[rdf:type] ?s [ex:Publication]} and {[ex:title] ?s
?l})
		
//4.Return the labels of all topics that are not titles of publications.
select ?l using #ds rulebase rdfs where {[rdf:type] ?s [top:Topic]} and
{[rdfs:label] ?s ?l}
	and not ({[rdf:type] ?x [ex:Publication]} and {[ex:title] ?x
?l});


//5. Return the persons who are authors of all publications.
rulebase misc
{
	//just to make the query a little prettier
	infer author(?x, ?a) from {[ex:author] ?x ?l}
		and {?li ?l ?i} 
		and {[ex:name] ?i ?a};
}
select ?a using #ds rulebase rdfs, misc where author(?x, ?a)
		and {[rdf:type] ?pub [ex:Publication]}
		and groupby(?a) forall author(?pub, ?a)
		
//6.Count the number of authors of a publication.
select ?cnt using #ds rulebase rdfs where {[rdf:type] ?s
[ex:Publication]} 
		and {[ex:author] ?s ?l} 
		and {?li ?l ?i} 
		and {[ex:name] ?i ?n}
		and groupby(?s) (?cnt=count(?n));

//7.Return all subtopics of topic "Information Systems", recursively. 
rulebase misc
{
	infer {[top:SubTopic] ?c ?a} from {[top:SubTopic] ?c ?b} and
{[top:SubTopic] ?b ?a};
}

select ?s using #ds rulebase rdfs, misc where {[rdf:type] ?t
[top:Topic]}
	and {[rdfs:label] ?t 'Information Systems'@en}
	and {[top:SubTopic] ?t ?s};

//8. Return the person who has classified the publication X.
rulebase reify{
	infer {?c ?p ?s ?o} from {[rdf:subject] ?c ?s} and
{[rdf:predicate] ?c ?p} and {[rdf:object] ?c ?o};
}
select ?person using #ds rulebase reify where {?c [ex:isAbout]
[ex:Paper] ?o} and {[dc:creator] ?c ?person};		

//9.Return the first author of Publication X.
rulebase li
{
	infer li(?s, ?i, ?n) from {[rdf:type] ?s [rdf:Seq]} and {?p ?s
?i} and 
		integer(regexp(?p,
"http://www.w3.org/1999/02/22-rdf-syntax-ns#_([0-9]*)", 1)) = ?n;
}
select ?n using #ds rulebase li where {[ex:author] [ex:Paper] ?a} and
li(?a, ?i, 1) and {[ex:name] ?i ?n};


//10. Return all resources whose namespace starts with
"http://aifb.uni-karlsruhe.de/".
select ?s using #ds rulebase rdfs where {[rdf:type] ?s [rdfs:Resource]}
and instr(?s,"http://www.aifb.uni-karlsruhe.de/")=0 ;

//11. Return the German label of the topic whose English label is
"Database Management".
select ?l using #ds rulebase rdfs where {[rdf:type] ?t [top:Topic]}
	and {[rdfs:label] ?t 'Database Management'@en}
	and {[rdfs:label] ?t ?l} and lang(?l)='de'

//12. Return all publications where the page number is the lexical value
'08'.
select ?s using #ds where {[ex:pages] ?s ?p} and literal(?p)='08';

//13. Return all publications where the page number is the integer value
8. 
select ?s using #ds where {[ex:pages] ?s ?p} and integer(?p)=8;

//14. Return all instances of that are members of the class Publication.
select ?s using #ds rulebase rdfs where {[rdf:type] ?s
[ex:Publication]};



> -----Original Message-----
> From: www-rdf-interest-request@w3.org [mailto:www-rdf-interest-
> request@w3.org] On Behalf Of Andreas Eberhart
> Sent: Wednesday, April 28, 2004 12:16 PM
> To: daml-all@daml.org; ontoweb-list@www1-c703.uibk.ac.at; ontoweb-
> language-sig@cs.man.ac.uk; public-rdf-dawg@w3.org;
> semanticweb@yahoogroups.com; seweb-list@www1-c703.uibk.ac.at;
www-webont-
> wg@w3.org; www-rdf-interest@w3.org; www-rdf-logic@w3.org; www-rdf-
> rules@w3.org
> Cc: Raphael Volz; pha@aifb.uni-karlsruhe.de; jbroeks@cs.vu.nl
> Subject: A Comparison of RDF Query Languages
> 
> 
> 
> Related to the recent work of the RDF Data Access Working Group [1],
we
> have
> compared six proposals for RDF query languages. The report, the use
case
> data, and the queries are available online [2].
> 
> Looking forward to hearing your feedback.
> 
> Peter Haase, Andreas Eberhart, Raphael Volz, Institute AIFB,
University of
> Karlsruhe
> Jeen Broekstra, Vrije Universiteit Amsterdam
> 
> 
> [1] http://www.w3.org/2001/sw/DataAccess/
> [2] http://www.aifb.uni-karlsruhe.de/WBS/pha/rdf-query/

Received on Wednesday, 28 April 2004 18:39:16 UTC