-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_graph.py
More file actions
35 lines (28 loc) · 943 Bytes
/
load_graph.py
File metadata and controls
35 lines (28 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
from rdflib import Graph
g = Graph()
g.parse("data/northwind-ontology.ttl", format="turtle")
g.parse("data/dumpdataNTRIPLE7.nt", format="nt")
print(f"Graph has {len(g)} triples.")
if len(sys.argv) < 3:
print("Usage: python load_graph.py <ENTITY_TYPE> <ENTITY_CODE>")
sys.exit(1)
entity_type = sys.argv[1].strip().lower()
entity_number_or_name = sys.argv[2]
if entity_type != "customer" and not entity_number_or_name.isdigit():
print("Error: Entity number must be numeric for types other than 'customer'.")
sys.exit(1)
query = f'''
PREFIX : <http://www.mysparql.com/resource/northwind/>
SELECT ?s ?p ?o WHERE {{
?s ?p ?o .
FILTER(?s = :{entity_type}-{entity_number_or_name})
}}
'''
results = g.query(query)
found = False
for row in results:
print(f"{row['s']}, {row['p']}, {row['o']}")
found = True
if not found:
print(f"No results found for {entity_type} number {entity_number_or_name}.")