Presentation is loading. Please wait.

Presentation is loading. Please wait.

Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction.

Similar presentations


Presentation on theme: "Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction."— Presentation transcript:

1 Semantic Web Andrejs Lesovskis

2 Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction of results. Also, there are: Economic issues; DRM, copyright and licensing issues;...

3 3 Publishing on the Semantic Web  SPARQL  OWL, RDFS, SKOS  RDF  URIs  XML Data Access Information organisation Information format Identification Serialization Publishing via a query service on the web

4 SPARQL Protocol and RDF Query Language

5 What is SPARQL? SPARQL is the query language of the Semantic Web, stays for SPARQL Protocol and RDF Query Language. SPARQL 1.1 Protocol became a W3C recommendation on March 21, 2013. This protocol was developed by the W3C SPARQL Working Group, part of the Semantic Web Activity.

6 Motivation Having RDF data available is not enough Need tools to process, transform, and reason with the information Need a way to store the RDF data and interact with it Are existing storage systems appropriate to store RDF data? Are existing query languages appropriate to query RDF data?

7 Why SPARQL? SPARQL allows to: Pull values from structured and semi- structured data represented in RDF; Explore RDF data by querying unknown relationships; Perform complex joins of disparate RDF repositories in a single query; Transform RDF data from one vocabulary to another; Develop higher-level cross-platform application.

8 Anatomy of a SPARQL query

9 Basic patterns A basic pattern is a set of triple patterns, all of which must be matched. In this case matches the graph means find a set of bindings such that the substitution of variables for values creates a subgraph that is in the set of triples making up the graph.

10 SPARQL query forms SELECT, CONSTRUCT, ASK, DESCRIBE.

11 SELECT query SPARQL’ SELECT is rather similar to SELECT from SQL. The SELECT form of results returns variables and their bindings directly. It combines the operations of projecting the required variables with introducing new variable bindings into a query solution.

12 SELECT query example PREFIX skos: PREFIX dbpedia2: SELECT ?presName, ?birthday, ?startDate WHERE { ?presName skos:subject ; dbpedia2:birth ?birthday; dbpedia2:presidentStart ?startDate. }

13 SELECT with OPTIONAL

14 SELECT with multiple OPTIONAL

15 CONSTRUCT query The CONSTRUCT query form returns a single RDF graph specified by a graph template. The result is an RDF graph formed by taking each query solution in the solution sequence, substituting for the variables in the graph template, and combining the triples into a single RDF graph by set union.

16 CONSTRUCT example @prefix :. :jane :hasParent :gene. :gene :hasParent :pat ; :gender :female. :joan :hasParent :pat ; :gender :female. :pat :gender :male. :mike :hasParent :joan.

17 CONSTRUCT example (cont.) PREFIX : CONSTRUCT { ?p :hasGrandfather ?g. } WHERE { ?p :hasParent ?parent. ?parent :hasParent ?g. ?g :gender :male.}

18 CONSTRUCT example (cont.) @prefix :. :jane :hasGrandfather :pat. :mike :hasGrandfather :pat.

19 ASK query Applications can use the ASK form to test whether or not a query pattern has a solution. No information is returned about the possible query solutions, just whether or not a solution exists.

20 ASK query example @prefix foaf:. _:a foaf:name "Alice". _:a foaf:homepage. _:b foaf:name "Bob". _:b foaf:mbox. PREFIX foaf: ASK { ?x foaf:name "Alice" }

21 DESCRIBE query The DESCRIBE form returns a single result RDF graph containing RDF data about resources. This data is not prescribed by a SPARQL query, where the query client would need to know the structure of the RDF in the data source, but, instead, is determined by the SPARQL query processor. Some SPARQL endpoint don’t support this type of queries.

22 PREFIX ent: DESCRIBE ?x WHERE { ?x ent:employeeId "1234" } @prefix foaf:. @prefix vcard:. @prefix exOrg:. @prefix rdf:. @prefix owl: _:a exOrg:employeeId "1234" ; foaf:mbox_sha1sum "ABCD1234" ; vcard:N [ vcard:Family "Smith" ; vcard:Given "John" ]. foaf:mbox_sha1sum rdf:type owl:InverseFunctionalProperty.

23 SPARQL query result formats XML, JSON (JavaScript Object Notation), RDF, HTML.

24 JavaScript Object Notation JSON (JavaScript Object Notation) is a text-based, lightweight data- interchange format. It's easy to read and write for humans and to parse and generate for machines. JSON was originally specified by Douglas Crockford, and is described in RFC 4627.

25 JavaScript Object Notation { "firstName": "John", "lastName" : "Smith", "age" : 25, "address" : { "streetAddress": "21 2nd Street", "city" : "New York", "state" : "NY", "postalCode" : "10021" }, … }

26 A RDF Graph Modeling Movies movie1 movie:Movie “Edward ScissorHands” “1990” rdf:type movie:title movie:year movie:Genre movie:Romance movie:Comedy rdf:type movie:genre movie:Role “Edward ScissorHands” r1 actor1 movie:playedBy movie:characterName rdf:type movie:hasPart

27 Example Query 1 Select the movies that has a character called “Edward Scissorhands” PREFIX movie: SELECT DISTINCT ?x ?t WHERE { ?x movie:title ?t ; movie:hasPart ?y. ?y movie:characterName ?z. FILTER (?z = “Edward Scissorhands”@en) }

28 Example Query 1 PREFIX movie: SELECT DISTINCT ?x ?t WHERE { ?x movie:title ?t ; movie:hasPart ?y. ?y movie:characterName ?z. FILTER (?z = “Edward Scissorhands”@en) } Note the use of “;” This allows to create triples referring to the previous triple pattern (extended version would be ?x movie:hasPart ?y) Note as well the use of the language speciation in the filter @en

29 Example Query 2 Create a graph of actors and relate them to the movies they play in (through a new ‘playsInMovie’ relation). PREFIX movie: PREFIX foaf: CONSTRUCT { ?x foaf:firstName ?fname. ?x foaf:lastName ?lname. ?x movie:playInMovie ?m } WHERE { ?m movie:title ?t ; movie:hasPart ?y. ?y movie:playedBy ?x. ?x foaf:firstName ?fname. ?x foaf:lastName ?lname. }

30 Example Query 3 Find all movies which share at least one genre with “Gone with the Wind” PREFIX movie: SELECT DISTINCT ?x2 ?t2 WHERE { ?x1 movie:title ?t1. ?x1 movie:genre ?g1. ?x2 movie:genre ?g2. ?x2 movie:title ?t2. FILTER (?t1 = “Gone with the Wind”@en && ?x1!=?x2 && ?g1=?g2) }

31 31 SPARQL and reasoning OWL, RDFS, application, rules PREFIX rdf: SELECT ?type WHERE { ?x rdf:type ?type. } :x rdf:type :C. :C rdfs:subClassOf :D. -------- | type | ======== | :C | | :D | --------

32 Thank you!


Download ppt "Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction."

Similar presentations


Ads by Google