Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a slightly opinionated autopep8 run #870

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .pep8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pep8]
ignore = W806
max-line-length = 85
exclude = pyRdfa,host,extras,transform,rdfs,pyMicrodata
exclude = host,extras,transform,rdfs
17 changes: 8 additions & 9 deletions examples/conjunctive_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@
from rdflib.graph import Graph, ConjunctiveGraph
from rdflib.plugins.memory import IOMemory

if __name__=='__main__':

if __name__ == '__main__':

ns = Namespace("http://love.com#")

mary = URIRef("http://love.com/lovers/mary#")
john = URIRef("http://love.com/lovers/john#")

cmary=URIRef("http://love.com/lovers/mary#")
cjohn=URIRef("http://love.com/lovers/john#")
cmary = URIRef("http://love.com/lovers/mary#")
cjohn = URIRef("http://love.com/lovers/john#")

store = IOMemory()

g = ConjunctiveGraph(store=store)
g.bind("love",ns)
g.bind("love", ns)

gmary = Graph(store=store, identifier=cmary)

Expand All @@ -38,21 +37,21 @@
gjohn = Graph(store=store, identifier=cjohn)
gjohn.add((john, ns['hasName'], Literal("John")))

#enumerate contexts
# enumerate contexts
for c in g.contexts():
print("-- %s " % c)

#separate graphs
# separate graphs
print(gjohn.serialize(format='n3'))
print("===================")
print(gmary.serialize(format='n3'))
print("===================")

#full graph
# full graph
print(g.serialize(format='n3'))

# query the conjunction of all graphs

print('Mary loves:')
for x in g[mary : ns.loves/ns.hasName]:
for x in g[mary: ns.loves / ns.hasName]:
print(x)
18 changes: 9 additions & 9 deletions examples/custom_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@
from rdflib import Graph, Literal, Namespace, XSD
from rdflib.term import bind

if __name__=='__main__':
if __name__ == '__main__':

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

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

c=complex(2,3)
c = complex(2, 3)

l=Literal(c)
l = Literal(c)

g=Graph()
g = Graph()
g.add((ns.mysubject, ns.myprop, l))

n3=g.serialize(format='n3')
n3 = g.serialize(format='n3')

# round-trip through n3

g2=Graph()
g2 = Graph()
g2.parse(data=n3, format='n3')

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

print(l2)

print(l2.value == c) # back to a python complex object
print(l2.value == c) # back to a python complex object
3 changes: 2 additions & 1 deletion examples/custom_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def customEval(ctx, part):

raise NotImplementedError()

if __name__=='__main__':

if __name__ == '__main__':

# add function directly, normally we would use setuptools and entry_points
rdflib.plugins.sparql.CUSTOM_EVALS['exampleEval'] = customEval
Expand Down
26 changes: 18 additions & 8 deletions examples/film.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
film.py http://www.imdb.com/title/tt0105236/
Review the movie "Reservoir Dogs"
"""
import datetime, os, sys, re, time
import datetime
import os
import sys
import re
import time

try:
import imdb
Expand All @@ -36,14 +40,15 @@

storefn = os.path.expanduser('~/movies.n3')
#storefn = '/home/simon/codes/film.dev/movies.n3'
storeuri = 'file://'+storefn
storeuri = 'file://' + storefn
title = 'Movies viewed by %s'

r_who = re.compile('^(.*?) <([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)>$')

IMDB = Namespace('http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#')
REV = Namespace('http://purl.org/stuff/rev#')


class Store:
def __init__(self):
self.graph = ConjunctiveGraph()
Expand All @@ -61,12 +66,14 @@ def who(self, who=None):
if who is not None:
name, email = (r_who.match(who).group(1), r_who.match(who).group(2))
self.graph.add((URIRef(storeuri), DC['title'], Literal(title % name)))
self.graph.add((URIRef(storeuri+'#author'), RDF.type, FOAF['Person']))
self.graph.add((URIRef(storeuri+'#author'), FOAF['name'], Literal(name)))
self.graph.add((URIRef(storeuri+'#author'), FOAF['mbox'], Literal(email)))
self.graph.add((URIRef(storeuri + '#author'), RDF.type, FOAF['Person']))
self.graph.add((URIRef(storeuri + '#author'),
FOAF['name'], Literal(name)))
self.graph.add((URIRef(storeuri + '#author'),
FOAF['mbox'], Literal(email)))
self.save()
else:
return self.graph.objects(URIRef(storeuri+'#author'), FOAF['name'])
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)
Expand All @@ -76,14 +83,14 @@ def new_movie(self, movie):
self.save()

def new_review(self, movie, date, rating, comment=None):
review = BNode() # @@ humanize the identifier (something like #rev-$date)
review = BNode() # @@ humanize the identifier (something like #rev-$date)
movieuri = URIRef('http://www.imdb.com/title/tt%s/' % movie.movieID)
self.graph.add((movieuri, REV['hasReview'], URIRef('%s#%s' % (storeuri, review))))
self.graph.add((review, RDF.type, REV['Review']))
self.graph.add((review, DC['date'], Literal(date)))
self.graph.add((review, REV['maxRating'], Literal(5)))
self.graph.add((review, REV['minRating'], Literal(0)))
self.graph.add((review, REV['reviewer'], URIRef(storeuri+'#author')))
self.graph.add((review, REV['reviewer'], URIRef(storeuri + '#author')))
self.graph.add((review, REV['rating'], Literal(rating)))
if comment is not None:
self.graph.add((review, REV['text'], Literal(comment)))
Expand All @@ -92,9 +99,11 @@ 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])


def main(argv=None):
if not argv:
argv = sys.argv
Expand Down Expand Up @@ -136,6 +145,7 @@ def main(argv=None):
else:
help()


if __name__ == '__main__':
if not imdb:
raise Exception('This example requires the IMDB library! Install with "pip install imdbpy"')
Expand Down
2 changes: 1 addition & 1 deletion examples/foafpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from rdflib import URIRef, Graph
from rdflib.namespace import FOAF

if __name__=='__main__':
if __name__ == '__main__':

g = Graph()
g.load("foaf.rdf")
Expand Down
6 changes: 4 additions & 2 deletions examples/graph_digest_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from rdflib.compare import to_isomorphic
from six.moves.urllib.request import urlopen
from six.moves import queue
import sys, csv
import sys
import csv

from io import StringIO
from collections import defaultdict
Expand Down Expand Up @@ -49,7 +50,7 @@
'to_hash_runtime',
'canonicalize_triples_runtime',
'error',
]
]


def files_benchmark(ontologies, output_file, threads):
Expand Down Expand Up @@ -160,6 +161,7 @@ def worker(q, finished_tasks, dl_lock):
w.flush()
written_tasks += 1


if __name__ == '__main__':
if len(sys.argv) > 4:
files_benchmark(sys.argv[1:-2], sys.argv[-2], sys.argv[-1])
Expand Down
4 changes: 2 additions & 2 deletions examples/prepared_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from rdflib.plugins.sparql import prepareQuery
from rdflib.namespace import FOAF

if __name__=='__main__':
if __name__ == '__main__':

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

g = rdflib.Graph()
g.load("foaf.rdf")
Expand Down
2 changes: 1 addition & 1 deletion examples/rdfa_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
schema:name ?title ]
FILTER (LANG(?title) = 'en') } """):

