-
Notifications
You must be signed in to change notification settings - Fork 0
/
sebb_tutorial.py
73 lines (57 loc) · 2.19 KB
/
sebb_tutorial.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import requests
def log_ttl(server: str, input_file_path: str):
'''
Example function to log a TTL file to the SEBB.
'''
with open(input_file_path, mode="r", encoding='utf-8') as file:
data = file.read()
print("Fichero leído con éxito de:", input_file_path)
headers = {
"Content-Type": "text/turtle"
}
response = requests.post(server+"/log", headers=headers, data=data)
if response.status_code == 200:
print("POST realizado con éxito")
else:
print(f"Error en POST: {response.status_code} - {response.text}")
def get_graph(server: str, output_file_path: str):
'''
Example function to download the complete graph stored in the SEBB
'''
print("Requesting graph...")
response = requests.get(server+"/get_graph")
if response.status_code == 200:
# print(response.text)
with open(output_file_path, mode="w", encoding='utf-8') as file:
file.write(response.text)
print("Fichero descargado con éxito en:", output_file_path)
else:
print(f"Error en GET: {response.status_code} - {response.text}")
if __name__ == '__main__':
# SEBB URI
server = "http://127.0.0.1:5000"
# Log full ontologies to SEBB
models = [
"example-data/amor.ttl",
"example-data/mft.ttl",
"example-data/bhv.ttl",
"example-data/amor-mft.ttl",
"example-data/amor-bhv.ttl"
]
for model in models:
log_ttl(server, model)
# Log a new ontology plenty of individuals
input_ttl_file = "example-data/amor-examples.ttl"
log_ttl(server, input_ttl_file)
# TODO fix the duplication of blank nodes (try with rdflib.ConjuctiveGraph)
'''
v0.1 works if the duplicated triples are related with BlankNodes.
If there are some blank nodes duplicated, there will appear duplicated
in the downloaded graph.
'''
# Log a few triples (no ontology), some of them are duplicated.
input_ttl_file = "example-data/new-triples.ttl"
log_ttl(server, input_ttl_file)
# Download the complete graph stored in the SEBB
output_ttl_file = "graph.ttl"
get_graph(server, output_ttl_file)