|
1 | 1 | """ |
2 | 2 | Simple examples showing how to use the SPARQLStore |
3 | 3 | """ |
4 | | -from urllib.request import urlopen |
| 4 | + |
5 | 5 | import sys |
| 6 | +from urllib.request import urlopen |
6 | 7 |
|
7 | 8 | from rdflib import Graph, Namespace, URIRef |
8 | | -from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore, SPARQLStore |
9 | | -from rdflib.term import Identifier, Literal |
10 | 9 | from rdflib.namespace import RDF, SKOS |
| 10 | +from rdflib.plugins.stores.sparqlstore import SPARQLStore, SPARQLUpdateStore |
| 11 | +from rdflib.term import Identifier, Literal |
11 | 12 |
|
12 | 13 | # Shows examples of the useage of SPARQLStore and SPARQLUpdateStore against local SPARQL1.1 endpoint if |
13 | 14 | # available. This assumes SPARQL1.1 query/update endpoints running locally at |
|
39 | 40 | graph.add((dbr.Brisbane, dbo.populationTotal, Literal(2))) |
40 | 41 |
|
41 | 42 | # EXAMPLE Update Store 2: |
42 | | - update_store = SPARQLUpdateStore(query_endpoint="http://localhost:3030/db/sparql", update_endpoint="http://localhost:3030/db/update") |
| 43 | + update_store = SPARQLUpdateStore( |
| 44 | + query_endpoint="http://localhost:3030/db/sparql", |
| 45 | + update_endpoint="http://localhost:3030/db/update", |
| 46 | + ) |
43 | 47 | graph = Graph(store=update_store, identifier="http://dbpedia.org") |
44 | 48 | graph.add((dbr["Category:Capitals_in_Europe"], RDF.type, SKOS.Concept)) |
45 | 49 | graph.add((dbr["Category:Holy_Grail"], RDF.type, SKOS.Concept)) |
46 | 50 | graph.add((dbr["Category:Hospital_ships_of_Japan"], RDF.type, SKOS.Concept)) |
47 | 51 |
|
48 | | - |
49 | 52 | # EXAMPLE Store 1: using a Graph with the Store type string set to "SPARQLStore" |
50 | 53 | graph = Graph("SPARQLStore", identifier="http://dbpedia.org") |
51 | 54 | graph.open("http://localhost:3030/db/sparql") |
|
85 | 88 | if count >= 3: |
86 | 89 | break |
87 | 90 |
|
88 | | - |
89 | 91 | # EXAMPLE Query 4: doing RDFlib triple navigation using a Graph() with a SPARQLStore backend |
90 | 92 | print("Triple navigation using a Graph() with a SPARQLStore backend:") |
91 | 93 | st = SPARQLStore(query_endpoint="http://localhost:3030/db/sparql") |
|
0 commit comments