Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
39fce20
six: added six to requirements
joernhees Nov 24, 2014
af95576
six: modify setup.py so we can sequentially change files from 2to3 to…
joernhees Nov 26, 2014
392e874
six: transformed and extended py3compat to be used as six wrapper
joernhees Nov 26, 2014
2adbb1c
six: fix tuple assignment in method signature for py3
joernhees Nov 26, 2014
7e07b63
six: __future__ headers
joernhees Nov 26, 2014
a5a1ded
cleanup: import of hashlib.md5
joernhees Nov 26, 2014
00e9435
six: relative imports for compat and py3compat
joernhees Nov 26, 2014
911b0d2
six: use urljoin, urlquote, urldefrag from six.moves
joernhees Nov 26, 2014
e5df52e
six: use PY2, PY3 from six, __nonzero__/__bool__ compatibility
joernhees Nov 26, 2014
f9d2a1b
six: unicode --> text_type
joernhees Nov 26, 2014
1b7bc9a
six: basestring --> string_types
joernhees Nov 26, 2014
7db79c8
six: long --> long_type
joernhees Nov 26, 2014
9c20830
six: term.py done
joernhees Nov 26, 2014
904cbfb
six: __init__.py done
joernhees Nov 26, 2014
53315d1
six: added list of python files which are 2to3 transformed.
joernhees Nov 27, 2014
1592aaf
six: collection.py headers and exception syntax
joernhees Nov 27, 2014
0822134
six: compare.py: headers, unicode
joernhees Feb 19, 2015
9d49d20
six: events.py: headers, handling of .keys()
joernhees Nov 27, 2014
ca08de6
six: plugin.py: headers, handling of iteritems
joernhees Nov 27, 2014
dd4cf35
six: py3compat imports BytesIO and StringIO from six
joernhees Nov 28, 2014
6e3d8f4
six: query.py: headers
joernhees Nov 28, 2014
ef5cf3c
six: query.py: imports fixed
joernhees Nov 28, 2014
5d9862e
six: query.py: unicode --> text_type
joernhees Nov 28, 2014
20b75ec
six: query.py: __nonzero__ --> __bool__ handling
joernhees Nov 28, 2014
41fb575
six: query.py done
joernhees Nov 28, 2014
264eb1f
six: resource.py: headers, unicode
joernhees Nov 28, 2014
e2a6c39
six: py3compat import cPickle
joernhees Nov 28, 2014
23c3b53
six: store.py: headers, pickle, exceptions, method sig tuple assignments
joernhees Nov 28, 2014
7aaf240
six: util.py: headers, StringIO
joernhees Nov 28, 2014
ff97d4f
six: py3compat.py: use efficient py2 BytesIO version
joernhees Nov 28, 2014
695b9de
six: graph.py: headers, imports
joernhees Nov 28, 2014
a3f490c
six: graph.py: method sig tuple assignments, iterators
joernhees Nov 28, 2014
846292d
six: py3compat.py: added six.moves.urllib.request.pathname2url
joernhees Nov 29, 2014
f1f0883
six: namespace.py: headers, imports
joernhees Nov 29, 2014
c80ecf3
six: namespace.py: unicode, string_types
joernhees Nov 29, 2014
ca6dce6
six: namespace.py: xrange --> range
joernhees Nov 29, 2014
87f5ab3
six: namespace.py: removed unnecessary u"" prefix
joernhees Nov 29, 2014
b9c924a
six: namespace.py done
joernhees Nov 29, 2014
f6d0cae
six: parser.py: headers, imports, unicode, basestring
joernhees Nov 29, 2014
2f5523e
six: run_tests.py: cleanup, py3 compatible
joernhees Nov 30, 2014
9d8f8cd
six: run_tests_py3.sh updated to base on setup.py build & use run_tes…
joernhees Nov 30, 2014
4016d1b
six: extras/describer.py: headers, rel imports
joernhees Dec 1, 2014
4997a42
six: extras/infixowl.py: headers
joernhees Dec 1, 2014
9cb180f
six: memory.py: headers, method sig tuple assignments
joernhees Dec 2, 2014
7259642
six: py3compat.py: handlers for iteritems, iterkeys, itervalues
joernhees Dec 2, 2014
672d694
six: memory.py: handling of iteritems
joernhees Dec 2, 2014
8aedecb
six: py3compat.py: added binary_type and unichr
joernhees Dec 3, 2014
4e9f12f
six: parsers/notation3.py: hearders; str, unicode, long, unichr, prin…
joernhees Dec 3, 2014
36a2260
six: parsers/nquads.py: headers, exception syntax
joernhees Dec 4, 2014
182ea44
six: util.py: cleanup unused StringIO
joernhees Dec 4, 2014
8f208de
six: compare.py: headers and unicode --> text_type
joernhees Feb 19, 2015
c005cc4
trivial py3 conversion of tools
gromgull Nov 19, 2016
d6fa925
converted all base serialisers and parsers
gromgull Nov 19, 2016
ab72075
converted examples
gromgull Nov 19, 2016
2b1e41e
converted sleepycat store
gromgull Nov 19, 2016
50a97f8
converted sparql engine
gromgull Nov 19, 2016
a8da22c
converted sparql results files
gromgull Nov 19, 2016
155707f
converted stores
gromgull Nov 19, 2016
890bd34
converted rest of microdata classes
gromgull Nov 19, 2016
f86cec3
converted rest of rdfaA files
gromgull Nov 21, 2016
8baa7a4
converted docs/plugintable
gromgull Nov 21, 2016
34584cd
converted csv2rdf
gromgull Nov 21, 2016
83b6396
tagged sparqlstore as converted and fixed example
gromgull Nov 21, 2016
7a2a6ea
converted all tests
gromgull Nov 21, 2016
514a8b3
removed no longer existing files from skiplist
joernhees Jan 28, 2017
b1076a6
six: sparql engine: leftover iteritems, itervalues, text_type
joernhees Jan 28, 2017
dfd9a71
six: turtle: text_type
joernhees Jan 28, 2017
9ab4078
six: sparql aggregates no longer relies on map returning a list
joernhees Jan 28, 2017
661a289
six: add still un-sixed files
joernhees Jan 28, 2017
da6837e
Move Store API to work with identifiers, not graphs
gromgull Jul 11, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions docs/plugintable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Crappy utility for generating Sphinx tables
Crappy utility for generating Sphinx tables
for rdflib plugins
"""

Expand All @@ -11,23 +11,22 @@

p = {}

for (name, kind), plugin in _plugins.items():
for (name, kind), plugin in _plugins.items():
if "/" in name: continue # skip duplicate entries for mimetypes
if cls == kind.__name__:
if cls == kind.__name__:
p[name]="%s.%s"%(plugin.module_path, plugin.class_name)

l1=max(len(x) for x in p)
l2=max(10+len(x) for x in p.values())

def hr():
print "="*l1,"="*l2
print("="*l1,"="*l2)

hr()
print "%-*s"%(l1,"Name"), "%-*s"%(l2, "Class")
print("%-*s"%(l1,"Name"), "%-*s"%(l2, "Class"))
hr()

for n in sorted(p):
print "%-*s"%(l1,n), ":class:`~%s`"%p[n]
for n in sorted(p):
print("%-*s"%(l1,n), ":class:`~%s`"%p[n])
hr()
print

print()
4 changes: 2 additions & 2 deletions examples/conjunctive_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@

# query the conjunction of all graphs

print 'Mary loves:'
print('Mary loves:')
for x in g[mary : ns.loves/ns.hasName]:
print x
print(x)
12 changes: 5 additions & 7 deletions examples/custom_datatype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""

RDFLib can map between data-typed literals and python objects.
RDFLib can map between data-typed literals and python objects.

Mapping for integers, floats, dateTimes, etc. are already added, but
you can also add your own.
Expand All @@ -17,9 +17,9 @@
if __name__=='__main__':

# complex numbers are not registered by default
# no custom constructor/serializer needed since
# no custom constructor/serializer needed since
# complex('(2+3j)') works fine
bind(XSD.complexNumber, complex)
bind(XSD.complexNumber, complex)

ns=Namespace("urn:my:namespace:")

Expand All @@ -39,8 +39,6 @@

l2=list(g2)[0][2]

print l2

print l2.value == c # back to a python complex object

print(l2)

print(l2.value == c) # back to a python complex object
2 changes: 1 addition & 1 deletion examples/custom_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def customEval(ctx, part):
# Find all FOAF Agents
for x in g.query(
'PREFIX foaf: <%s> SELECT * WHERE { ?s a foaf:Agent . }' % FOAF):
print x
print(x)
28 changes: 14 additions & 14 deletions examples/film.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
"""
"""

film.py: a simple tool to manage your movies review
Simon Rozet, http://atonie.org/
Expand All @@ -10,7 +10,7 @@
- handle non IMDB uri
- markdown support in comment

Requires download and import of Python imdb library from
Requires download and import of Python imdb library from
http://imdbpy.sourceforge.net/ - (warning: installation
will trigger automatic installation of several other packages)

Expand All @@ -25,14 +25,14 @@
"""
import datetime, os, sys, re, time