print("%s by %s"%(row.title, row.author))
print("%s by %s" % (row.title, row.author))
11 changes: 5 additions & 6 deletions examples/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
from rdflib import Graph, RDF, RDFS, Literal
from rdflib.namespace import FOAF

if __name__=='__main__':
if __name__ == '__main__':

g = Graph()

bob = g.resource('urn:bob')

bob.set(RDF.type, FOAF.Person) # .set replaces all other values
bob.set(RDF.type, FOAF.Person) # .set replaces all other values
bob.set(FOAF.name, Literal("Bob"))


bill = g.resource('urn:bill')

bill.add(RDF.type, FOAF.Person) # add adds to existing values
bill.add(RDF.type, FOAF.Person) # add adds to existing values
bill.add(RDF.type, FOAF.Agent)
bill.set(RDFS.label, Literal("Bill"))

Expand All @@ -42,8 +41,8 @@

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

# setting single properties is also possible:
bill[RDFS.label]=Literal("William")
bill[RDFS.label] = Literal("William")
2 changes: 1 addition & 1 deletion examples/simple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rdflib import Graph, Literal, BNode, RDF
from rdflib.namespace import FOAF, DC

if __name__=='__main__':
if __name__ == '__main__':

store = Graph()

Expand Down
4 changes: 2 additions & 2 deletions examples/sleepycat_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

graph = ConjunctiveGraph('Sleepycat')

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

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

Expand All @@ -56,5 +56,5 @@
# Clean up the temp folder to remove the Sleepycat database files...
import os
for f in os.listdir(path):
os.unlink(path+'/'+f)
os.unlink(path + '/' + f)
os.rmdir(path)
8 changes: 4 additions & 4 deletions examples/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
from rdflib import Graph, RDF
from rdflib.namespace import FOAF

if __name__=='__main__':
if __name__ == '__main__':

graph = Graph()

graph.load("foaf.rdf")

for person in graph[: RDF.type : FOAF.Person]:
for person in graph[: RDF.type: FOAF.Person]:

friends = list(graph[person:FOAF.knows * '+'/FOAF.name])
friends = list(graph[person:FOAF.knows * '+' / FOAF.name])
if friends:
print("%s's circle of friends:"%graph.value(person, FOAF.name))
print("%s's circle of friends:" % graph.value(person, FOAF.name))
for name in friends:
print(name)
13 changes: 6 additions & 7 deletions examples/smushing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@

STABLE = Namespace("http://example.com/person/mbox_sha1sum/")

if __name__=='__main__':
if __name__ == '__main__':
g = Graph()
g.parse("smushingdemo.n3", format="n3")

newURI = {} # old subject : stable uri
for s,p,o in g.triples((None, FOAF['mbox_sha1sum'], None)):
newURI = {} # old subject : stable uri
for s, p, o in g.triples((None, FOAF['mbox_sha1sum'], None)):
newURI[s] = STABLE[o]


out = Graph()
out.bind('foaf', FOAF)

for s,p,o in g:
for s, p, o in g:
s = newURI.get(s, s)
o = newURI.get(o, o) # might be linked to another person
out.add((s,p,o))
o = newURI.get(o, o) # might be linked to another person
out.add((s, p, o))

print(out.serialize(format="n3").decode('utf-8'))
2 changes: 1 addition & 1 deletion examples/sparql_query_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import rdflib

if __name__=='__main__':
if __name__ == '__main__':

g = rdflib.Graph()
g.load("foaf.rdf")
Expand Down
2 changes: 1 addition & 1 deletion examples/sparql_update_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import rdflib

if __name__=='__main__':
if __name__ == '__main__':

g = rdflib.Graph()
g.load("foaf.rdf")
Expand Down
1 change: 0 additions & 1 deletion examples/sparqlstore_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

graph.open("http://dbpedia.org/sparql")


pop = graph.value(
URIRef("http://dbpedia.org/resource/Berlin"),
dbo.populationTotal)
Expand Down
Loading