cognite-neat 0.88.0__py3-none-any.whl → 0.88.2__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.

Potentially problematic release.


This version of cognite-neat might be problematic. Click here for more details.

Files changed (99) hide show
  1. cognite/neat/_version.py +1 -1
  2. cognite/neat/app/api/routers/configuration.py +1 -1
  3. cognite/neat/app/ui/neat-app/build/asset-manifest.json +7 -7
  4. cognite/neat/app/ui/neat-app/build/index.html +1 -1
  5. cognite/neat/app/ui/neat-app/build/static/css/{main.38a62222.css → main.72e3d92e.css} +2 -2
  6. cognite/neat/app/ui/neat-app/build/static/css/main.72e3d92e.css.map +1 -0
  7. cognite/neat/app/ui/neat-app/build/static/js/main.5a52cf09.js +3 -0
  8. cognite/neat/app/ui/neat-app/build/static/js/{main.ec7f72e2.js.LICENSE.txt → main.5a52cf09.js.LICENSE.txt} +0 -9
  9. cognite/neat/app/ui/neat-app/build/static/js/main.5a52cf09.js.map +1 -0
  10. cognite/neat/config.py +44 -27
  11. cognite/neat/exceptions.py +8 -2
  12. cognite/neat/graph/extractors/_classic_cdf/_assets.py +21 -73
  13. cognite/neat/graph/extractors/_classic_cdf/_base.py +102 -0
  14. cognite/neat/graph/extractors/_classic_cdf/_events.py +46 -42
  15. cognite/neat/graph/extractors/_classic_cdf/_files.py +41 -45
  16. cognite/neat/graph/extractors/_classic_cdf/_labels.py +75 -52
  17. cognite/neat/graph/extractors/_classic_cdf/_relationships.py +49 -27
  18. cognite/neat/graph/extractors/_classic_cdf/_sequences.py +47 -50
  19. cognite/neat/graph/extractors/_classic_cdf/_timeseries.py +47 -49
  20. cognite/neat/graph/loaders/_base.py +4 -4
  21. cognite/neat/graph/loaders/_rdf2asset.py +12 -14
  22. cognite/neat/graph/loaders/_rdf2dms.py +14 -10
  23. cognite/neat/graph/queries/_base.py +22 -29
  24. cognite/neat/graph/queries/_shared.py +1 -1
  25. cognite/neat/graph/stores/_base.py +19 -11
  26. cognite/neat/graph/transformers/_rdfpath.py +3 -2
  27. cognite/neat/issues/__init__.py +16 -0
  28. cognite/neat/{issues.py → issues/_base.py} +78 -2
  29. cognite/neat/issues/errors/external.py +21 -0
  30. cognite/neat/issues/errors/properties.py +75 -0
  31. cognite/neat/issues/errors/resources.py +123 -0
  32. cognite/neat/issues/errors/schema.py +0 -0
  33. cognite/neat/{rules/issues → issues}/formatters.py +9 -9
  34. cognite/neat/issues/neat_warnings/__init__.py +2 -0
  35. cognite/neat/issues/neat_warnings/identifier.py +27 -0
  36. cognite/neat/issues/neat_warnings/models.py +22 -0
  37. cognite/neat/issues/neat_warnings/properties.py +77 -0
  38. cognite/neat/issues/neat_warnings/resources.py +125 -0
  39. cognite/neat/rules/exporters/_rules2dms.py +3 -2
  40. cognite/neat/rules/exporters/_rules2ontology.py +28 -20
  41. cognite/neat/rules/exporters/_validation.py +15 -21
  42. cognite/neat/rules/importers/__init__.py +7 -3
  43. cognite/neat/rules/importers/_base.py +3 -3
  44. cognite/neat/rules/importers/_dms2rules.py +39 -18
  45. cognite/neat/rules/importers/_dtdl2rules/dtdl_converter.py +44 -53
  46. cognite/neat/rules/importers/_dtdl2rules/dtdl_importer.py +6 -5
  47. cognite/neat/rules/importers/_rdf/__init__.py +0 -0
  48. cognite/neat/rules/importers/_rdf/_imf2rules/__init__.py +3 -0
  49. cognite/neat/rules/importers/_rdf/_imf2rules/_imf2classes.py +82 -0
  50. cognite/neat/rules/importers/_rdf/_imf2rules/_imf2metadata.py +34 -0
  51. cognite/neat/rules/importers/_rdf/_imf2rules/_imf2properties.py +123 -0
  52. cognite/neat/rules/importers/{_owl2rules/_owl2rules.py → _rdf/_imf2rules/_imf2rules.py} +15 -11
  53. cognite/neat/rules/importers/{_inference2rules.py → _rdf/_inference2rules.py} +1 -1
  54. cognite/neat/rules/importers/_rdf/_owl2rules/_owl2classes.py +57 -0
  55. cognite/neat/rules/importers/_rdf/_owl2rules/_owl2metadata.py +68 -0
  56. cognite/neat/rules/importers/_rdf/_owl2rules/_owl2properties.py +59 -0
  57. cognite/neat/rules/importers/_rdf/_owl2rules/_owl2rules.py +76 -0
  58. cognite/neat/rules/importers/_rdf/_shared.py +586 -0
  59. cognite/neat/rules/importers/_spreadsheet2rules.py +31 -28
  60. cognite/neat/rules/importers/_yaml2rules.py +2 -1
  61. cognite/neat/rules/issues/__init__.py +1 -5
  62. cognite/neat/rules/issues/base.py +2 -21
  63. cognite/neat/rules/issues/dms.py +20 -134
  64. cognite/neat/rules/issues/ontology.py +298 -0
  65. cognite/neat/rules/issues/spreadsheet.py +51 -3
  66. cognite/neat/rules/issues/tables.py +72 -0
  67. cognite/neat/rules/models/_rdfpath.py +4 -4
  68. cognite/neat/rules/models/_types/_field.py +14 -21
  69. cognite/neat/rules/models/asset/_validation.py +1 -1
  70. cognite/neat/rules/models/dms/_schema.py +53 -30
  71. cognite/neat/rules/models/dms/_validation.py +2 -2
  72. cognite/neat/rules/models/entities.py +3 -0
  73. cognite/neat/rules/models/information/_rules.py +5 -4
  74. cognite/neat/rules/models/information/_validation.py +1 -1
  75. cognite/neat/utils/rdf_.py +17 -9
  76. cognite/neat/utils/regex_patterns.py +52 -0
  77. cognite/neat/workflows/steps/lib/current/rules_importer.py +73 -1
  78. cognite/neat/workflows/steps/lib/current/rules_validator.py +19 -7
  79. {cognite_neat-0.88.0.dist-info → cognite_neat-0.88.2.dist-info}/METADATA +2 -6
  80. {cognite_neat-0.88.0.dist-info → cognite_neat-0.88.2.dist-info}/RECORD +85 -72
  81. cognite/neat/app/ui/neat-app/build/static/css/main.38a62222.css.map +0 -1
  82. cognite/neat/app/ui/neat-app/build/static/js/main.ec7f72e2.js +0 -3
  83. cognite/neat/app/ui/neat-app/build/static/js/main.ec7f72e2.js.map +0 -1
  84. cognite/neat/graph/issues/loader.py +0 -104
  85. cognite/neat/graph/stores/_oxrdflib.py +0 -247
  86. cognite/neat/rules/exceptions.py +0 -2972
  87. cognite/neat/rules/importers/_owl2rules/_owl2classes.py +0 -215
  88. cognite/neat/rules/importers/_owl2rules/_owl2metadata.py +0 -213
  89. cognite/neat/rules/importers/_owl2rules/_owl2properties.py +0 -203
  90. cognite/neat/rules/issues/importing.py +0 -408
  91. cognite/neat/rules/models/_types/_base.py +0 -16
  92. cognite/neat/workflows/examples/Export_Rules_to_Ontology/workflow.yaml +0 -152
  93. cognite/neat/workflows/examples/Extract_DEXPI_Graph_and_Export_Rules/workflow.yaml +0 -139
  94. cognite/neat/workflows/examples/Ontology_to_Data_Model/workflow.yaml +0 -116
  95. /cognite/neat/{graph/issues → issues/errors}/__init__.py +0 -0
  96. /cognite/neat/rules/importers/{_owl2rules → _rdf/_owl2rules}/__init__.py +0 -0
  97. {cognite_neat-0.88.0.dist-info → cognite_neat-0.88.2.dist-info}/LICENSE +0 -0
  98. {cognite_neat-0.88.0.dist-info → cognite_neat-0.88.2.dist-info}/WHEEL +0 -0
  99. {cognite_neat-0.88.0.dist-info → cognite_neat-0.88.2.dist-info}/entry_points.txt +0 -0
