RDF Syntax and examples ดร. มารุต บูรณรัช [email protected]...
-
Upload
stewart-george -
Category
Documents
-
view
226 -
download
2
Transcript of RDF Syntax and examples ดร. มารุต บูรณรัช [email protected]...
RDF Syntax and examples
ดร.มาร�ต บูรณร�ช [email protected]
269618: หั�วข้�อพิ�เศษด�านเทคโนโลยี�สารสนเทศข้��นสง - เทคโนโลยี�เว!บูเช�งความหัมายี (Special Topics in Advanced Information Technology – Semantic Web Technology)
ภาคว�ชาว�ทยีาการคอมพิ�วเตอร$และเทคโนโลยี�สารสนเทศคณะว�ทยีาศาสตร$ มหัาว�ทยีาล�ยีนเรศวรภาคการศ'กษาท�( 2 ปี*การศ'กษา 2557
RDF Syntax
RDF Graph RDF/XML N-Triples Turtle (Terse RDF Triple Language)
2
Examples Adding triple with object as a resource Adding triple with object as literal (string) Adding triple with object as literal (integer) Adding triple with “rdf:type” property Adding triple for the same property with
different values Different syntaxes for “rdf:about”, “rdf:ID”,
“rdf:type”3
Adding triple withobject as a resource
Example RDF Triple
“John Doe is a father of Jack Doe”
Subject http://www.mydomain.com/person#john_doe
Predicate http://www.mydomain.com/vocab#father-of
Object http://www.mydomain.com/person#jack_doe
5
RDF Graph
http://www.mydomain.com/person#john_doe
http://www.mydomain.com/person#jack_doe
http://www.mydomain.com/vocab#father-of
6
RDF/XML<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:x="http://www.mydomain.com/vocab#"> <rdf:Description rdf:about="http://www.mydomain.com/person#john_doe"> <x:father-of rdf:resource="http://www.mydomain.com/person#jack_doe"/> </rdf:Description> </rdf:RDF>
7
N-Triples
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#father-of> <http://www.mydomain.com/person#jack_doe> .
8
Turtle
@prefix x: <http://www.mydomain.com/vocab#>.
@prefix person: <http://www.mydomain.com/person#>.
person:john_doe x:father-of person:jack_doe.
9
Adding triple withobject as literal (string)
Adding new triple
Subject http://www.mydomain.com/person#john_doe
Predicate http://www.mydomain.com/vocab#has_name
Object “John Doe”@en
Note: “@” is optional for specifying language code of a string.
11
RDF Graph
http://www.mydomain.com/person#john_doe
http://www.mydomain.com/person#jack_doe
http://www.mydomain.com/vocab#father-of
“John Doe”@en
http://www.mydomain.com/vocab#has_name
12
RDF/XML
<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:x="http://www.mydomain.com/vocab#"> <rdf:Description rdf:about="http://www.mydomain.com/person#john_doe"> <x:father-of rdf:resource="http://www.mydomain.com/person#jack_doe"/> <x:has_name xml:lang=“en”>John Doe</x:has_name></rdf:Description> </rdf:RDF>
13
N-Triples
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#father-of> <http://www.mydomain.com/person#jack_doe> .
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#has_name> "John Doe" @en .
14
Turtle
@prefix x: <http://www.mydomain.com/vocab#>.
@prefix person: <http://www.mydomain.com/person#>.
person:john_doe x:father-of person:jack_doe ; x:has_name "John Doe"@en .
15
Adding triple withobject as literal (integer)
Adding new triple
Subject http://www.mydomain.com/person#john_doe
Predicate http://www.mydomain.com/vocab#has_birthyear
Object “1970”^^http://www.w3.org/2001/XMLSchema#integer
Note: “^^” is optional for specifying data type of a literal. If not specified, the default data type is string.
17
RDF Graph
http://www.mydomain.com/person#john_doe
http://www.mydomain.com/person#jack_doe
http://www.mydomain.com/vocab#father-of
“John Doe”@en
“1970”^^http://www.w3.org/2001/XMLSchema#integer
http://www.mydomain.com/vocab#has_name
http://www.mydomain.com/vocab#has_birthyear
18
RDF/XML<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:x="http://www.mydomain.com/vocab#"> <rdf:Description rdf:about="http://www.mydomain.com/person#john_doe"> <x:father-of rdf:resource="http://www.mydomain.com/person#jack_doe"/> <x:has_name xml:lang=“en”>John Doe</my:has_name> <x:has_birthyear rdf:datatype=“http://www.w3.org/2001/XMLSchema#integer”>1970</x:has_birthyear></rdf:Description> </rdf:RDF>
19
N-Triples
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#father-of> <http://www.mydomain.com/person#jack_doe> .
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#has_name> "John Doe" @en .
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#has_birthyear> "1970"^^http://www.w3.org/2001/XMLSchema#integer .
20
Turtle
@prefix x: <http://www.mydomain.com/vocab#>.
@prefix person: <http://www.mydomain.com/person#>.
@prefix xsd:<http://www.w3.org/2001/XMLSchema#>.
person:john_doe x:father-of person:jack_doe ; x:has_name "John Doe"@en ;
x:has_birthyear "1970"^^xsd:integer .
21
Adding triple with “rdf:type” property
Adding new triple
Subject http://www.mydomain.com/person#jack_doe
Predicate http://www.w3.org/1999/02/22-rdf-syntax-ns#type
Object http://www.mydomain.com/vocab#student
23
RDF Graph
http://www.mydomain.com/person#john_doe
http://www.mydomain.com/person#jack_doe
http://www.mydomain.com/vocab#father-of
“John Doe”@en
“1970”^^http://www.w3.org/2001/XMLSchema#integer
http://www.mydomain.com/vocab#has_name
http://www.mydomain.com/vocab#has_birthyear
http://www.mydomain.com/vocab#student
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
24
RDF/XML<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:x="http://www.mydomain.com/vocab#">
<rdf:Description rdf:about="http://www.mydomain.com/person#john_doe">
<x:father-of rdf:resource="http://www.mydomain.com/person#jack_doe"/>
<x:has_name xml:lang=“en”>John Doe</x:has_name>
<x:has_birthyear rdf:datatype=“http://www.w3.org/2001/XMLSchema#integer”>1970</x:has_birthyear>
</rdf:Description>
<rdf:Description rdf:about="http://www.mydomain.com/person#jack_doe">
<rdf:type rdf:resource="http://www.mydomain.com/vocab#student"/>
</rdf:Description>
</rdf:RDF> 25
N-Triples<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#father-of> <http://www.mydomain.com/person#jack_doe> .
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#has_name> "John Doe"@en.
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#has_birthyear> "1970"^^http://www.w3.org/2001/XMLSchema#integer.
<http://www.mydomain.com/person#jack_doe> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.mydomain.com/vocab#student> .
26
Turtle@prefix x: <http://www.mydomain.com/vocab#>.
@prefix person: <http://www.mydomain.com/person#>.
@prefix xsd:<http://www.w3.org/2001/XMLSchema#>.
person:john_doe x:father-of person:jack_doe ;x:has_name "John Doe"@en ;
x:has_birthyear "1970"^^xsd:integer .
person:jack_doe a x:student .
27
Adding triple for the same property with different values
Adding new triple
Subject http://www.mydomain.com/person#john_doe
Predicate http://www.mydomain.com/vocab#has_name
Object “จอหั$น โด”@th
Note: “@” is optional for specifying language code of a string.
29
RDF Graph
http://www.mydomain.com/person#john_doe
http://www.mydomain.com/person#jack_doe
http://www.mydomain.com/vocab#father-of
“John Doe”@en
“1970”^^http://www.w3.org/2001/XMLSchema#integer
http://www.mydomain.com/vocab#has_name
http://www.mydomain.com/vocab#has_birthyear
http://www.mydomain.com/vocab#student
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.mydomain.com/vocab#has_name
“จอหั$น โด”@th
30
RDF/XML<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:x="http://www.mydomain.com/vocab#">
<rdf:Description rdf:about="http://www.mydomain.com/person#john_doe">
<x:father-of rdf:resource="http://www.mydomain.com/person#jack_doe"/>
<x:has_name xml:lang="en">John Doe</x:has_name>
<x:has_birthyear rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">1970</x:has_birthyear>
<x:has_name xml:lang="th">จอหั$น โด</x:has_name>
</rdf:Description>
<rdf:Description rdf:about="http://www.mydomain.com/person#jack_doe">
<rdf:type rdf:resource="http://www.mydomain.com/vocab#student"/>
</rdf:Description>
</rdf:RDF> 31
N-Triples<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#father-of> <http://www.mydomain.com/person#jack_doe> .
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#has_name> "John Doe"@en.
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#has_birthyear> "1970"^^http://www.w3.org/2001/XMLSchema#integer.
<http://www.mydomain.com/person#jack_doe> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.mydomain.com/vocab#student> .
<http://www.mydomain.com/person#john_doe> <http://www.mydomain.com/vocab#has_name> “จอหั$น โด"@th .
32
Turtle
@prefix x: <http://www.mydomain.com/vocab#>.
@prefix person: <http://www.mydomain.com/person#>.
@prefix xsd:<http://www.w3.org/2001/XMLSchema#>.
person:john_doe x:father-of person:jack_doe ;x:has_name "John Doe"@en , “จอหั$น โด"@th ;
x:has_birthyear "1970"^^xsd:integer .
person:jack_doe a x:student .
33
Different syntaxes for “rdf:about”, “rdf:ID”, “rdf:type”
The following RDF..<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:x="http://www.mydomain.com/vocab#">
<rdf:Description rdf:about="http://www.mydomain.com/person#joe_clark">
<x:has_name xml:lang="en">Joe Clark</x:has_name>
<rdf:type rdf:resource="http://www.mydomain.com/vocab#student"/>
</rdf:Description>
</rdf:RDF>
35
is equivalent to<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:x="http://www.mydomain.com/vocab#"
xml:base="http://www.mydomain.com/person">
<rdf:Description rdf:ID="joe_clark">
<x:has_name xml:lang="en">Joe Clark</x:has_name>
<rdf:type rdf:resource="http://www.mydomain.com/vocab#student"/>
</rdf:Description>
</rdf:RDF>
36
is equivalent to (2)
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:x="http://www.mydomain.com/vocab#">
<x:student rdf:about ="http://www.mydomain.com/person#joe_clark">
<x:has_name xml:lang="en">Joe Clark</x:has_name>
</x:student>
</rdf:RDF>
37
is equivalent to (3)
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:x="http://www.mydomain.com/vocab#"
xml:base="http://www.mydomain.com/person">
<x:student rdf:ID="joe_clark">
<x:has_name xml:lang="en">Joe Clark</x:has_name>
</x:student>
</rdf:RDF>
38
Summary
RDF triples can be represented in multiple syntaxes RDF/XML is a current standard although it is
more complex than other syntaxes. Turtle is an extension of N-Tripples syntax and is
a subset of Notation 3 (N3) syntax. Turtle gains more popularity due to its simplicity
and has just become a standard. Turtle syntax is compatible with SPARQL syntax
which makes it easier to use with SPARQL.
39
Lab
1. Please create the example RDF/XML data in a file “person.rdf”1.1 Validate the created RDF data in W3C RDF Validation Service - http://www.w3.org/RDF/Validator/
1.2 Show the results in RDF triples and graph
2. Create the above RDF data in using N-Triples and Turtle syntax and validate the data using http://rdf.greggkellogg.net/distiller
40
Exercise 1:
Add the following information to the above RDF data Full name of ‘person:jack_doe’ as “Jack Doe” (in English)
and “แจ!ค โด” (in Thai) Add 2 phone numbers of ‘person:jack_doe’ as “082-111-
5555” and “02-123-1111” using property ‘x:has_phone’ Add birthdate of ‘person:jack_doe’ as “1970-11-11” using
property ‘x:has_birthdate’ with ‘xsd:date’ datatype. Add a triple that ‘person:john_doe’ has property ‘rdf:type’
of ‘x:doctor’.
41
Exercise 1:
Show the new RDF data in the following formats:1) RDF Graph
2) RDF/XML
3) N-Triples
4) Turtle
42
Exercise: 2
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://www.mydomain.com/vocab#">
<rdfs:Class rdf:ID="Person" />
<rdfs:Class rdf:ID="Student">
<rdfs:subClassOf rdf:resource="#Person" />
</rdfs:Class>
<rdfs:Class rdf:ID="Doctor">
<rdfs:subClassOf rdf:resource="#Person" />
</rdfs:Class>
<rdf:Property rdf:ID="father-of">
<rdfs:domain rdf:resource="#Person" />
<rdfs:range rdf:resource="#Person" />
</rdf:Property>
<rdf:Property rdf:ID="has_name">
<rdfs:domain rdf:resource="#Person" />
</rdf:Property>
<rdf:Property rdf:ID="has_birthyear">
<rdfs:domain rdf:resource="#Person" />
</rdf:Property>
</rdf:RDF>
Show this RDF data that makes use of RDF schema vocabulary in RDF Graph form
43