Semantic Web technologies - Jyväskylän...

51
UNIVERSITY OF JYVÄSKYLÄ Semantic Web technologies Summary University of Jyväskylä Khriyenko Oleksiy

Transcript of Semantic Web technologies - Jyväskylän...

Page 1: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Semantic Web technologies

Summary

University of Jyväskylä Khriyenko Oleksiy

Page 2: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Semantic Web vision

� Solution– Let’s produce Web data in a form that is easy to

“digest” by a machine without losing good propertiesof WWW

� How?– Switch: informal representation => formal model– Connect information, but stay consistent– Distribute information (no central repository)

2

I am enjoying about learning and using new technology…

� Semantics– Relation between signs, words, symbols and the

things (documents, people, places, events,organizations, concepts, etc.) to which they refer.

– Relation of the things to each other.

Syntax:

Semantics:

I technologyI love technology____

Web

Semantic Web

RDF

RDF

RDF

RDF

From decentralized platform for

distributed presentationstowards decentralized platform for

distributed knowledge

20/03/2019 TIES4520

Page 3: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Computer symbols

Disambiguity of data (1)

3

Ideas Human symbols

mouse

cry

mouse1

mouse2

cry1

cry2

bank 1

bank 2bank

20/03/2019 TIES4520

Page 4: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Disambiguity of data (2)

� Disambiguity of referencing to things:– Example: mouse, windows, cry, …– Every thing should have its unique name– Solution: URIs (Uniform Resource Identifiers)

� Disambiguity of concepts– Example:

• John is attracted to Mary. • North pole is attracted to south pole.

– There has to be some common understanding of the domain inquestion

– Solution: Ontology – a precise explanation of terms and reasoning ina subject area.

420/03/2019 TIES4520

Page 5: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Open world assumption

� Any information can come at any point in the future� We never know everything about the world. There can be true

facts that are not contained in the knowledge base

5

Open world Closed world

Data Helsinki and Tampere are in Finland.Paris is not in Finland.

Q1 Is Helsinki in Finland?

A1 YES YES

Q2 Is Paris in Finland?

A2 NO NO

Q3 Is Jyväskylä in Finland?

A3 I don’t know NO

20/03/2019 TIES4520

Page 6: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Half way summary

� Semantic Webo Anybody can express data about anything and connect it to anythingo Data is readable and manipulated by machines

6

� Problemso Disambiguity of data =>

URIs + ontologies

� Propertieso Non-unique Naming

Assumptiono Open World Assumption

20/03/2019 TIES4520

Page 7: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Namespaces

� Problem:– In one document you have these URIs:

• http://www.jyu.fi/people/students/john/assignments/assignment1• http://www.jyu.fi/people/students/john/assignments/assignment2• http://www.jyu.fi/people/students/john/assignments/assignment3

– Too long representation

7

� Solution:– Introduce a namespace as a prefix of the short (qualified name):Full name: http://www.jyu.fi/people/students/john/assignments/assignment1

– Use qualified names (qnames):• as:assignment1• as:assignment2• as:assignment3

� Benefits:– Improved readability– Saves space

Prefix (for example as:) Rest of the name

20/03/2019 TIES4520

Page 8: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

RDF (Resource Description Framework)

� RDF is a general method to decompose knowledge into small pieces with rulesabout the meaning of those pieces. It is a method to describe facts in a short form.

8

ID Firstname Surname City

145 Albert Einstein NY

626 Marie Currie LA

California

State

USACountry

Person-145

Albert

Firstname

Einstein

NY145ID

Surname

City

Marie Currie

LA626

Person-626

ID

Firstname

Surname

City

� RDF represents graphs

� Everything is a Resource– Anything that we can talk about and

has identity in a form of URI.– Example: human, building, weather

20/03/2019 TIES4520

Page 9: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

RDF as graph, RDF as text

9

AlbertEinstein

c:NY

145

p:per145

f:hasID

f:hasFirstname

f:hasSurname

f:livesIn

p:per145 f:hasID “145” . p:per145 f:hasFirstName “Albert” . p:per145 f:hasSurname “Einstein” . p:per145 f:livesIn c:NY .

All the data in RDF is described in statements/triples:subject – predicate – object

20/03/2019 TIES4520

