semantic web andrejs lesovskis. publishing on the web making information available without knowing...
TRANSCRIPT
![Page 1: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/1.jpg)
Semantic WebSemantic Web
Andrejs LesovskisAndrejs Lesovskis
![Page 2: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/2.jpg)
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;
. . .
![Page 3: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/3.jpg)
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
![Page 4: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/4.jpg)
SPARQL Protocol and RDF Query Language
![Page 5: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/5.jpg)
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.
![Page 6: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/6.jpg)
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?
![Page 7: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/7.jpg)
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.
![Page 8: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/8.jpg)
Anatomy of a SPARQL query
PREFIX foo: <…>PREFIX bar: <…>…SELECT …FROM <…>FROM NAMED <…>WHERE {
…}ORDER BY …LIMIT …OFFSET …
Declare prefixshortcuts (optional) Query result
clause
Triple patterns
Query modifiers(optional)
Define the dataset
(optional)
![Page 9: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/9.jpg)
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.
![Page 10: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/10.jpg)
SPARQL query forms
SELECT,
CONSTRUCT,
ASK,
DESCRIBE.
![Page 11: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/11.jpg)
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.
![Page 12: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/12.jpg)
SELECT query example
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dbpedia2: <http://dbpedia.org/property/>
SELECT ?presName, ?birthday, ?startDate
WHERE
{
?presName skos:subject
<http://dbpedia.org/resource/Category:Presidents _of_the_United_States>;
dbpedia2:birth ?birthday;
dbpedia2:presidentStart ?startDate.
}
![Page 13: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/13.jpg)
SELECT with OPTIONAL
![Page 14: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/14.jpg)
SELECT with multiple OPTIONAL
![Page 15: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/15.jpg)
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.
![Page 16: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/16.jpg)
CONSTRUCT example@prefix : <http://www.snee.com/ns/demo#> . :jane :hasParent :gene .
:gene :hasParent :pat ;
:gender :female .
:joan :hasParent :pat ;
:gender :female .
:pat :gender :male .
:mike :hasParent :joan .
![Page 17: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/17.jpg)
CONSTRUCT example (cont.)
PREFIX : <http://www.snee.com/ns/demo#>
CONSTRUCT { ?p :hasGrandfather ?g . }
WHERE { ?p :hasParent ?parent .?parent :hasParent ?g .?g :gender :male . }
![Page 18: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/18.jpg)
CONSTRUCT example (cont.)
@prefix : <http://www.snee.com/ns/demo#> .
:jane :hasGrandfather :pat .
:mike :hasGrandfather :pat .
![Page 19: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/19.jpg)
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.
![Page 20: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/20.jpg)
ASK query example
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" ._:a foaf:homepage <http://work.example.org/alice/> .
_:b foaf:name "Bob" ._:b foaf:mbox <mailto:[email protected]> .
PREFIX foaf: <http://xmlns.com/foaf/0.1/>ASK { ?x foaf:name "Alice" }
![Page 21: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/21.jpg)
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.
![Page 22: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/22.jpg)
PREFIX ent: <http://org.example.com/employees#>DESCRIBE ?x WHERE { ?x ent:employeeId "1234" }
@prefix foaf: <http://xmlns.com/foaf/0.1/> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0> .@prefix exOrg: <http://org.example.com/employees#> .@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.@prefix owl: <http://www.w3.org/2002/07/owl#>
_:a exOrg:employeeId "1234" ; foaf:mbox_sha1sum "ABCD1234" ; vcard:N [ vcard:Family "Smith" ; vcard:Given "John" ] .
foaf:mbox_sha1sum rdf:type owl:InverseFunctionalProperty .
![Page 23: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/23.jpg)
SPARQL query result formats
XML,
JSON (JavaScript Object Notation),
RDF,
HTML.
![Page 24: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/24.jpg)
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.
![Page 25: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/25.jpg)
JavaScript Object Notation{ "firstName": "John", "lastName" : "Smith", "age" : 25, "address" : { "streetAddress": "21 2nd Street", "city" : "New York", "state" : "NY", "postalCode" : "10021" }, … }
![Page 26: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/26.jpg)
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 rdf:type
movie:genre
movie:genre
movie:Role
“Edward ScissorHands”
r1
actor1movie:playedBy
movie:characterName
rdf:type
movie:hasPart
![Page 27: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/27.jpg)
Example Query 1Select the movies that has a character called “Edward Scissorhands”
PREFIX movie: <http://example.org/movies/>
SELECT DISTINCT ?x ?t
WHERE {
?x movie:title ?t ;
movie:hasPart ?y .
?y movie:characterName ?z .
FILTER (?z = “Edward Scissorhands”@en)
}
![Page 28: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/28.jpg)
Example Query 1PREFIX movie: <http://example.org/movies/>
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
![Page 29: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/29.jpg)
Example Query 2Create a graph of actors and relate them to the movies they play in (through a new ‘playsInMovie’ relation).
PREFIX movie: <http://example.org/movies/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>
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.
}
![Page 30: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/30.jpg)
Example Query 3
Find all movies which share at least one genre with “Gone with the Wind”
PREFIX movie: <http://example.org/movies/>
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)
}
![Page 31: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/31.jpg)
31
SPARQL and reasoningOWL, RDFS, application, rules
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>SELECT ?typeWHERE{ ?x rdf:type ?type .}
:x rdf:type :C .:C rdfs:subClassOf :D .
--------| type |========| :C || :D |--------
![Page 32: Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbc5503460f94aadfe6/html5/thumbnails/32.jpg)
Thank you!Thank you!