-
Notifications
You must be signed in to change notification settings - Fork 31
/
woql_query.py
47 lines (35 loc) · 1.34 KB
/
woql_query.py
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
36
37
38
39
40
41
42
43
44
45
46
47
import pprint as pp
from terminusdb_client import Client
from terminusdb_client import WOQLQuery as wq
# For Terminus X, use the following
# client = Client("https://cloud.terminusdb.com/<Your Team>/")
# client.connect(db="demo_workshop", team="<Your Team>", use_token=True)
client = Client("http://127.0.0.1:6363/")
client.connect(db="getting_started")
### Uncomment to see all triples ##
# pp.pprint(wq().star().execute(client))
darci = wq().string("Darci Prosser")
query = wq().triple("v:person", "@schema:name", darci) + wq().triple(
"v:person", "@schema:contact_number", "v:phone_num"
)
result = query.execute(client)
if result["bindings"]:
print("Darci's contact number:")
print(result["bindings"][0]["phone_num"]["@value"])
else:
print("Cannot find result.")
print("=== Darci is on holiday ===")
query = (
wq().triple("v:person", "@schema:name", darci)
+ wq().triple("v:person", "@schema:manager", "v:manager")
+ wq().triple("v:manager", "@schema:contact_number", "v:phone_num")
+ wq().triple("v:manager", "@schema:name", "v:manager_name")
)
result = query.execute(client)
if result["bindings"]:
print("Manager's name:")
print(result["bindings"][0]["manager_name"]["@value"])
print("Manager's contact number:")
print(result["bindings"][0]["phone_num"]["@value"])
else:
print("Cannot find result.")