try:
try:
import imdb
except ImportError:
except ImportError:
imdb = None

from rdflib import BNode, ConjunctiveGraph, URIRef, Literal, Namespace, RDF
from rdflib.namespace import FOAF, DC

from rdflib.py3compat import input

storefn = os.path.expanduser('~/movies.n3')
#storefn = '/home/simon/codes/film.dev/movies.n3'
Expand All @@ -53,10 +53,10 @@ def __init__(self):
self.graph.bind('foaf', FOAF)
self.graph.bind('imdb', IMDB)
self.graph.bind('rev', 'http://purl.org/stuff/rev#')

def save(self):
self.graph.serialize(storeuri, format='n3')

def who(self, who=None):
if who is not None:
name, email = (r_who.match(who).group(1), r_who.match(who).group(2))
Expand All @@ -67,14 +67,14 @@ def who(self, who=None):
self.save()
else:
return self.graph.objects(URIRef(storeuri+'#author'), FOAF['name'])

def new_movie(self, movie):
movieuri = URIRef('http://www.imdb.com/title/tt%s/' % movie.movieID)
self.graph.add((movieuri, RDF.type, IMDB['Movie']))
self.graph.add((movieuri, DC['title'], Literal(movie['title'])))
self.graph.add((movieuri, IMDB['year'], Literal(int(movie['year']))))
self.save()

