Presentation is loading. Please wait.

Presentation is loading. Please wait.

SPARQL In-Class Shared Exercise. Pop Quiz If you have a large knowledge store, why should you not issue: SELECT ?s ?p ?o WHERE { ?s ?p ?o } Ans: It returns.

Similar presentations


Presentation on theme: "SPARQL In-Class Shared Exercise. Pop Quiz If you have a large knowledge store, why should you not issue: SELECT ?s ?p ?o WHERE { ?s ?p ?o } Ans: It returns."— Presentation transcript:

1 SPARQL In-Class Shared Exercise

2 Pop Quiz If you have a large knowledge store, why should you not issue: SELECT ?s ?p ?o WHERE { ?s ?p ?o } Ans: It returns the entire knowledge store (i.e. all triples)

3 Pop Quiz 1. How many triples? August 16, 1999 en Answer: 3

4 Pop Quiz 2. What is the query result? What is the query result: PREFIX dc: PREFIX ex: SELECT ?o WHERE { ?s dc:creator ?p. ?s ex:creation-date ?o } Answer: 3 o ? August 16, 1999

5 Pop Quiz 3. What is the query result? What is the query result: PREFIX dc: PREFIX ex: SELECT ?o WHERE { ?s dc:creator ?p. ?s ex:creation-date ?o. ?p dc:language “en” } Answer: 3 o ?

6 Ans: 7 Pop Quiz 1. How many triples?

7 Pop Quiz 2. What is the query result? What is the query result: PREFIX ex: PREFIX exv: PREFIX rdf: SELECT ?o WHERE { ?s a rdf:Bag. ?s2 exv:students ?s. { ?s rdf:_1 ?o. } UNION { ?s rdf:_2 ?o. } } o ? http://example.org/students/Amy http://example.org/students/Mohamed

8 Pop Quiz 2. What is the query result? What is the query result: PREFIX ex: PREFIX exv: PREFIX rdf: SELECT ?o WHERE { (?o2) rdf:first ?o. } o ? http://example.org/students/Johann Returns the last of every list in the knowledge store - > Not generally useful.

9 Pop Quiz 3. What is the query result? What is the query result: PREFIX ex: PREFIX exv: PREFIX rdf: SELECT ?o WHERE { ?s2 rdf:rest (?o2); rdf:first ?o. } o ? http://example.org/students/Mohamed Returns the next to last of every list in the knowledge store.

10 Exercise Preliminaries Have Gruff installed and working (item 3 of Lab 2) Get example rdf files (on eLearning Lecture 5 directory)

11 Start-up (Together) Start GRUFF Create a new triple store –Put somewhere convenient –Name it funtoday Use default estimate of size Load rdf files –Load one at a time ericMiller.rdf smallSet.rdf Display Both Graphs –Add->Display all triples

12 First SPARQL Switch to gruff Query view –View->Query view Create a query that returns all triples (using the SELECT construct) Run it - How many triples? –Shows at bottom just after query runs –Hit ‘Do Query’ again SELECT ?s ?p ?o WHERE { ?s ?p ?o. }

13 Sub-selection Return the objects and properties for ‘…Me’ –Windows help: Shift+LeftClick, then Ctrl-C can copy a field (Ctrl-V to paste) (See View menu for shortcuts) Run it - How many triples? SELECT ?p ?o WHERE { ?p ?o }

14 PREFIX Add a prefix statement for …Me –Call the prefix em –Change the where clause to use the prefix Run the query –How many triples –Same answer as before? PREFIX em: SELECT ?p ?o WHERE { em:me ?p ?o }

15 Classes Used Change the query to find all the classes being used in the knowledge store Did the query get to unique answers or was it just our store? SELECT ?o WHERE { ?s a ?o } or rdf:type for ‘a’ NOTE: rdf is predefined for you. Answer: Just our store. Can use DISTINCT SELECT DISTINCT ?o WHERE { ?s a ?o }

16 More Data Load more rdf files BagExample.rdf collectionExample.rdf Display all nodes –Arrange 6.001 and 6.002, each as top of a path (with some shared resources) –Make note of the types of nodes, which have class types, and names of property types. Especially that bag uses a type, list doesn’t

17 First Bag Item Write select query to return the ‘first’ bag item of class 6.001 down the students path. –Use the prefixes: PREFIX ex: PREFIX exv: PREFIX ex: PREFIX exv: SELECT ?o WHERE { ex:6.001 exv:students ?bn. ?bn rdf:_1 ?o}

18 Bag Iteration How do you change the query to get the next bag item? Answer: Change _1 to _2 -similar for all others until no return PREFIX ex: PREFIX exv: SELECT ?o WHERE { ex:6.001 exv:students ?bn. ?bn rdf:_2 ?o}

19 First List Item Change the query to return the ‘first’ list item of class 6.002 down the students path. –Use the prefixes: PREFIX ex: PREFIX exv: PREFIX ex: PREFIX exv: SELECT ?o WHERE { ex:6.002 exv:students ?bn. ?bn rdf:first ?o }

20 List Iteration How do you change the query to get the next list item? Answer: Extend the chain further down -You cannot use the blank node identifier in a new sparql query (per the specification). -You have to extend the chain more for each -rdf:nil return indicates end of list -this can be a fine structure for non-SPARQL graph access PREFIX ex: PREFIX exv: SELECT ?o WHERE { ex:6.002 exv:students ?bn. ?bn rdf:rest ?bn2. ?bn2 rdf:first ?o. } Last Gruff Example – remainder are verbal exercises

21 Explicit Inference My ontology says that zebra is a subclass of mammal. Modify the query below to implement the inference. SELECT ?o WHERE { ?s1 a mammal. ?s1 someProperty ?o } SELECT ?o WHERE { {?s1 a mammal} UNION {?s1 a zebra} ?s1 someProperty ?o } The Lesson: SPARQL can be automatically converted to accommodate subClassOf in an ontology.

22 Explicit Inference My ontology says that endsAtDateTime is a subproperty of endsAt. Modify the query below to implement the inference. SELECT ?o WHERE { ?s1 a event. ?s1 endsAt ?o } SELECT ?o WHERE { ?s1 a event. {?s1 endsAt ?o} UNION {?s1 endsAtDateTime ?o} } The Lesson: SPARQL can be automatically converted to accommodate subPropertyOf in an ontology.

23 Explicit Inference My ontology says the domain of property ‘teaches’ is class ‘person’. Modify the query below to implement the inference. SELECT ?o WHERE { ?s1 a person. ?s1 someProperty ?o } SELECT ?o WHERE { {?s1 a person} UNION {?s1 teaches ?junk} ?s1 someProperty ?o } The Lesson: SPARQL can be automatically converted to accommodate domain and range in an ontology.

24 Explicit Inference WARNING –Implementation of inference of complicated ontologies in SPARQL queries can easily make SPARQL queries unreasonably long to execute –There are limits to how much inference can be performed in a SPARQL SELECT It cannot perform inference over classes, properties, etc. found during the query (i.e. found as a variable like ?p)


Download ppt "SPARQL In-Class Shared Exercise. Pop Quiz If you have a large knowledge store, why should you not issue: SELECT ?s ?p ?o WHERE { ?s ?p ?o } Ans: It returns."

Similar presentations


Ads by Google