Page 10: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Graph matching and merging

10

Albert Einstein

c:NY

145

p:per145

f:hasID

f:hasFirstname

f:hasSurname

f:livesIn

The Big Apple

s:NY

8 175 133

c:NY

c:citizens

c:nickname

c:state

Albert Einstein

145

p:per145

f:hasID

f:hasFirstname

f:hasSurname

f:livesIn

The Big Apple

s:NY

8 175 133

c:NY

c:citizens

c:nickname

c:state

c:NY

f:livesIn

20/03/2019 TIES4520

Page 11: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Serialization

� The way of representing the graph in textual form� Serializations (notations):

– RDF/XML

– TriX– N-triples– Turtle (Terse RDF Triple Language)– Notation 3

1120/03/2019 TIES4520

Page 12: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

RDF/XML

� Suitable for machines� Many XML parsers exist� Difficult for humans to see subject-predicate-object triples

12

<rdf:RDFxmlns="http://data.gov/ontology/edu#" xmlns:log="http://www.w3.org/2000/10/swap/log#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax- ns#">

<rdf:Description rdf:about=" http://www.jyu.fi/courses/TIES4520 "><credits >5</ credits >

</rdf:Description> <rdf:Description rdf:about=" http://www.jyu.fi/people/Mary ">

<studies rdf:resource=" http://www.jyu.fi/courses/TIES4520 "/> <livesIn xmlns="http://data.gov/ontology/urban#"

rdf:resource=" http://www.geo.com/city/Turku "/> </rdf:Description>

</rdf:RDF>

20/03/2019 TIES4520

Page 13: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

N-triples

� Simple textual serialization of RDF statements� Each statement consists of subject, predicate and object

separated by a white space� Statements are separated by dots (.)� Resources are referred to with full URIs in <> brackets� Literals are wrapped into double quotes (“ ” )

13

<http://www.jyu.fi/people/Mary> <http://data.gov/ontology/urban#livesIn> <http://www.geo.com/city/Turku> .

<http://www.jyu.fi/people/Mary> <http://data.gov/ontology/edu# studies > <http://www.jyu.fi/courses/TIES4520> .

<http://www.jyu.fi/courses/TIES4520> <http://data.gov/ontology/edu#credits> “5” .

20/03/2019 TIES4520

Page 14: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Turtle (1)

� Turtle is similar to N-triples, but even more compact

� Uses @prefix to define the prefix and later on use justqualified names (e.g. fam:John)

� Abbreviated form of triples with semantic sugar:– Semicolon (;) to separate statements about the same subject

– Comma (,) to separate statements about the same subjectwith the same predicate

� And more features: http://www.w3.org/TeamSubmission/turtle/

http://www.w3.org/TR/turtle/

14

x:Mary x:hasAge “25” ; x:gender x:female ; x:likes x:chocolate .

x:Mary x:likes x:chocolate , x:cheese , x:bread .

@prefix p: <http://www.jyu.fi/people/> .@prefix u: <http://data.gov/ontology/urban#> .

p:Mary u:hasAge “25” .

20/03/2019 TIES4520

Page 15: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Turtle (2)

� Same example as before:

15

@prefix p: <http://www.jyu.fi/people/> .@prefix u: <http://data.gov/ontology/urban#> .@prefix edu: <http://data.gov/ontology/edu#> .@prefix co: <http://www.jyu.fi/courses/> .@prefix ci: <http://www.geo.com/city/> .

p:Mary u:livesIn ci:Turku .p:Mary edu:studies co:TIES4520 .co:TIES4520 edu:credits “5” .

p:Mary u:livesIn ci:Turku ; edu:studies co:TIES4520 .co:TIES4520 edu:credits “5” .

<http://www.jyu.fi/people/Mary> <http://data.gov/ontology/urban#livesIn> <http://www.geo.com/city/Turku> .

<http://www.jyu.fi/people/Mary> <http://data.gov/ontology/edu# studies > <http://www.jyu.fi/courses/TIES4520> .

<http://www.jyu.fi/courses/TIES4520> <http://data.gov/ontology/edu#credits> “5” .

20/03/2019 TIES4520

Page 16: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Notation 3

� Notation 3 (superset of Turtle) is the most important RDFnotation, most clearly captures the abstract graph.