@@ -1,104 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Any
3
-
4
- from cognite.neat.issues import NeatError, NeatWarning
5
-
6
- __all__ = [
7
- "FailedAuthorizationError",
8
- "MissingDataModelError",
9
- "FailedConvertError",
10
- "InvalidClassWarning",
11
- "InvalidInstanceError",
12
- ]
13
-
14
-
15
- @dataclass(frozen=True)
16
- class FailedAuthorizationError(NeatError):
17
- description = "Missing authorization for {action}: {reason}"
18
-
19
- action: str
20
- reason: str
21
-
22
- def message(self) -> str:
23
- return self.description.format(action=self.action, reason=self.reason)
24
-
25
- def dump(self) -> dict[str, Any]:
26
- output = super().dump()
27
- output["action"] = self.action
28
- output["reason"] = self.reason
29
- return output
30
-
31
-
32
- @dataclass(frozen=True)
33
- class MissingDataModelError(NeatError):
34
- description = "The data model with identifier {identifier} is missing: {reason}"
35
- fix = "Check the data model identifier and try again."
36
-
37
- identifier: str
38
- reason: str
39
-
40
- def message(self) -> str:
41
- return self.description.format(identifier=self.identifier, reason=self.reason)
42
-
43
- def dump(self) -> dict[str, Any]:
44
- output = super().dump()
45
- output["identifier"] = self.identifier
46
- output["reason"] = self.reason
47
- return output
48
-
49
-
50
- @dataclass(frozen=True)
51
- class FailedConvertError(NeatError):
52
- description = "Failed to convert the {identifier} to {target_format}: {reason}"
53
- fix = "Check the error message and correct the rules."
54
- identifier: str
55
- target_format: str
56
- reason: str
57
-
58
- def message(self) -> str:
59
- return self.description.format(identifier=self.identifier, target_format=self.target_format, reason=self.reason)
60
-
61
- def dump(self) -> dict[str, Any]:
62
- output = super().dump()
63
- output["identifier"] = self.identifier
64
- output["targetFormat"] = self.target_format
65
- output["reason"] = self.reason
66
- return output
67
-
68
-
69
- @dataclass(frozen=True)
70
- class InvalidClassWarning(NeatWarning):
71
- description = "The class {class_name} is invalid and will be skipped. {reason}"
72
- fix = "Check the error message and correct the class."
73
-
74
- class_name: str
75
- reason: str
76
-
77
- def message(self) -> str:
78
- return self.description.format(class_name=self.class_name, reason=self.reason)
79
-
80
- def dump(self) -> dict[str, Any]:
81
- output = super().dump()
82
- output["class_name"] = self.class_name
83
- output["reason"] = self.reason
84
- return output
85
-
86
-
87
- @dataclass(frozen=True)
88
- class InvalidInstanceError(NeatError):
89
- description = "The {type_} with identifier {identifier} is invalid and will be skipped. {reason}"
90
- fix = "Check the error message and correct the instance."
91
-
92
- type_: str
93
- identifier: str
94
- reason: str
95
-
96
- def message(self) -> str:
97
- return self.description.format(type_=self.type_, identifier=self.identifier, reason=self.reason)
98
-
99
- def dump(self) -> dict[str, Any]:
100
- output = super().dump()
101
- output["type"] = self.type_
102
- output["identifier"] = self.identifier
103
- output["reason"] = self.reason
104
- return output
@@ -1,247 +0,0 @@
1
- import shutil
2
- from collections.abc import Generator, Iterable, Iterator, Mapping
3
- from typing import Any, cast
4
-
5
- import pyoxigraph as ox
6
- from rdflib import Graph
7
- from rdflib.graph import DATASET_DEFAULT_GRAPH_ID
8
- from rdflib.plugins.sparql.sparql import Query, Update
9
- from rdflib.query import Result
10
- from rdflib.store import VALID_STORE, Store
11
- from rdflib.term import BNode, Identifier, Literal, Node, URIRef, Variable
12
-
13
- __all__ = ["OxigraphStore"]
14
-
15
- from typing import TypeAlias
16
-
17
- _Triple: TypeAlias = tuple[Node, Node, Node]
18
- _Quad: TypeAlias = tuple[Node, Node, Node, Graph]
19
- _TriplePattern: TypeAlias = tuple[Node | None, Node | None, Node | None]
20
-
21
-
22
- class OxigraphStore(Store):
23
- context_aware: bool = True
24
- formula_aware: bool = False
25
- transaction_aware: bool = False
26
- graph_aware: bool = True
27
-
28
- def __init__(
29
- self, configuration: str | None = None, identifier: Identifier | None = None, *, store: ox.Store | None = None
30
- ):
31
- self._store = store
32
- self._prefix_for_namespace: dict[URIRef, str] = {}
33
- self._namespace_for_prefix: dict[str, URIRef] = {}
34
- super().__init__(configuration, identifier)
35
-
36
- def open(self, configuration: str, create: bool = False) -> int | None:
37
- if self._store is not None:
38
- raise ValueError("The open function should be called before any RDF operation")
39
- self._store = ox.Store(configuration)
40
- return VALID_STORE
41
-
42
- def close(self, commit_pending_transaction: bool = False) -> None:
43
- del self._store
44
-
45
- def destroy(self, configuration: str) -> None:
46
- shutil.rmtree(configuration)
47
-
48
- def gc(self) -> None:
49
- pass
50
-
51
- @property
52
- def _inner(self) -> ox.Store:
53
- if self._store is None:
54
- self._store = ox.Store()
55
- return self._store
56
-
57
- def add(self, triple: _Triple, context: Graph, quoted: bool = False) -> None:
58
- if quoted:
59
- raise ValueError("Oxigraph stores are not formula aware")
60
- self._inner.add(_to_ox(triple, context))
61
- super().add(triple, context, quoted)
62
-
63
- def addN(self, quads: Iterable[_Quad]) -> None:
64
- self._inner.extend([_to_ox(q) for q in quads])
65
- for quad in quads:
66
- (s, p, o, g) = quad
67
- super().add((s, p, o), g)
68
-
69
- def remove(self, triple: _TriplePattern, context: Graph | None = None) -> None:
70
- for q in self._inner.quads_for_pattern(*_to_ox_quad_pattern(triple, context)):
71
- self._inner.remove(q)
72
- super().remove(triple, context)
73
-
74
- def triples(
75
- self, triple_pattern: _TriplePattern, context: Graph | None = None
76
- ) -> Iterator[tuple[_Triple, Iterator[Graph | None]]]:
77
- return (_from_ox(q) for q in self._inner.quads_for_pattern(*_to_ox_quad_pattern(triple_pattern, context)))
78
-
79
- def __len__(self, context: Graph | None = None) -> int:
80
- if context is None:
81
- # TODO: very bad
82
- return len({q.triple for q in self._inner})
83
- return sum(1 for _ in self._inner.quads_for_pattern(None, None, None, _to_ox(context)))
84
-
85
- def contexts(self, triple: _Triple | None = None) -> Generator[Graph, None, None]:
86
- if triple is None:
87
- return (_from_ox(g) for g in self._inner.named_graphs())
88
- return (_from_ox(q[3]) for q in self._inner.quads_for_pattern(*_to_ox_quad_pattern(triple)))
89
-
90
- def query(
91
- self,
92
- query: Query | str,
93
- initNs: Mapping[str, Any],
94
- initBindings: Mapping[str, Identifier],
95
- queryGraph: str,
96
- **kwargs: Any,
97
- ) -> "Result":
98
- if isinstance(queryGraph, Query) or kwargs:
99
- raise NotImplementedError
100
- init_ns = dict(self._namespace_for_prefix, **initNs)
101
- if isinstance(query, Query):
102
- query = str(query)
103
- query = "".join(f"PREFIX {prefix}: <{namespace}>\n" for prefix, namespace in init_ns.items()) + query
104
- if initBindings:
105
- # Todo Anders: This is likely a bug as .n3 is not valid the Identifier.
106
- # There are no tests reaching this code.
107
- query += "\nVALUES ( {} ) {{ ({}) }}".format(
108
- " ".join(f"?{k}" for k in initBindings),
109
- " ".join(v.n3() for v in initBindings.values()), # type: ignore[attr-defined]
110
- )
111
- result = self._inner.query(
112
- query,
113
- use_default_graph_as_union=queryGraph == "__UNION__",
114
- default_graph=_to_ox(queryGraph) if isinstance(queryGraph, Node) else None,
115
- )
116
- if isinstance(result, bool):
117
- out = Result("ASK")
118
- out.askAnswer = result
119
- elif isinstance(result, ox.QuerySolutions):
120
- out = Result("SELECT")
121
- out.vars = [Variable(v.value) for v in result.variables]
122
- out.bindings = [
123
- {v: _from_ox(val) for v, val in zip(out.vars, solution, strict=False)} for solution in result
124
- ]
125
- elif isinstance(result, ox.QueryTriples):
126
- out = Result("CONSTRUCT")
127
- out.graph = Graph()
128
- out.graph += (_from_ox(t) for t in result)
129
- else:
130
- raise ValueError(f"Unexpected query result: {result}")
131
- return out
132
-
133
- def update(
134
- self,
135
- update: Update | str,
136
- initNs: Mapping[str, Any],
137
- initBindings: Mapping[str, Identifier],
138
- queryGraph: str,
139
- **kwargs: Any,
140
- ) -> None:
141
- raise NotImplementedError
142
-
143
- def commit(self) -> None:
144
- # TODO: implement
145
- pass
146
-
147
- def rollback(self) -> None:
148
- # TODO: implement
149
- pass
150
-
151
- def add_graph(self, graph: Graph) -> None:
152
- self._inner.add_graph(_to_ox(graph))
153
-
154
- def remove_graph(self, graph: Graph) -> None:
155
- self._inner.remove_graph(_to_ox(graph))
156
-
157
- def bind(self, prefix: str, namespace: URIRef, override: bool = True) -> None:
158
- if not override and (prefix in self._namespace_for_prefix or namespace in self._prefix_for_namespace):
159
- return # nothing to do
160
- self._delete_from_prefix(prefix)
161
- self._delete_from_namespace(namespace)
162
- self._namespace_for_prefix[prefix] = namespace
163
- self._prefix_for_namespace[namespace] = prefix
164
-
165
- def _delete_from_prefix(self, prefix):
166
- if prefix not in self._namespace_for_prefix:
167
- return
168
- namespace = self._namespace_for_prefix[prefix]
169
- del self._namespace_for_prefix[prefix]
170
- self._delete_from_namespace(namespace)
171
-
172
- def _delete_from_namespace(self, namespace):
173
- if namespace not in self._prefix_for_namespace:
174
- return
175
- prefix = self._prefix_for_namespace[namespace]
176
- del self._prefix_for_namespace[namespace]
177
- self._delete_from_prefix(prefix)
178
-
179
- def prefix(self, namespace: URIRef) -> str | None:
180
- return self._prefix_for_namespace.get(namespace)
181
-
182
- def namespace(self, prefix: str) -> URIRef | None:
183
- return self._namespace_for_prefix.get(prefix)
184
-
185
- def namespaces(self) -> Iterator[tuple[str, URIRef]]:
186
- yield from self._namespace_for_prefix.items()
187
-
188
-
189
- def _to_ox(term: Node | _Triple | _Quad | Graph, context: Graph | None = None):
190
- if term is None:
191
- return None
192
- elif term == DATASET_DEFAULT_GRAPH_ID:
193
- return ox.DefaultGraph()
194
- elif isinstance(term, URIRef):
195
- return ox.NamedNode(term)
196
- elif isinstance(term, BNode):
197
- return ox.BlankNode(term)
198
- elif isinstance(term, Literal):
199
- return ox.Literal(term, language=term.language, datatype=ox.NamedNode(term.datatype) if term.datatype else None)
200
- elif isinstance(term, Graph):
201
- return _to_ox(term.identifier)
202
- elif isinstance(term, tuple) and len(term) == 3 and isinstance(context, Graph):
203
- triple = cast(_Triple, term)
204
- return ox.Quad(_to_ox(triple[0]), _to_ox(triple[1]), _to_ox(triple[2]), _to_ox(context))
205
- elif isinstance(term, tuple) and len(term) == 4:
206
- quad = cast(_Quad, term)
207
- return ox.Quad(_to_ox(quad[0]), _to_ox(quad[1]), _to_ox(quad[2]), _to_ox(quad[3]))
208
- raise ValueError(f"Unexpected rdflib term: {term!r}")
209
-
210
-
211
- def _to_ox_quad_pattern(triple: _TriplePattern, context: Graph | None = None):
212
- (s, p, o) = triple
213
- return _to_ox_term_pattern(s), _to_ox_term_pattern(p), _to_ox_term_pattern(o), _to_ox_term_pattern(context)
214
-
215
-
216
- def _to_ox_term_pattern(term):
217
- if term is None:
218
- return None
219
- if isinstance(term, URIRef):
220
- return ox.NamedNode(term)
221
- elif isinstance(term, BNode):
222
- return ox.BlankNode(term)
223
- elif isinstance(term, Literal):
224
- return ox.Literal(term, language=term.language, datatype=ox.NamedNode(term.datatype) if term.datatype else None)
225
- elif isinstance(term, Graph):
226
- return _to_ox(term.identifier)
227
- raise ValueError(f"Unexpected rdflib term: {term!r}")
228
-
229
-
230
- def _from_ox(term):
231
- if term is None:
232
- return None
233
- if isinstance(term, ox.NamedNode):
234
- return URIRef(term.value)
235
- if isinstance(term, ox.BlankNode):
236
- return BNode(term.value)
237
- if isinstance(term, ox.Literal):
238
- if term.language:
239
- return Literal(term.value, lang=term.language)
240
- return Literal(term.value, datatype=URIRef(term.datatype.value))
241
- if isinstance(term, ox.DefaultGraph):
242
- return None
243
- if isinstance(term, ox.Triple):
244
- return _from_ox(term.subject), _from_ox(term.predicate), _from_ox(term.object)
245
- if isinstance(term, ox.Quad):
246
- return (_from_ox(term.subject), _from_ox(term.predicate), _from_ox(term.object)), _from_ox(term.graph_name)
247
- raise ValueError(f"Unexpected Oxigraph term: {term!r}")