SPARQL Exercise Most of this exercise has been copied from: INF3580/INF4580 – MANDATORY EXERCISE 3 http://www.uio.no/studier/emner/matnat/ifi/INF3580/v15/undervisningsmateriale/oblig3.pdf
Copy the Turtle defined ontology on next slide to an ” Copy the Turtle defined ontology on next slide to an ”.owl” file and load it into Protégé.
@prefix : <http://www. simpsons. no/simpsonsfamily#> @prefix : <http://www.simpsons.no/simpsonsfamily#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix xml: <http://www.w3.org/XML/1998/namespace> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . <http://www.simpsons.no/simpsonsfamily> rdf:type owl:Ontology . ################################################################# # # Object Properties :hasBrother rdf:type owl:ObjectProperty . :hasParent rdf:type owl:ObjectProperty . :hasSister rdf:type owl:ObjectProperty . :hasUncle rdf:type owl:ObjectProperty . :hasFamilyMember rdf:type owl:ObjectProperty . :hasSpouse rdf:type owl:ObjectProperty . :hasFather rdf:type owl:ObjectProperty . :hasMother rdf:type owl:ObjectProperty . # Data properties :birthday rdf:type owl:DatatypeProperty ; rdfs:range xsd:dateTime . :diedOn rdf:type owl:DatatypeProperty ; :hasName rdf:type owl:DatatypeProperty ; rdfs:range xsd:string . # Classes :Family rdf:type owl:Class . :Man rdf:type owl:Class ; rdfs:subClassOf foaf:Person . :Woman rdf:type owl:Class ; #################################################################### :Homer a foaf:Person ; foaf:age "36"^^xsd:int ; foaf:name "Homer Simpson" . :Marge foaf:age "34"^^xsd:int ; foaf:name "Marge Simpson" . :Lisa foaf:age "8"^^xsd:int ; foaf:name "Lisa Simpson" . :Bart foaf:age "10"^^xsd:int ; foaf:name "Bart Simpson" . :Maggie foaf:age "1"^^xsd:int ; foaf:name "Maggie Simpson" . :Simpsons a :Family ; :hasFamilyMember :Maggie , :Homer , :Lisa , :Bart, :Marge . :hasSpouse :Marge . :hasSpouse :Homer . :hasFather :Homer ; :hasMother :Marge . :Abraham a foaf:Person . :hasParent [ a foaf:Person ; :hasFather :Abraham ] . :Mona a foaf:Person . :hasMother :Mona :hasSister :Patty , :Selma ] ; :hasBrother :Herb :Herb a foaf:Person . :Patty a foaf:Person ; :hasSister :Selma . :Selma :hasSister :Patty . :hasSpouse
Task 1 Query: Find all Persons and order them by identifier, list also optionally their name. Use the result variable names ?person, ?name . Tip: This is a simple query, where you will need to use SELECT, WHERE, OPTIONAL and ORDER BY . If you do not get any results, try the query SELECT ?s ?p ?o WHERE {?s ?p ?o} and see if your get the expected results and namespaces. This query lists all triples in the graph.
Task 2 Query: Find everyone who has a mother and list both the person and the mother. Order by mother.
Task 3 Query: Find everyone who has a mother or a father and list both the person and the mother or father. Order by mother/father.
Task 4 Query: Find all of Maggie’s grandmothers. Result variable name: ?grandmother .
Task 5 Query: Find everyone older than 10. Order by age, oldest first. Output name and age. Result variable names: ?person, ?age .
Task 6 Query: Is Herb the brother of Homer? (We know Homer has a brother named Herb, but here the question is: Do the ontology contain this information?) Tip: Use ASK .