mustrd 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mustrd/README.adoc +210 -210
- mustrd/TestResult.py +136 -136
- mustrd/logger_setup.py +48 -48
- mustrd/model/catalog-v001.xml +5 -5
- mustrd/model/mustrdShapes.ttl +253 -253
- mustrd/model/mustrdTestShapes.ttl +24 -24
- mustrd/model/ontology.ttl +494 -494
- mustrd/model/test-resources/resources.ttl +60 -60
- mustrd/model/triplestoreOntology.ttl +174 -174
- mustrd/model/triplestoreshapes.ttl +41 -41
- mustrd/mustrd.py +787 -787
- mustrd/mustrdAnzo.py +236 -220
- mustrd/mustrdGraphDb.py +125 -125
- mustrd/mustrdRdfLib.py +56 -56
- mustrd/mustrdTestPlugin.py +327 -328
- mustrd/namespace.py +125 -125
- mustrd/run.py +106 -106
- mustrd/spec_component.py +690 -690
- mustrd/steprunner.py +166 -166
- mustrd/templates/md_ResultList_leaf_template.jinja +18 -18
- mustrd/templates/md_ResultList_template.jinja +8 -8
- mustrd/templates/md_stats_template.jinja +2 -2
- mustrd/test/test_mustrd.py +4 -4
- mustrd/utils.py +38 -38
- {mustrd-0.2.0.dist-info → mustrd-0.2.1.dist-info}/LICENSE +21 -21
- {mustrd-0.2.0.dist-info → mustrd-0.2.1.dist-info}/METADATA +4 -2
- mustrd-0.2.1.dist-info/RECORD +31 -0
- mustrd/mustrdQueryProcessor.py +0 -136
- mustrd-0.2.0.dist-info/RECORD +0 -32
- {mustrd-0.2.0.dist-info → mustrd-0.2.1.dist-info}/WHEEL +0 -0
- {mustrd-0.2.0.dist-info → mustrd-0.2.1.dist-info}/entry_points.txt +0 -0
mustrd/mustrdQueryProcessor.py
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
|
2
|
-
from pyparsing import ParseResults
|
3
|
-
from rdflib import RDF, Graph, URIRef, Variable, Literal, XSD, util, BNode
|
4
|
-
from rdflib.plugins.sparql.parser import parseQuery, parseUpdate
|
5
|
-
from rdflib.plugins.sparql.algebra import translateQuery, translateUpdate, translateAlgebra
|
6
|
-
from rdflib.plugins.sparql.sparql import Query
|
7
|
-
from rdflib.plugins.sparql.parserutils import CompValue, value, Expr
|
8
|
-
from rdflib.namespace import DefinedNamespace, Namespace
|
9
|
-
from rdflib.term import Identifier
|
10
|
-
from typing import Union
|
11
|
-
|
12
|
-
from builtins import list, set, tuple, str
|
13
|
-
|
14
|
-
|
15
|
-
namespace = "https://mustrd.com/query/"
|
16
|
-
|
17
|
-
class MustrdQueryProcessor:
|
18
|
-
original_query : Union [Query, ParseResults]
|
19
|
-
current_query : Union [Query, ParseResults]
|
20
|
-
graph : Graph
|
21
|
-
algebra_mode: bool = False
|
22
|
-
graph_mode: bool = True
|
23
|
-
|
24
|
-
def __init__(self, query_str: str, algebra_mode: bool = False, graph_mode: bool = True):
|
25
|
-
parsetree = parseQuery(query_str)
|
26
|
-
# Init original query to algebra or parsed query
|
27
|
-
self.original_query = (algebra_mode and translateQuery(parsetree)) or parsetree
|
28
|
-
self.current_query = self.original_query
|
29
|
-
self.algebra_mode = algebra_mode
|
30
|
-
self.graph_mode = graph_mode
|
31
|
-
self.graph = Graph()
|
32
|
-
if graph_mode:
|
33
|
-
self.query_to_graph((algebra_mode and self.original_query.algebra) or parsetree._toklist, BNode())
|
34
|
-
|
35
|
-
def query_to_graph(self, part: CompValue, partBnode):
|
36
|
-
if not part or not partBnode:
|
37
|
-
return
|
38
|
-
self.graph.add((partBnode, RDF.type, URIRef(namespace + type(part).__name__)))
|
39
|
-
self.graph.add((partBnode, QUERY.has_class , Literal(str(part.__class__.__name__))))
|
40
|
-
if isinstance(part, CompValue) or isinstance(part, ParseResults):
|
41
|
-
self.graph.add((partBnode, QUERY.name , Literal(part.name)))
|
42
|
-
if isinstance(part, CompValue):
|
43
|
-
for key, sub_part in part.items():
|
44
|
-
sub_part_bnode = BNode()
|
45
|
-
self.graph.add((partBnode, URIRef(namespace + str(key)) , sub_part_bnode))
|
46
|
-
self.query_to_graph(sub_part, sub_part_bnode)
|
47
|
-
elif hasattr(part, '__iter__') and not isinstance(part, Identifier) and not isinstance(part, str):
|
48
|
-
for sub_part in part:
|
49
|
-
sub_part_bnode = BNode()
|
50
|
-
self.graph.add((partBnode, QUERY.has_list , sub_part_bnode))
|
51
|
-
self.query_to_graph(sub_part, sub_part_bnode)
|
52
|
-
elif isinstance(part, Identifier) or isinstance(part, str):
|
53
|
-
self.graph.add((partBnode, QUERY.has_value, Literal(part)))
|
54
|
-
|
55
|
-
def serialize_graph(self):
|
56
|
-
if not self.graph_mode:
|
57
|
-
raise Exception("Not able to execute that function if graph mode is not activated: cannot work with two sources of truth")
|
58
|
-
return self.graph.serialize(format = "ttl")
|
59
|
-
|
60
|
-
def query_graph(self, meta_query: str):
|
61
|
-
if not self.graph_mode:
|
62
|
-
raise Exception("Not able to execute that function if graph mode is not activated: cannot work with two sources of truth")
|
63
|
-
return self.graph.query(meta_query)
|
64
|
-
|
65
|
-
def update(self, meta_query: str):
|
66
|
-
if not self.graph_mode:
|
67
|
-
# Implement update directly on objects: self.current_query
|
68
|
-
pass
|
69
|
-
return self.graph.update(meta_query)
|
70
|
-
|
71
|
-
def get_query(self):
|
72
|
-
if self.graph_mode:
|
73
|
-
roots = self.graph.query("SELECT DISTINCT ?sub WHERE {?sub ?prop ?obj FILTER NOT EXISTS {?s ?p ?sub}}")
|
74
|
-
if len(roots) != 1:
|
75
|
-
raise Exception("query graph has more than one root: invalid")
|
76
|
-
|
77
|
-
for root in roots:
|
78
|
-
new_query = self.graph_to_query(root.sub)
|
79
|
-
if not self.algebra_mode:
|
80
|
-
new_query = ParseResults(toklist=new_query, name=self.original_query.name)
|
81
|
-
new_query = translateQuery(new_query)
|
82
|
-
else:
|
83
|
-
new_query = Query(algebra=new_query, prologue=self.original_query.prologue)
|
84
|
-
else:
|
85
|
-
if not self.algebra_mode:
|
86
|
-
new_query = translateQuery(self.current_query)
|
87
|
-
else:
|
88
|
-
new_query = self.current_query
|
89
|
-
return translateAlgebra(new_query)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
def graph_to_query(self, subject):
|
94
|
-
subject_dict = self.get_subject_dict(subject)
|
95
|
-
if QUERY.has_class in subject_dict:
|
96
|
-
class_name = str(subject_dict[QUERY.has_class])
|
97
|
-
subject_dict.pop(QUERY.has_class)
|
98
|
-
if class_name in globals():
|
99
|
-
clazz = globals()[class_name]
|
100
|
-
if clazz in (CompValue, Expr):
|
101
|
-
comp_name = str(subject_dict[QUERY.name])
|
102
|
-
subject_dict.pop(QUERY.name)
|
103
|
-
subject_dict.pop(RDF.type)
|
104
|
-
new_dict = dict(map(lambda kv: [str(kv[0]).replace(str(QUERY._NS), ""),
|
105
|
-
self.graph_to_query(kv[1])] ,
|
106
|
-
subject_dict.items()))
|
107
|
-
return clazz(comp_name, **new_dict)
|
108
|
-
elif clazz in (set, list, tuple) and QUERY.has_list in subject_dict:
|
109
|
-
return clazz(map(lambda item: self.graph_to_query(item), subject_dict[QUERY.has_list]))
|
110
|
-
elif clazz == ParseResults and QUERY.has_list in subject_dict:
|
111
|
-
return ParseResults(toklist=list(map(lambda item: self.graph_to_query(item), subject_dict[QUERY.has_list])))
|
112
|
-
elif clazz in (Literal, Variable, URIRef, str) and QUERY.has_value in subject_dict:
|
113
|
-
return clazz(str(subject_dict[QUERY.has_value]))
|
114
|
-
|
115
|
-
|
116
|
-
def get_subject_dict(self, subject):
|
117
|
-
dict = {}
|
118
|
-
for key, value in self.graph.predicate_objects(subject):
|
119
|
-
# If key already exists: create or add to a list
|
120
|
-
if key == QUERY.has_list:
|
121
|
-
if key in dict:
|
122
|
-
dict[key].append(value)
|
123
|
-
else:
|
124
|
-
dict[key] = [value]
|
125
|
-
else:
|
126
|
-
dict[key] = value
|
127
|
-
return dict
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
class QUERY(DefinedNamespace):
|
132
|
-
_NS = Namespace("https://mustrd.com/query/")
|
133
|
-
has_class : URIRef
|
134
|
-
has_list : URIRef
|
135
|
-
name : URIRef
|
136
|
-
has_value: URIRef
|
mustrd-0.2.0.dist-info/RECORD
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
mustrd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
mustrd/logger_setup.py,sha256=AXTXiiyQ4E_SyqNaKlLsZlkkKr_YJfJZ0N4PEoN7d7E,1630
|
3
|
-
mustrd/model/catalog-v001.xml,sha256=jgD6VOxR6A8izzr3ZmL4AzaTZ5cVwsvt618MTuRlGBk,386
|
4
|
-
mustrd/model/mustrdShapes.ttl,sha256=BR-9fAwGpQt6glfPpDB0Xx3vFXMt_UTQwi469o6aWUo,9709
|
5
|
-
mustrd/model/mustrdTestOntology.ttl,sha256=W7IRbPKrhpYFweZvc9QH8gdjBiuZMHKETIuHBepLnYw,2034
|
6
|
-
mustrd/model/mustrdTestShapes.ttl,sha256=Bcof6p7MtzO2L6H1DWB1hibLSix7Dxo-z6HlFcG31M8,842
|
7
|
-
mustrd/model/ontology.ttl,sha256=JF6LG5-T7tbi3QfmJcEFQcFo-rQT0CTYGg7PEmuzINY,17303
|
8
|
-
mustrd/model/test-resources/resources.ttl,sha256=7z1P4qJwuqRdmHzKd_mhnUIs-aQoSQxas7yDCwKYarc,1558
|
9
|
-
mustrd/model/triplestoreOntology.ttl,sha256=87leTcKot45AgcCGfJLEwbY9rsuRGHbYbnTFeijrzOk,6199
|
10
|
-
mustrd/model/triplestoreshapes.ttl,sha256=qiLzbclGDzueH5GCKANEwMM9VxOmswu42FiSnITATeQ,1876
|
11
|
-
mustrd/mustrd.py,sha256=H-j5s3qQmcmJ9g39Q9z5z075HJ5iMapM8OcY8HgcwJs,35081
|
12
|
-
mustrd/mustrdAnzo.py,sha256=yGoNf93n9MeKMqef8H0qm-1HKvnKm1PO-spekATL6XM,10632
|
13
|
-
mustrd/mustrdGraphDb.py,sha256=KNXXYyZjYm_IZaeuuxlPBP-XyX9hZ5UvrdxshKnZhwo,5599
|
14
|
-
mustrd/mustrdQueryProcessor.py,sha256=fpEzD0R7rGy2ktOBSiUpNGevxMSVJxKfxnR3BAg4yRk,6357
|
15
|
-
mustrd/mustrdRdfLib.py,sha256=LeS-uArlxQwsM-7lrJyp8O8m-6VgxsR1BlpxsOCNePs,2129
|
16
|
-
mustrd/mustrdTestPlugin.py,sha256=SsTkwrs0n1lvHvuiyQs-z4dsXnjB7p3d6aFWR8_jLV8,15035
|
17
|
-
mustrd/namespace.py,sha256=3zJbdWEji_2SkhasHK3J2UO3am_phNKDwAFk2htXRYM,3765
|
18
|
-
mustrd/README.adoc,sha256=y6tY7YDFB6f-vICYJyPN8n615BKLm49lRqqWFWiqrzg,12620
|
19
|
-
mustrd/run.py,sha256=r3FS_iAuXYpENbbrLfgymGUP4dx-ZGJ_Y2ZvnZdL9dg,4380
|
20
|
-
mustrd/spec_component.py,sha256=bmfHGE_8uy9yIcbvflWnhEeCW9SCbw86k0E22GQAelk,33304
|
21
|
-
mustrd/steprunner.py,sha256=n3k4O2SjsLUEG5QOxLG8Z8D3iH9PJzzR63dIV2KHcBE,7555
|
22
|
-
mustrd/templates/md_ResultList_leaf_template.jinja,sha256=un1XMeNO9xLcry-DmTQ2QoWoTM5Q5CkVUV_LS4O7sHM,526
|
23
|
-
mustrd/templates/md_ResultList_template.jinja,sha256=RrTaPN1obsTEpG5BjQp7BV9iBFzZOXHwslgvyC0hDKY,211
|
24
|
-
mustrd/templates/md_stats_template.jinja,sha256=DlNfH9eoEFVHQmvp6QNbQv36cqRLyBkqG1ITOHb_Yu8,157
|
25
|
-
mustrd/test/test_mustrd.py,sha256=Q2qTTY--I0wfhgHW7hnkIoV3t_sUTXm8xMmirJaFc7o,129
|
26
|
-
mustrd/TestResult.py,sha256=q5BnvRxhfCEEY062rHasnA61AeKR4oXXs5z8lASvx1o,4986
|
27
|
-
mustrd/utils.py,sha256=fuvdLE20MdkJtY5atBiU8-u7sVcq1mzIYF0gTcw1UMk,1424
|
28
|
-
mustrd-0.2.0.dist-info/entry_points.txt,sha256=v7V7sN0_L1aB4Ug_9io5axlQSeJ1C0tNrQWwdXdV58s,50
|
29
|
-
mustrd-0.2.0.dist-info/LICENSE,sha256=OwjAcbL4HsENdMen1iYR23HH7OEn899oCt100xUo0Zo,1099
|
30
|
-
mustrd-0.2.0.dist-info/METADATA,sha256=0_uSxV7kB9BlUOd14aTILn9waE18kPWVueSPzjFp8-I,4130
|
31
|
-
mustrd-0.2.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
-
mustrd-0.2.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|