� Introduces formula { … }– E.g. to make statements about statements

� New logic-related predicates (e.g. =>, @forSome, etc.)� Variables allowed (?varName)� Suffix: *.n3� Relationship to other notations:

16

N-triples Turtle N3

20/03/2019 TIES4520

Page 17: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Three rules of RDF

1. Every fact is expressed as a triple (subject, predicate, object)2. Subjects, predicates and objects are names for entities represented as

URIs3. Objects can be literal values as well (subjects and predicates are not!!! )

17

<urn:isbn:1-12-456789-0> <http://www.jyu.fi/library#hasAuthor> “John” .

Subject

(URI)

Predicate

(URI)

Object

(URI or Literal value)

c:TIES4520 co:hasLecture lec:Lecture1 .

c:TIES4520 co:hasCode “TIES4520” .

p:per673 fam:hasSurname “Doe” .

“John” fam:hasAge “25” .

20/03/2019 TIES4520

Page 18: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Literals: DatatypeLiteral values are raw text that can be usedinstead of objects in RDF triples.

� Datatype literal represents non-string values

(e.g. boolean, numbers, date or time, etc.) with

datatype that indicates how to interpret the rawtext.

– Lexical form of the literal + URI of thedatatype (datatypes defined in XML Schema are used byconvention: xsd:integer, xsd:decimal, xsd:float, xsd:double,xsd:string, xsd:boolean, xsd:dateTime, etc. ).

18

“1234” .

“1234” ^^xsd:integer .

“1234” ^^<http://www.w3.org/2001/XMLSchema#integer> .

An untyped literal value. No datatype.

A typed literal value using a namespace.

The same with the full datatype URI.

:jone :age “10” ^^xsd:float . :jone :age “10.000” ^^xsd:float . is the same as

:jone :age “10” . :jone :age “10.000” ^^xsd:float . is not the same as

Important:

:jone :taxesPayed “true” . :jone :taxesPayed “true” ^^xsd:boolean . is not the same as

20/03/2019 TIES4520

Page 19: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

� Making statement about a statement or more statements

� Used to represent the context

� Example: Bill thinks that John loves Mary

p:Bill cog:thinks

Reification problem

19

p:John f:loves p:Mary

20/03/2019 TIES4520

Page 20: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Solutions to reification

� Referring to the statement as a resource:

20

p:Bill cog:thinks s:st1 .s:st1 rdf:type rdf:Statement .s:st1 rdf:subject p:John . s:st1 rdf:predicate f:loves . s:st1 rdf:object p:Mary .

valid in Turtlevalid in Notation3

� Using special context brackets:p:Bill cog:thinks { p:John f:loves p:Mary } .

not valid in Turtlevalid in Notation3

20/03/2019 TIES4520

Page 21: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Blank nodes

� When we want to annotate a resource whose identity is unknown we use blank node.

� Example: Larry has a fast red car.

21

p:Larry p:owns ? .? rdf:type v:Car; v:color c:red; v:speed s:fast .

p:Larry p:owns _:xe46na54an ._:xe46na54an rdf:type v:Car

; v:color c:red; v:speed s:fast .

Use a blank node identifier (_:name ),that allows the same blank node to bereferred to in more then one place:

p:Larry p:owns [rdf:type v:Car; v:color c:red; v:speed s:fast . ] .

Use abbreviation ([ ] ) foranonymous blank node, if there isno need to reuse the blank node:

20/03/2019 TIES4520

Page 22: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Turtle abbreviations

� @prefix – abbreviation for prefix definition

� a – abbreviation for the property<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>

� , – is used to repeat the subject and the predicate of triples that onlydiffer in the object

� ; – is used to repeat the subject of triples that vary in the predicate andthe object

� [ ] – abbreviation for the blank node

� ( ) – abbreviation for RDF Collection (structure for lists of RDF nodes)

22

@prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

p:Larry <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> p:Human .p:Larry rdf:type p:Human .p:Larry a p:Human .

p:Larry p:owns v:Car , v:bike .

p:Larry a p:Human ; p:owns v:Car .

p:Larry p:owns [ rdf:type v:Car ; v:color c:red ; v:speed s:fast . ] .

