summaryrefslogtreecommitdiff
path: root/examples/simple_example.py
diff options
context:
space:
mode:
authorGunnar Aastrand Grimnes <gromgull@gmail.com>2013-05-07 22:29:21 +0200
committerGunnar Aastrand Grimnes <gromgull@gmail.com>2013-05-07 22:29:21 +0200
commit51ef22af04a6a260e09979d09ebdd4816e9542e4 (patch)
tree1874763e520b7ea0efc78637c28b85d855ee52bd /examples/simple_example.py
parent67ace218e6921d443342b6574788f59b1155bbe5 (diff)
downloadrdflib-51ef22af04a6a260e09979d09ebdd4816e9542e4.tar.gz
and even more doc updates
Diffstat (limited to 'examples/simple_example.py')
-rw-r--r--examples/simple_example.py81
1 files changed, 38 insertions, 43 deletions
diff --git a/examples/simple_example.py b/examples/simple_example.py
index bdfb96e2..7b44ff79 100644
--- a/examples/simple_example.py
+++ b/examples/simple_example.py
@@ -1,58 +1,53 @@
-import logging
-
-# Optional: Configure how we want rdflib logger to log messages
-_logger = logging.getLogger("rdflib")
-_logger.setLevel(logging.DEBUG)
-_hdlr = logging.StreamHandler()
-_hdlr.setFormatter(logging.Formatter('%(name)s %(levelname)s: %(message)s'))
-_logger.addHandler(_hdlr)
from rdflib import Graph, Literal, BNode, RDF
from rdflib.namespace import FOAF, DC
-store = Graph()
+if __name__=='__main__':
+
+ store = Graph()
-# Bind a few prefix, namespace pairs for pretty output
-store.bind("dc", DC)
-store.bind("foaf", FOAF)
+ # Bind a few prefix, namespace pairs for pretty output
+ store.bind("dc", DC)
+ store.bind("foaf", FOAF)
-# Create an identifier to use as the subject for Donna.
-donna = BNode()
+ # Create an identifier to use as the subject for Donna.
+ donna = BNode()
-# Add triples using store's add method.
-store.add((donna, RDF.type, FOAF.Person))
-store.add((donna, FOAF.nick, Literal("donna", lang="foo")))
-store.add((donna, FOAF.name, Literal("Donna Fales")))
+ # Add triples using store's add method.
+ store.add((donna, RDF.type, FOAF.Person))
+ store.add((donna, FOAF.nick, Literal("donna", lang="foo")))
+ store.add((donna, FOAF.name, Literal("Donna Fales")))
-# Iterate over triples in store and print them out.
-print "--- printing raw triples ---"
-for s, p, o in store:
- print s, p, o
+ # Iterate over triples in store and print them out.
+ print "--- printing raw triples ---"
+ for s, p, o in store:
+ print s, p, o
-# For each foaf:Person in the store print out its mbox property.
-print "--- printing mboxes ---"
-for person in store.subjects(RDF.type, FOAF["Person"]):
- for mbox in store.objects(person, FOAF["mbox"]):
- print mbox
+ # For each foaf:Person in the store print out its mbox property.
+ print "--- printing mboxes ---"
+ for person in store.subjects(RDF.type, FOAF["Person"]):
+ for mbox in store.objects(person, FOAF["mbox"]):
+ print mbox
-# Serialize the store as RDF/XML to the file foaf.rdf.
-store.serialize("foaf.rdf", format="pretty-xml", max_depth=3)
+ # Serialize the store as RDF/XML to the file donna_foaf.rdf.
+ store.serialize("donna_foaf.rdf", format="pretty-xml", max_depth=3)
-# Let's show off the serializers
+ # Let's show off the serializers
-print "RDF Serializations:"
+ print "RDF Serializations:"
-# Serialize as XML
-print "--- start: rdf-xml ---"
-print store.serialize(format="pretty-xml")
-print "--- end: rdf-xml ---\n"
+ # Serialize as XML
+ print "--- start: rdf-xml ---"
+ print store.serialize(format="pretty-xml")
+ print "--- end: rdf-xml ---\n"
-# Serialize as Turtle
-print "--- start: turtle ---"
-print store.serialize(format="turtle")
-print "--- end: turtle ---\n"
+ # Serialize as Turtle
+ print "--- start: turtle ---"
+ print store.serialize(format="turtle")
+ print "--- end: turtle ---\n"
-# Serialize as NTriples
-print "--- start: ntriples ---"
-print store.serialize(format="nt")
-print "--- end: ntriples ---\n"
+ # Serialize as NTriples
+ print "--- start: ntriples ---"
+ print store.serialize(format="nt")
+ print "--- end: ntriples ---\n"
+