def new_review(self, movie, date, rating, comment=None):
review = BNode() # @@ humanize the identifier (something like #rev-$date)
movieuri = URIRef('http://www.imdb.com/title/tt%s/' % movie.movieID)
Expand All @@ -91,7 +91,7 @@ def new_review(self, movie, date, rating, comment=None):

def movie_is_in(self, uri):
return (URIRef(uri), RDF.type, IMDB['Movie']) in self.graph

def help():
print(__doc__.split('--')[1])

Expand Down Expand Up @@ -121,22 +121,22 @@ def main(argv=None):
rating = None
while not rating or (rating > 5 or rating <= 0):
try:
rating = int(raw_input('Rating (on five): '))
rating = int(input('Rating (on five): '))
except ValueError:
rating = None
date = None
while not date:
try:
i = raw_input('Review date (YYYY-MM-DD): ')
i = input('Review date (YYYY-MM-DD): ')
date = datetime.datetime(*time.strptime(i, '%Y-%m-%d')[:6])
except:
date = None
comment = raw_input('Comment: ')
comment = input('Comment: ')
s.new_review(movie, date, rating, comment)
else:
help()

if __name__ == '__main__':
if not imdb:
if not imdb:
raise Exception('This example requires the IMDB library! Install with "pip install imdbpy"')
main()
8 changes: 4 additions & 4 deletions examples/foafpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
in triple-patterns.

We overload some python operators on URIRefs to allow creating path
operators directly in python.
operators directly in python.

============ =========================================
Operator Path
Expand All @@ -13,7 +13,7 @@
``p1 | p2`` Path alternative
``p1 * '*'`` chain of 0 or more p's
``p1 * '+'`` chain of 1 or more p's
``p1 * '?'`` 0 or 1 p
``p1 * '?'`` 0 or 1 p
``~p1`` p1 inverted, i.e. (s p1 o) <=> (o ~p1 s)
``-p1`` NOT p1, i.e. any property but p1
============ =========================================
Expand All @@ -38,7 +38,7 @@

tim = URIRef("http://www.w3.org/People/Berners-Lee/card#i")

print "Timbl knows:"
print("Timbl knows:")

for o in g.objects(tim, FOAF.knows / FOAF.name):
print o
print(o)
6 changes: 3 additions & 3 deletions examples/prepared_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SPARQL Queries be prepared (i.e parsed and translated to SPARQL algebra)
by the :meth:`rdflib.plugins.sparql.prepareQuery` method.

When executing, variables can be bound with the
When executing, variables can be bound with the
``initBindings`` keyword parameter


Expand All @@ -17,7 +17,7 @@
if __name__=='__main__':

q = prepareQuery(
'SELECT ?s WHERE { ?person foaf:knows ?s .}',
'SELECT ?s WHERE { ?person foaf:knows ?s .}',
initNs = { "foaf": FOAF })