cd:Beatles cd:artist ( b:George b:John b:Paul b:Ringo ) .

20/03/2019 TIES4520

Page 23: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Manipulation of RDF data

� Storing– RDF file on the web– Specialized RDF storage (“RDF database”)– Other form (*.xls, DB, …) exposed as RDF

� Querying– Like in relational DB there is a query language (SPARQL)– Can query from several sources (web sources, local RDF storages,

etc.)

� Reasoning– Can derive new facts from already existing facts– Can check consistency of the model– Does not exist in relational DB !!!

2320/03/2019 TIES4520

Page 24: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Storing of RDF

� Small datasets (few triples)– RDF file published on the web or stored locally– Examples: *.rdf , *.nt , *.ttl , *.n3 , etc.

� Large datasets (thousands to millions of triples)– Database-bases solution better– Usually in form of RDF storage

� Legacy data– Keep in original form– Provide mapping to RDF– Expose as RDF to the outer world

Triplestore: http://en.wikipedia.org/wiki/TriplestoreGraph databases: https://en.wikipedia.org/wiki/Graph_databaseList of triplestores: http://www.w3.org/wiki/LargeTripleStores

2420/03/2019 TIES4520

Page 25: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

RDF4J

DRF4J (former Sesame) an open source Java framework forprocessing RDF data. Link: http://rdf4j.org/

� Features:– Parsing: Supports all major notations

