Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Chapter 3 A Semantic Web Primer1SPARQL Graph PracticeJeffrey PartykaTo try these queries yourself and see their results, import the class SimpsonsSPARQL into an Eclipse project. Then put simpsons.rdf at the top level of your project.3Query #1: Get all triplesPREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX simpsons: <http://www.simpsons.com/simpsons/> PREFIX ppl: <http://www.randompeople.com/ppl/> PREFIX job: <http://www.job.com/job/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?subj ?pred ?obj WHERE { ?subj ?pred ?obj . }4Query #2: Get all triples with simpsons:Homer as the subjectPREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX simpsons: <http://www.simpsons.com/simpsons/> PREFIX ppl: <http://www.randompeople.com/ppl/> PREFIX job: <http://www.job.com/job/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?pred ?obj WHERE { <simpsons:Homer> ?pred ?obj . }5Query #3: Get the surnames of all people that Bart knowsPREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX simpsons: <http://www.simpsons.com/simpsons/> PREFIX ppl: <http://www.randompeople.com/ppl/> PREFIX job: <http://www.job.com/job/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?surname WHERE { <simpsons:Bart> foaf:knows ?person . ?person foaf:surname ?surname . }6Query #4: Get all Simpsons characters with an age > 10PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX simpsons: <http://www.simpsons.com/simpsons/> PREFIX ppl: <http://www.randompeople.com/ppl/> PREFIX job: <http://www.job.com/job/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?person WHERE { ?person ppl:hasAge ?age . FILTER(xsd:integer(?age) > 10) }7Query #5: For each person that is of rdf:type foaf:Person, get their name and the school they attendPREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX simpsons: <http://www.simpsons.com/simpsons/> PREFIX ppl: <http://www.randompeople.com/ppl/> PREFIX job: <http://www.job.com/job/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?name ?school WHERE { ?person rdf:type <foaf:Person> ; foaf:name ?name ; ppl:attendsSchool ?school . }8Query #6: Get the names of Marge’s sisters (blank node practice)PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX simpsons: <http://www.simpsons.com/simpsons/> PREFIX ppl: <http://www.randompeople.com/ppl/> PREFIX job: <http://www.job.com/job/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?sisterName WHERE { <simpsons:Marge> ppl:hasSister ?bn . ?bn ?pred ?sister . ?sister foaf:name ?sisterName .
View Full Document