120 likes | 222 Views
RDF Query language. The following slides are from Grigoris Antoniou, Frank van Harmelen, “A Semantic Web Primer” Dean Allemang, Jim Hendler, “Semantic Web for the working ontologist”. Lecture outline. Ontology Syntax of RDF and RDFS Basic Ideas of RDF Three representations of RDF
E N D
RDF Query language The following slides are from Grigoris Antoniou, Frank van Harmelen, “A Semantic Web Primer” Dean Allemang, Jim Hendler, “Semantic Web for the working ontologist”
Lecture outline • Ontology • Syntax of RDF and RDFS • Basic Ideas of RDF • Three representations of RDF • Basic Concepts of RDF Schema • Τhe Language of RDF Schema • Axiomatic Semantics for RDF and RDFS • Applications of RDF and RDFS • Querying of RDF/RDFS Documents The following slides are from Grigoris Antoniou, Frank van Harmelen, “A Semantic Web Primer”
Why RDF Query language—different XML representation • There are XML query languages, such as XQuery • XML at a lower level of abstraction than RDF • There are various ways of syntactically representing an RDF statement in XML • Thus we would require several XQuery queries, e.g. • //uni:lecturer/uni:title if uni:title is an element • //uni:lecturer/@uni:title if uni:title is an attribute • Both XML representations equivalent!
Why RDF Query—understanding semantics <uni:lecturer rdf:ID="949352"> <uni:name>Grigoris Antoniou</uni:name> </uni:lecturer> <uni:professor rdf:ID="949318"> <uni:name>David Billington</uni:name> </uni:professor> <rdfs:Class rdf:about="#professor"> <rdfs:subClassOf rdf:resource="#lecturer"/> </rdfs:Class> • A query for the names of all lecturers should return both Grigoris Antoniou and David Billington
RDF query languages • All have a SQL like syntax • SPARQL • became W3C recommendation in 2008. • RQL • …
Using select-from-where • As in SQL • SELECT: specifies the projection operation, i.e., the number and order of retrieved data • FROM: specifies the data source from which to query; it is optional. • WHERE: imposes constraints on possible solutions • Retrieve all phone numbers of staff members: SELECT ?X ?Y WHERE {?X phone ?Y. } • Here X and Y are variables, and ?X phone ?Y represents a resource-property-value triple
Retrieve all lecturers and their phone numbers: SELECT ?X ?Y WHERE {?X rdf:type lecturer. ?X phone ?Y. } SELECT ?X ?Y WHERE {?X rdf:type lecturer; phone ?Y. }
Triple representation lit:Shakespeare lit:wrote lit:AsYouLikeIt; lit:wrote lit:Twel fthNight; lit:wrote lit:KingLear; lit:wrote lit:LovesLaboursLost ; lit:wrote lit:Hamlet; lit:wrote lit:TheTempest; lit:wrote lit:WintersTale; lit:wrote lit:HenryV; lit:wrote lit:MeasureForMeasure; lit:wrote lit:Othello; bio: livedIn geo: Stratford. bio: AnneHathaway bio: married lit:Shakespeare. geo: Stratford geo:isIn geo:England. geo: Scotland geo:partOf geo:UK. geo: England geo:partOf geo:UK. geo: Wales geo:partOf geo:UK. geo: NorthernIreland geo: partOf geo:UK. geo: ChannelIslands geo: part Of geo: UK. geo: IsleOfMan geo: partOf geo: UK.
Triple pattern • Triple pattern is the basic building block of SPARQL • Similar to triple • Can have variables in place of resources • Same variable indicates the same resource ?wlit:wrotelit:KingLear. lit:Shakespeare ?rlit:KingLear. lit:Shakespearelit:wrote ?p. • Who wrote KingLear? • What relationship did Shakespeare have to KingLear? • What did Shakespeare write?
Graph pattern • List of triple pattern enclosed in braces {?person bio: livedIn ?place. ?place geo: isIn geo:England. ?person lit:wrote lit:KingLear. } • Result ?person=Shakespeare ?place=Stratford
{?person bio:married ?s . ?person lit:wrote lit:KingLear. } Result No result Solution bio:married owl:inverseOf bio:married . Another solution { {{?spouse1 bio:married ?spouse2} UNION { ?spouse2 bio:married ?spouse1} } { ?spouse1 lit:wrote lit:KingLear} } Graph pattern
There are SPARQL query interfaces, e.g., • http://dbpedia.org/sparql • You can query dbpedia, e.g., select ?person where {?person <http://www.w3.org/2000/01/rdf-schema#label> "Steve"@en } • The result is • person • http://dbpedia.org/resource/Steve • http://dbpedia.org/class/yago/SteveMcMichael • http://dbpedia.org/class/yago/Steve,TheFirst • …