-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (36 loc) · 978 Bytes
/
main.py
File metadata and controls
51 lines (36 loc) · 978 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import morph_kgc
import os
import wget
#clean old mapping
os.system("rm mapping.ttl")
# download mapping
url='https://raw.githubusercontent.com/jatoledo/KG/main/mapping.ttl'
wget.download(url)
#generate log from Docker inspect
os.system("docker inspect $(docker images -a -q) >data.json")
# configuration file
config = """
[CONFIGURATION]
output_dir=
output_file=result
[DataSourceJSON]
file_path=data.json
mappings=mapping.ttl"""
# generate the triples and load them to an RDFlib graph
graph = morph_kgc.materialize(config)
# work with the graph
graph.query(' SELECT DISTINCT ?classes WHERE { ?s a ?classes } ')
graph.serialize(destination='result.ttl', format='turtle')
#os.system("java -jar rmlmapper-4.15.0-r361-all.jar -m mapping.ttl -o result.ttl")
# Sparql query
import rdflib
g = rdflib.Graph()
g.parse("result.ttl",format="turtle")
knows_query = """
SELECT *
WHERE {
?s ?p ?o.
}"""
qres = g.query(knows_query)
for row in qres:
print(f"{row.s}")