g = rdflib.Graph()
Expand All @@ -26,4 +26,4 @@
tim = rdflib.URIRef("http://www.w3.org/People/Berners-Lee/card#i")

for row in g.query(q, initBindings={'person': tim}):
print row
print(row)
10 changes: 5 additions & 5 deletions examples/rdfa_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""

A simple example showing how to process RDFa from the web

"""
Expand All @@ -11,12 +11,12 @@

g.parse('http://www.worldcat.org/title/library-of-babel/oclc/44089369', format='rdfa')

print "Books found:"
print("Books found:")

for row in g.query("""SELECT ?title ?author WHERE {
[ a schema:Book ;
for row in g.query("""SELECT ?title ?author WHERE {
[ a schema:Book ;
schema:author [ rdfs:label ?author ] ;
schema:name ?title ]
FILTER (LANG(?title) = 'en') } """):

print "%s by %s"%(row.title, row.author)
print("%s by %s"%(row.title, row.author))
16 changes: 7 additions & 9 deletions examples/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@

# Resources returned when querying are 'auto-boxed' as resources:

print "Bill's friend: ", bill.value(FOAF.knows).value(FOAF.name)
print("Bill's friend: ", bill.value(FOAF.knows).value(FOAF.name))

# slicing ([] syntax) can also be used:
# slicing ([] syntax) can also be used:

print "Bill knows: ",
for friend in bill[FOAF.knows]:
print friend[FOAF.name].next(), " "
print("Bill knows: ")
for friend in bill[FOAF.knows]:
print(next(friend[FOAF.name]))

# or even quicker with paths:
print "Bill knows: ",
print("Bill knows: ")
for friend in bill[FOAF.knows/FOAF.name]:
print friend
print(friend)

# setting single properties is also possible:
bill[RDFS.label]=Literal("William")

print g.serialize(format='n3')
29 changes: 14 additions & 15 deletions examples/simple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,34 @@
store.add((donna, FOAF.name, Literal("Donna Fales")))

# Iterate over triples in store and print them out.
print "--- printing raw triples ---"
print("--- printing raw triples ---")
for s, p, o in store:
print s, p, o
print(s, p, o)

# For each foaf:Person in the store print out its mbox property.
print "--- printing mboxes ---"
print("--- printing mboxes ---")
for person in store.subjects(RDF.type, FOAF["Person"]):
for mbox in store.objects(person, FOAF["mbox"]):
print mbox
print(mbox)

# 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

print "RDF Serializations:"
print("RDF Serializations:")

# Serialize as XML
print "--- start: rdf-xml ---"
print store.serialize(format="pretty-xml")
print "--- end: rdf-xml ---\n"
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"
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"

print("--- start: ntriples ---")
print(store.serialize(format="nt"))
print("--- end: ntriples ---\n")
28 changes: 14 additions & 14 deletions examples/sleepycat_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# Open previously created store, or create it if it doesn't exist yet
graph = ConjunctiveGraph('Sleepycat')

rt = graph.open(path, create=False)

if rt == NO_STORE:
Expand All @@ -24,7 +24,7 @@
else:
assert rt == VALID_STORE, 'The underlying store is corrupt'

print 'Triples in graph before add: ', len(graph)
print('Triples in graph before add: ', len(graph))

# Now we'll add some triples to the graph & commit the changes
rdflib = Namespace('http://rdflib.net/test/')
Expand All @@ -33,28 +33,28 @@
graph.add((rdflib['pic:1'], rdflib.name, Literal('Jane & Bob')))
graph.add((rdflib['pic:2'], rdflib.name, Literal('Squirrel in Tree')))

print 'Triples in graph after add: ', len(graph)
print('Triples in graph after add: ', len(graph))

# display the graph in RDF/XML
print graph.serialize(format='n3')
print(graph.serialize(format='n3'))

# close when done, otherwise sleepycat will leak lock entries.
# close when done, otherwise sleepycat will leak lock entries.
graph.close()

graph = None

# reopen the graph

graph = ConjunctiveGraph('Sleepycat')
graph.open(path, create = False)
print 'Triples still in graph: ', len(graph)

graph.open(path, create = False)

print('Triples still in graph: ', len(graph))

graph.close()

# Clean up the temp folder to remove the Sleepycat database files...
import os
for f in os.listdir(path):
for f in os.listdir(path):
os.unlink(path+'/'+f)
os.rmdir(path)
Loading