– Storing: In-memory, native store, file-based, and supports many third party storage solutions (http://rdf4j.org/about/rdf4j-databases/)

– Inferencing: Ontology-based, custom Rule-based

– Querying: SPARQL, SeRQL

� easy-to-use API that can be connected to all leading RDF storage solutions.

AliBaba is an RDF application library for developing complex RDF storage applications. It is a collection of modules that provide simplified RDF store abstractions to accelerate development and facilitate application maintenance. Link: https://bitbucket.org/openrdf/alibaba

2520/03/2019 TIES4520

Page 26: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

GraphDB

Otnotext GraphDB (formerly OWLIM) is a leading RDF Triplestore built on OWL(Ontology Web Language) standards. GraphDB handles massive loads, queries and OWLinferencing in real time. There are three different editions: GraphDB Free, GraphDB Standard andGraphDB Enterprise. Link: http://ontotext.com/products/graphdb/, http://graphdb.ontotext.com/

� Features:– Parsing: Supports all major notations

– Storing: file-based native store

– Inferencing: at load time, Ontology-based, custom Rule-based

– Querying: SPARQL, supports HTTP based querying

� GraphDB Server: a set of programming interfaces that exposes all database functionality as a REST API.

� GraphDB Workbench: management interfaces implemented on top of the GraphDB Server REST API.

� Fully compliant with the RDF4J (Sesame) service API� GraphDB on the Cloud: database as a service solution for small or medium database size

and query load. (https://console.s4.ontotext.com/#/home)

� Tools: LoadRDF tool: an OFFLINE tool, designed for fast loading of large data sets. (http://graphdb.ontotext.com/documentation/free/loadrdf-tool.html)

Storage tool: an application for scanning and repairing a GraphDB repository. (http://graphdb.ontotext.com/documentation/free/storage-tool.html)

2620/03/2019 TIES4520

Page 27: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Apache Jena Fuseki

� Fuseki provides REST-style interaction with RDF data. It is aSPARQL server that provides REST-style SPARQL HTTP Update,SPARQL Query, and SPARQL Update using the SPARQL protocol overHTTP.

� Installation:1. Download (http://jena.apache.org/download/ or from course webpage) and

unzip Fuseki2. Start server from Fuseki folder by running:

3. Open http://localhost:3030/4. Documentation: http://jena.apache.org/documentation/fuseki2/

http://jena.apache.org/documentation/serving_data

27

fuseki-server --update --mem /ds

practical

fuseki-server --update --loc=c:/dir… /ds

20/03/2019 TIES4520

Page 28: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

SPARQL: General Form

� SPARQL queries take the following general form

28

PREFIX (Namespace Prefixes)e.g. PREFIX f: <http://example.org#>

SELECT (Result Set)e.g. SELECT ?age

FROM and FROM NAMED(Dataset)e.g. FROM <http://users.jyu.fi/~olkhriye/ties4520/rdf/people.rdf>

WHERE(Query Triple Pattern)e.g. WHERE { f:mary f:age ?age }

ORDER BY, DISTINCT, HAVING, LIMIT, etc. (Modifiers)e.g. ORDER BY ?age

20/03/2019 TIES4520

Page 29: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Example data set

29

@prefix f: <http://example.org#> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix foaf: <http://xmlns.com/foaf/0.1/>.

f:john a foaf:Person .f:bill a foaf:Person .f:mary a foaf:Person .f:jane a foaf:Person .f:john f:age "25"^^xsd:int .f:bill f:age "30"^^xsd:int .f:mary f:age "24"^^xsd:int .f:jane f:age "26"^^xsd:int .f:john f:loves f:mary .f:bill f:loves f:jane .f:john f:hasFriend f:bill.f:john f:name "John Roy" .f:bill f:name "Bill Jou" .f:mary f:name "Mary Lestern" .f:jane f:name "Jane Caiton" .f:bill foaf:name "Bill" .f:john foaf:name "John" .f:mary foaf:name "Mary" .f:jane foaf:name "Jane" .

f:mary

25

f:john

f:age

f:janef:bill f:loves

30

24

26

f:age

f:loves

f:age

f:age

John Roy Mary Lestern

f:name

Bill Jou Jane Caiton

f:name

f:namef:name

foaf:Person

a a

aa

20/03/2019 TIES4520

Page 30: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Simple SPARQL queries (1)

� Show me the property f:age of resource f:mary

30

f:mary

25

f:john

f:age

f:janef:billf:loves

30

24

26

f:age

f:loves

f:age

f:age

Data

SELECT ?ageWHERE { <http://example.org#mary> <http://example.org#age> ?age }

Query

PREFIX f: <http://example.org#> SELECT ?ageWHERE { f:mary f:age ?age }

age

24

Resultf:mary

?age

f:age

20/03/2019 TIES4520

Page 31: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Simple SPARQL queries (2)

� Show me f:age of all resources

31

f:mary

25

f:john

f:age

f:janef:billf:loves

30

24

26

f:age

f:loves

f:age

f:age

Data Query

PREFIX f: <http://example.org#> SELECT ?person ?ageWHERE { ?person f:age ?age }

person age

f:bill 30

f:jane 26

f:john 25

f:mary 24

Result?person

?age

f:age

20/03/2019 TIES4520

Page 32: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Simple SPARQL queries (3)

� Show me all things that are loved. Also show me their age (f:age )

32

f:mary

25

f:john

f:age

f:janef:billf:loves

30

24

26

f:age

f:loves

f:age

f:age

Data Query

PREFIX f: <http://example.org#> SELECT ?person ?ageWHERE {

?x f:loves ?person . ?person f:age ?age

}

person age

f:jane 26

f:mary 24

Result

?person

?age

f:age

?xf:loves

20/03/2019 TIES4520

Page 33: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

SPARQL: FILTER (testing values)

� Show me people and their age for people older than 25.

33

f:mary

25

f:john

f:age

f:janef:billf:loves

30

24

26

f:age

f:loves

f:age

f:age

Data Query

PREFIX f: <http://example.org#> SELECT ?person ?ageWHERE {

?person f:age ?age .FILTER ( ?age > 25)

}

person age

f:bill 30

f:jane 26

Result

If ?age is not a number, then it will not work

?person

?age

f:age

20/03/2019 TIES4520

Page 34: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

SPARQL: Logical OR (UNION)

� Show me all people who have a friend together with all the people that are younger than 25

34

f:mary

25

f:john

f:age

f:janef:billf:loves

30

24

26

f:age

f:loves

f:age

f:age

Data Query

PREFIX f: <http://example.org#> SELECT ?personWHERE {

{ ?person f:age ?age . FILTER ( ?age < 25)}UNION

{ ?person f:hasFriend ?friend }}

person

f:mary

f:john

ResultPREFIX f: <http://example.org#> SELECT ?personWHERE {?person f:age ?age . FILTER ( ?age < 25)}

PREFIX f: <http://example.org#> SELECT ?personWHERE {?person f:hasFriend ?friend }

+

20/03/2019 TIES4520

Page 35: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

SPARQL: several sources

Use SERVICE clause for federated queries.

� The SERVICE keyword instructs a federated query processor to invoke a portion of a SPARQL query against a remote SPARQL endpoint (not a RDF file).

35

Query…PREFIX ex: <http://users.jyu.fi/~olkhriye/ties4520/ rdf/>SELECT ?person ?age ?jobWHERE {

SERVICE ex:people { ?person f:age ?age .} SERVICE ex:employment { ?person e:worksAs ?job .}SERVICE ex:jobs { ?job rdf:type j:EducationJob .}

}

person age job

f:bill 30 j:professor

f:john 25 j:teacher

Result

20/03/2019 TIES4520

Page 36: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Some Public SPARQL Endpoints

3620/03/2019 TIES4520

Page 37: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Ontology

� A person's vocabulary is the set of words within a language thatare familiar to that person. (Wikipedia)

� On the Semantic Web, vocabularies define the concepts andrelationships used to describe and represent an area of concern.(W3C). Vocabularies are used to:

– classify the terms that can be used in a particular application,– characterize relationships, and– define constraints on using those terms.

3720/03/2019 TIES4520

Page 38: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Ontology

� An Ontology is an explicit, formal specification of a sharedconceptualization. Ontologies are formal models that describe acertain domain and specify the definitions of terms by describingtheir relationships with other terms in the ontology.

� Example: medical ontology, IT ontology, music ontology, etc.� Consists of:

– TBox• Describes abstract concepts (Class) and their relationships (Property)• Taxonomy, classification

– ABox• Describes concrete individuals (Instance) and their relationships to other individuals

and/or abstract concepts from Tbox

� There cannot be a global ontology of everything– Ontologies are dynamic (they change in time)– Every person can have a different perspective on the domain

3820/03/2019 TIES4520

Page 39: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Instance vs. class

� Class (type)– Represents a set of things that share same properties (and/or

behavior)– characterized via attributes (name-value pairs)– Example: Person, Fruit, Feeling…

� Instance (individual)– Represents a concrete thing– Can belong to one or more classes– Example: johnDoe, appleGoldenDelicious, anger…

39

Usually names start with a capital letter

Usually names start with a small letter

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-synt ax-ns#> .@prefix ont: <http://www.john.com/myOntology.owl#> .

ont:benny rdf:type ont:Dog .ont:superman a ont:ComicBookCharacter .ont:mrBean <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ont:ComicCharacter .

20/03/2019 TIES4520

Page 40: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Important parts of TBox

� Class hierarchy– Defines classes of things and their relationships (class-

subclass and others)

� Object properties– Connections between two individuals– Example:

� Data properties– Connection between an individual and a value– Example:

40

p:john p:loves p:mary .

p:john p:hasHeight "178.5"^^xsd:float .

20/03/2019 TIES4520

Page 41: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Sample ontology: class hierarchy

41

MotherBoard

Mouse

Keyboard

InputDev

OutputDev

Display

Printer

CPU

Memory

HDD

TouchScreen

PC

Thing

RAM

20/03/2019 TIES4520

Page 42: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Properties

� In ontologies we define property’s domain and range– Domain : What can have this property– Range : What can be the value of this property

42

hum:isAttractedByD:R: Human

Human

phy:isAttractedByD:R: Particle

Particle

med:hasDiagnosisD:R: Diagnosis

Human

hum:hasSurnameD:R: rdfs:Literal

Human

psy:hasAtomicNumberD:R: xsd:string

Atom

20/03/2019 TIES4520

Page 43: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Properties

� Object properties:– Domain: URI– Range: URI

� Data properties:– Domain: URI– Range: Literal (typed or plain)

43

@prefix o: <http://john.com/myOnt.owl#> .

o:mary o:likes o:chocolate .

@prefix o: <http://john.com/myOnt.owl#> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

o:mary o:age "30"^^xsd:int .

20/03/2019 TIES4520

Page 44: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Sample ontology: object properties

44

topObjectPrpertyD:R: hasCPU

D:R: CPU

PC

hasMemoryD:R: Memory

PC

hasRAMD:R: RAM

PC

hasComponentD:R: CPU

MotherBoard

RAM InputDev OutputDev

Thing

Thing

20/03/2019 TIES4520

Page 45: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Sample ontology: data properties

45

topDataPrpertyD:R: hasSpeed

D:R:

CPU

hasCapacityD:R:

Memory

producedInD:R:

PC

hasProducerD:R:

PC

rdfs:Literal

rdf:PlainLiteral

xsd:date

xsd:string

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

Thing

Thing

20/03/2019 TIES4520

Page 46: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Ontology language

� Language that is used to formally define ontologies� Example:

– RDFS (RDF Schema)– OWL (Web Ontology Language)– OWL2

� Majority is based on RDF model as well– Ontology written in such language is RDF itself

� Differences between ontology languages– Expressiveness– Computational complexity of reasoning

4620/03/2019 TIES4520

Page 47: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

RDF Schema (RDFS)

� Simple ontology language (W3C Recommendation in 2004)� Prefix: � Features:

– Declaration of classes and subclass hierarchy:

– Declaration of literals and their hierarchy:

– Definition of properties and their hierarchy:

– Other features (statement, container, collections, comments, etc.)

47

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema #>

x:Human rdf:type rdfs:Class .x:Human rdfs:subClassOf x:LivingBeing .

x:Henkilotunnus rdf:type rdfs:Literal .rdfs:Datatype rdfs:subClassOf rdfs:Literal .

x:hasAge rdf:type rdf:Property .x:hasAge rdfs:domain x:LivingBeing .x:hasAge rdfs:range xsd:int .rdfs:subPropertyOf rdf:type rdf:Property .x:hasMovablePart rdfs:subPropertyOf x:hasPart .x:hasStaticPart rdfs:subPropertyOf x:hasPart .

20/03/2019 TIES4520

Page 48: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

RDFS example

� Ontology

� Annotated resource

48

@prefix x: <http://mypage.com/myOntologies/humanOntology#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

x:LivingBeing rdf:type rdfs:Class .x:Human a rdfs:Class ;

rdfs:subClassOf x:LivingBeing .x:hasAge a rdf:Property ;

rdfs:domain x:Human ;rdfs:range xsd:int .

@prefix x: <http://mypage.com/myOntologies/humanOntology#> . @prefix xsd: <http://www.w3.org/2000/01/rdf-schema#> .

x:bill a x:Human ; x:hasAge "40"^^xsd:int .

@prefix x: <http://mypage.com/myOntologies/humanOntology#> . @prefix xsd: <http://www.w3.org/2000/01/rdf-schema#> .

x:bill a x:LivingBeing ; "40"^^xsd:int .x:hasAgex:hasAge

20/03/2019 TIES4520

Page 49: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

OWL

4920/03/2019 TIES4520

Page 50: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Protégé

� Protégé is an ontology editor (http://protege.stanford.edu/)� Documentation: (http://protegewiki.stanford.edu/wiki/Main_Page)� Differences between Protege 3.x and 5.x (4.x) are equivalent to those between

Frames based systems and OWL (and DL reasoning) based ones(http://users.jyu.fi/~olkhriye/ties4520/lectures/FramesAndOWLSideBySide.pdf)

– Version 3.x (OWL 1 + RDFS)– Version 5.x & 4.x (OWL 2)

• written in a much more principled way than Protege 3 and for OWL ontologiesProtege 5 (4) is generally the right choice;

• does not include some of the plugins of Protege 3 and Protege 3 forms mechanism.

� Many plugins– Reasoners (HermiT, Pellet, FaCT++)– Exporters– New views

� Manchester syntax– Used in Protégé to define set operations and property restrictions– More info: http://www.w3.org/TR/owl2-manchester-syntax/

5020/03/2019 TIES4520

Page 51: Semantic Web technologies - Jyväskylän yliopistousers.jyu.fi/~olkhriye/ties4371/lectures/SW.pdf · UNIVERSITY OF JYVÄSKYLÄ Computer symbols Disambiguity of data (1) 3 Ideas Human

UNIVERSITY OF JYVÄSKYLÄ

Programming Tools for Semantic Web

Lecture 5:Programming with Semantic Web (RDF4J and Jena APIs)http://users.jyu.fi/~olkhriye/ties4520/

5120/03/2019 TIES4520