summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorNicholas Car <nicholas.car@surroundaustralia.com>2021-07-20 23:13:06 +1000
committerNicholas Car <nicholas.car@surroundaustralia.com>2021-07-20 23:13:06 +1000
commit17969dccdc6b182ef19c1a9e0b86a6585026aeab (patch)
treee9d421e78624f0e9cd11f8217c2d92c129963012 /examples
parent7ebfd306543d8cc0a8b48700870e6fba3d7d256d (diff)
downloadrdflib-17969dccdc6b182ef19c1a9e0b86a6585026aeab.tar.gz
blacked everything6.0.0
Diffstat (limited to 'examples')
-rw-r--r--examples/berkeleydb_example.py7
-rw-r--r--examples/conjunctive_graphs.py2
-rw-r--r--examples/datasets.py42
-rw-r--r--examples/prepared_query.py2
-rw-r--r--examples/slice.py4
-rw-r--r--examples/sparqlstore_example.py10
6 files changed, 39 insertions, 28 deletions
diff --git a/examples/berkeleydb_example.py b/examples/berkeleydb_example.py
index d50352b1..9a16e86a 100644
--- a/examples/berkeleydb_example.py
+++ b/examples/berkeleydb_example.py
@@ -22,8 +22,7 @@ from tempfile import mktemp
def example_1():
- """Creates a ConjunctiveGraph and performs some BerkeleyDB tasks with it
- """
+ """Creates a ConjunctiveGraph and performs some BerkeleyDB tasks with it"""
path = mktemp()
# Declare we are using a BerkeleyDB Store
@@ -115,13 +114,13 @@ def example_2():
return e.code, str(e), None
data = res.read()
- encoding = res.info().get_content_charset('utf-8')
+ encoding = res.info().get_content_charset("utf-8")
j = json.loads(data.decode(encoding))
for v in j["tree"]:
# process the element in GitHub result if it's a Turtle file
if v["path"].endswith(".ttl"):
# for each file, call it by URL, decode it and parse it into the graph
- r = urlopen(v['url'])
+ r = urlopen(v["url"])
content = json.loads(r.read().decode())["content"]
g.parse(data=base64.b64decode(content).decode(), format="turtle")
print(len(g))
diff --git a/examples/conjunctive_graphs.py b/examples/conjunctive_graphs.py
index e6b6c11a..b2e6aacf 100644
--- a/examples/conjunctive_graphs.py
+++ b/examples/conjunctive_graphs.py
@@ -59,7 +59,7 @@ if __name__ == "__main__":
print("Query the conjunction of all graphs:")
xx = None
- for x in g[mary: LOVE.loves / LOVE.hasCuteName]:
+ for x in g[mary : LOVE.loves / LOVE.hasCuteName]:
xx = x
print("Q: Who does Mary love?")
print("A: Mary loves {}".format(xx))
diff --git a/examples/datasets.py b/examples/datasets.py
index 76f8ae73..e5d14aa1 100644
--- a/examples/datasets.py
+++ b/examples/datasets.py
@@ -25,27 +25,33 @@ graph_1 = URIRef("http://example.com/graph-1")
d.graph(identifier=graph_1)
# Add two quads to Graph graph_1 in the Dataset
-d.add((
- URIRef("http://example.com/subject-x"),
- URIRef("http://example.com/predicate-x"),
- Literal("Triple X"),
- graph_1
-))
-d.add((
- URIRef("http://example.com/subject-z"),
- URIRef("http://example.com/predicate-z"),
- Literal("Triple Z"),
- graph_1
-))
+d.add(
+ (
+ URIRef("http://example.com/subject-x"),
+ URIRef("http://example.com/predicate-x"),
+ Literal("Triple X"),
+ graph_1,
+ )
+)
+d.add(
+ (
+ URIRef("http://example.com/subject-z"),
+ URIRef("http://example.com/predicate-z"),
+ Literal("Triple Z"),
+ graph_1,
+ )
+)
# Add another quad to the Dataset to a non-existent Graph:
# the Graph is created automatically
-d.add((
- URIRef("http://example.com/subject-y"),
- URIRef("http://example.com/predicate-y"),
- Literal("Triple Y"),
- URIRef("http://example.com/graph-2")
-))
+d.add(
+ (
+ URIRef("http://example.com/subject-y"),
+ URIRef("http://example.com/predicate-y"),
+ Literal("Triple Y"),
+ URIRef("http://example.com/graph-2"),
+ )
+)
# printing the Dataset like this: print(d.serialize(format="trig"))
# produces a result like this:
diff --git a/examples/prepared_query.py b/examples/prepared_query.py
index daa424fa..828ed052 100644
--- a/examples/prepared_query.py
+++ b/examples/prepared_query.py
@@ -17,7 +17,7 @@ if __name__ == "__main__":
q = prepareQuery(
"SELECT ?name WHERE { ?person foaf:knows/foaf:name ?name . }",
- initNs={"foaf": FOAF}
+ initNs={"foaf": FOAF},
)
g = rdflib.Graph()
diff --git a/examples/slice.py b/examples/slice.py
index de3bb731..60f3a700 100644
--- a/examples/slice.py
+++ b/examples/slice.py
@@ -17,8 +17,8 @@ if __name__ == "__main__":
graph = Graph()
graph.load("foaf.n3", format="n3")
- for person in graph[: RDF.type: FOAF.Person]:
- friends = list(graph[person: FOAF.knows * "+" / FOAF.name])
+ for person in graph[: RDF.type : FOAF.Person]:
+ friends = list(graph[person : FOAF.knows * "+" / FOAF.name])
if friends:
print(f"{graph.value(person, FOAF.name)}'s circle of friends:")
for name in friends:
diff --git a/examples/sparqlstore_example.py b/examples/sparqlstore_example.py
index 9d9d3fd4..0fe23314 100644
--- a/examples/sparqlstore_example.py
+++ b/examples/sparqlstore_example.py
@@ -25,7 +25,9 @@ if __name__ == "__main__":
# EXAMPLE 2: using a SPARQLStore object directly
st = SPARQLStore(query_endpoint="http://dbpedia.org/sparql")
- for p in st.objects(URIRef("http://dbpedia.org/resource/Brisbane"), dbo.populationTotal):
+ for p in st.objects(
+ URIRef("http://dbpedia.org/resource/Brisbane"), dbo.populationTotal
+ ):
print(
"According to DBPedia, Brisbane has a population of "
"{0:,}".format(int(p), ",d")
@@ -39,6 +41,7 @@ if __name__ == "__main__":
# we are asking DBPedia for 3 skos:Concept instances
count = 0
from rdflib.namespace import RDF, SKOS
+
for s in graph.subjects(predicate=RDF.type, object=SKOS.Concept):
count += 1
print(f"\t- {s}")
@@ -47,5 +50,8 @@ if __name__ == "__main__":
# EXAMPLE 4: using a SPARQL endpoint that requires Basic HTTP authentication
# NOTE: this example won't run since the endpoint isn't live (or real)
- s = SPARQLStore(query_endpoint="http://fake-sparql-endpoint.com/repository/x", auth=("my_username", "my_password"))
+ s = SPARQLStore(
+ query_endpoint="http://fake-sparql-endpoint.com/repository/x",
+ auth=("my_username", "my_password"),
+ )
# do normal Graph things