Skip to article frontmatterSkip to article content

Examples from RDF 1.1 Turtle

Diese Datei: Beispiele aus RDF 1.1 Turtle, eingelesen mit rdflib 6.3.

RDF 1.1 Turtle RDF 1.1 Turtle. Terse RDF Triple Language. W3C Recommendation 25 February 2014. https://www.w3.org/TR/turtle/

rdflib 6.3 rdflib 6.3.2. https://rdflib.readthedocs.io/en/stable/

from rdflib import Graph
import pprint # https://docs.python.org/3/library/pprint.html
import owlrl # https://owl-rl.readthedocs.io/en/latest/owlrl.html
Example_1 = """
@base <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rel: <http://www.perceive.net/schemas/relationship/> .

<#green-goblin>
    rel:enemyOf <#spiderman> ;
    a foaf:Person ;    # in the context of the Marvel universe
    foaf:name "Green Goblin" .

<#spiderman>
    rel:enemyOf <#green-goblin> ;
    a foaf:Person ;
    foaf:name "Spiderman", "Человек-паук"@ru .
"""
Example_1_g = Graph()
Example_1_g.parse(data=Example_1)
<Graph identifier=N12847b9dddcb4404ad6c2f9ddaa283fb (<class 'rdflib.graph.Graph'>)>
Example_9 = """
# A triple with all absolute IRIs
<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> .

@base <http://one.example/> .
<subject2> <predicate2> <object2> .     # relative IRIs, e.g. http://one.example/subject2

BASE <http://one.example/>
<subject2> <predicate2> <object2> .     # relative IRIs, e.g. http://one.example/subject2

@prefix p: <http://two.example/> .
p:subject3 p:predicate3 p:object3 .     # prefixed name, e.g. http://two.example/subject3

PREFIX p: <http://two.example/>
p:subject3 p:predicate3 p:object3 .     # prefixed name, e.g. http://two.example/subject3

@prefix p: <path/> .                    # prefix p: now stands for http://one.example/path/
p:subject4 p:predicate4 p:object4 .     # prefixed name, e.g. http://one.example/path/subject4

@prefix : <http://another.example/> .    # empty prefix
:subject5 :predicate5 :object5 .        # prefixed name, e.g. http://another.example/subject5

:subject6 a :subject7 .                 # same as :subject6 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> :subject7 .

<http://伝言.example/?user=أكرم&amp;channel=R%26D> a :subject8 . # a multi-script subject IRI .
"""

Example_9_g = Graph()
Example_9_g.parse(data=Example_9)
Example_10 = """
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://example.org/#green-goblin> foaf:name "Green Goblin" .
<http://example.org/#spiderman> foaf:name "Spiderman" .
"""

Example_10_g = Graph()
Example_10_g.parse(data=Example_10)
<Graph identifier=Nabefffc2a62e43a0a2a4260642ca255a (<class 'rdflib.graph.Graph'>)>
for stmt in Example_10_g:
    pprint.pprint(stmt)
(rdflib.term.URIRef('http://example.org/#spiderman'),
 rdflib.term.URIRef('http://xmlns.com/foaf/0.1/name'),
 rdflib.term.Literal('Spiderman'))
(rdflib.term.URIRef('http://example.org/#green-goblin'),
 rdflib.term.URIRef('http://xmlns.com/foaf/0.1/name'),
 rdflib.term.Literal('Green Goblin'))
Example_11 = """
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix show: <http://example.org/vocab/show/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

show:218 rdfs:label "That Seventies Show"^^xsd:string .            # literal with XML Schema string datatype
show:218 rdfs:label "That Seventies Show"^^<http://www.w3.org/2001/XMLSchema#string> . # same as above
show:218 rdfs:label "That Seventies Show" .                                            # same again
show:218 show:localName "That Seventies Show"@en .                 # literal with a language tag
show:218 show:localName 'Cette Série des Années Soixante-dix'@fr . # literal delimited by single quote
show:218 show:localName "Cette Série des Années Septante"@fr-be .  # literal with a region subtag
show:218 show:blurb '''This is a multi-line                        # literal with embedded new lines and quotes
literal without quotes ;-)
and up to two sequential apostrophes ('').''' .
"""
Example_11_g = Graph()
Example_11_g.parse(data=Example_11)
<Graph identifier=Nfe4228eab1504b6fa1bdf7b8f988553a (<class 'rdflib.graph.Graph'>)>
Example_12 = """
@prefix : <http://example.org/elements> .                                                                              
<http://en.wikipedia.org/wiki/Helium>                                                                                  
    :atomicNumber 2 ;               # xsd:integer                                                                      
    :atomicMass 4.002602 ;          # xsd:decimal                                                                      
    :specificGravity 1.663E-4 .     # xsd:double                                                                       
"""
Example_12_g = Graph()
Example_12_g.parse(data=Example_12)
Example_14 = """
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:alice foaf:knows _:bob .
_:bob foaf:knows _:alice .
"""
Example_14_g = Graph()
Example_14_g.parse(data=Example_14)
Example_15 = """
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
# Someone knows someone else, who has the name "Bob".
[] foaf:knows [ foaf:name "Bob" ] .
"""
Example_15_g = Graph()
Example_15_g.parse(data=Example_15)
Example_16 = """
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
[ foaf:name "Alice" ] foaf:knows [
    foaf:name "Bob" ;
    foaf:knows [
        foaf:name "Eve" ] ;
    foaf:mbox <bob@example.com> ] .
"""
Example_16_g = Graph()
Example_16_g.parse(data=Example_16)
Example_19 = """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ex: <http://example.org/stuff/1.0/> .

<http://www.w3.org/TR/rdf-syntax-grammar>
  dc:title "RDF/XML Syntax Specification (Revised)" ;
  ex:editor [
    ex:fullname "Dave Beckett";
    ex:homePage <http://purl.org/net/dajobe/>
  ] ."""
Example_19_g = Graph()
Example_19_g.parse(data=Example_19)
Example_20 = """
PREFIX : <http://example.org/stuff/1.0/>
:a :b ( "apple" "banana" ) .
"""
Example_20_g = Graph()
Example_20_g.parse(data=Example_20)
for stmt in Example_20_g:
    pprint.pprint(stmt)
(rdflib.term.BNode('n488140c442714d798de41c230cd63c38b2'),
 rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#rest'),
 rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'))
(rdflib.term.BNode('n488140c442714d798de41c230cd63c38b1'),
 rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#rest'),
 rdflib.term.BNode('n488140c442714d798de41c230cd63c38b2'))
(rdflib.term.BNode('n488140c442714d798de41c230cd63c38b1'),
 rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#first'),
 rdflib.term.Literal('apple'))
(rdflib.term.URIRef('http://example.org/stuff/1.0/a'),
 rdflib.term.URIRef('http://example.org/stuff/1.0/b'),
 rdflib.term.BNode('n488140c442714d798de41c230cd63c38b1'))
(rdflib.term.BNode('n488140c442714d798de41c230cd63c38b2'),
 rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#first'),
 rdflib.term.Literal('banana'))
Example_21 = """
@prefix : <http://example.org/stuff/1.0/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
:a :b
  [ rdf:first "apple";
    rdf:rest [ rdf:first "banana";
               rdf:rest rdf:nil ]
  ] .
"""
Example_21_g = Graph()
Example_21_g.parse(data=Example_21)
for stmt in Example_20_g:
    pprint.pprint(stmt)