cognite-neat 0.99.0__py3-none-any.whl → 0.99.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.
Potentially problematic release.
This version of cognite-neat might be problematic. Click here for more details.
- cognite/neat/_client/_api/data_modeling_loaders.py +77 -4
- cognite/neat/_client/_api/schema.py +63 -2
- cognite/neat/_client/data_classes/schema.py +2 -348
- cognite/neat/_constants.py +27 -4
- cognite/neat/_graph/extractors/_classic_cdf/_classic.py +5 -5
- cognite/neat/_graph/loaders/_rdf2dms.py +2 -2
- cognite/neat/_graph/transformers/_classic_cdf.py +24 -13
- cognite/neat/_issues/_base.py +26 -17
- cognite/neat/_issues/errors/__init__.py +4 -2
- cognite/neat/_issues/errors/_external.py +7 -0
- cognite/neat/_issues/errors/_properties.py +2 -7
- cognite/neat/_issues/errors/_resources.py +1 -1
- cognite/neat/_issues/warnings/__init__.py +4 -2
- cognite/neat/_issues/warnings/_external.py +9 -1
- cognite/neat/_issues/warnings/_resources.py +26 -2
- cognite/neat/_issues/warnings/user_modeling.py +4 -4
- cognite/neat/_rules/_constants.py +2 -6
- cognite/neat/_rules/exporters/_rules2dms.py +4 -6
- cognite/neat/_rules/importers/__init__.py +1 -3
- cognite/neat/_rules/importers/_base.py +1 -1
- cognite/neat/_rules/importers/_dms2rules.py +3 -25
- cognite/neat/_rules/importers/_rdf/__init__.py +5 -0
- cognite/neat/_rules/importers/_rdf/_base.py +34 -11
- cognite/neat/_rules/importers/_rdf/_imf2rules.py +91 -0
- cognite/neat/_rules/importers/_rdf/_inference2rules.py +18 -2
- cognite/neat/_rules/importers/_rdf/_owl2rules.py +80 -0
- cognite/neat/_rules/importers/_rdf/_shared.py +138 -441
- cognite/neat/_rules/models/dms/__init__.py +2 -0
- cognite/neat/_rules/models/dms/_exporter.py +32 -30
- cognite/neat/_rules/models/dms/_rules.py +3 -45
- cognite/neat/_rules/models/dms/_validation.py +389 -122
- cognite/neat/_rules/models/information/__init__.py +2 -0
- cognite/neat/_rules/models/information/_rules.py +0 -59
- cognite/neat/_rules/models/information/_validation.py +9 -9
- cognite/neat/_rules/models/mapping/_classic2core.py +1 -1
- cognite/neat/_rules/models/mapping/_classic2core.yaml +8 -4
- cognite/neat/_rules/transformers/_pipelines.py +1 -1
- cognite/neat/_rules/transformers/_verification.py +29 -4
- cognite/neat/_session/_base.py +16 -41
- cognite/neat/_session/_prepare.py +6 -5
- cognite/neat/_session/_to.py +5 -2
- cognite/neat/_session/exceptions.py +4 -0
- cognite/neat/_utils/rdf_.py +6 -4
- cognite/neat/_version.py +1 -1
- cognite/neat/_workflows/steps/lib/current/rules_exporter.py +0 -88
- cognite/neat/_workflows/steps/lib/current/rules_importer.py +2 -16
- cognite/neat/_workflows/steps/lib/current/rules_validator.py +3 -5
- {cognite_neat-0.99.0.dist-info → cognite_neat-0.99.1.dist-info}/METADATA +1 -1
- {cognite_neat-0.99.0.dist-info → cognite_neat-0.99.1.dist-info}/RECORD +52 -60
- cognite/neat/_rules/importers/_rdf/_imf2rules/__init__.py +0 -3
- cognite/neat/_rules/importers/_rdf/_imf2rules/_imf2classes.py +0 -86
- cognite/neat/_rules/importers/_rdf/_imf2rules/_imf2metadata.py +0 -29
- cognite/neat/_rules/importers/_rdf/_imf2rules/_imf2properties.py +0 -130
- cognite/neat/_rules/importers/_rdf/_imf2rules/_imf2rules.py +0 -154
- cognite/neat/_rules/importers/_rdf/_owl2rules/__init__.py +0 -3
- cognite/neat/_rules/importers/_rdf/_owl2rules/_owl2classes.py +0 -58
- cognite/neat/_rules/importers/_rdf/_owl2rules/_owl2metadata.py +0 -65
- cognite/neat/_rules/importers/_rdf/_owl2rules/_owl2properties.py +0 -59
- cognite/neat/_rules/importers/_rdf/_owl2rules/_owl2rules.py +0 -39
- {cognite_neat-0.99.0.dist-info → cognite_neat-0.99.1.dist-info}/LICENSE +0 -0
- {cognite_neat-0.99.0.dist-info → cognite_neat-0.99.1.dist-info}/WHEEL +0 -0
- {cognite_neat-0.99.0.dist-info → cognite_neat-0.99.1.dist-info}/entry_points.txt +0 -0
|
@@ -20,6 +20,7 @@ from cognite.neat._client.data_classes.data_modeling import (
|
|
|
20
20
|
ViewApplyDict,
|
|
21
21
|
)
|
|
22
22
|
from cognite.neat._client.data_classes.schema import DMSSchema
|
|
23
|
+
from cognite.neat._constants import COGNITE_SPACES
|
|
23
24
|
from cognite.neat._issues.errors import NeatTypeError, ResourceNotFoundError
|
|
24
25
|
from cognite.neat._issues.warnings import NotSupportedWarning, PropertyNotFoundWarning
|
|
25
26
|
from cognite.neat._issues.warnings.user_modeling import (
|
|
@@ -54,19 +55,13 @@ class _DMSExporter:
|
|
|
54
55
|
include_pipeline (bool): If True, the pipeline will be included with the schema. Pipeline means the
|
|
55
56
|
raw tables and transformations necessary to populate the data model.
|
|
56
57
|
instance_space (str): The space to use for the instance. Defaults to None,`Rules.metadata.space` will be used
|
|
58
|
+
remove_cdf_spaces(bool): The
|
|
57
59
|
"""
|
|
58
60
|
|
|
59
|
-
def __init__(self, rules: DMSRules, instance_space: str | None = None):
|
|
61
|
+
def __init__(self, rules: DMSRules, instance_space: str | None = None, remove_cdf_spaces: bool = False):
|
|
60
62
|
self.instance_space = instance_space
|
|
61
63
|
self.rules = rules
|
|
62
|
-
self.
|
|
63
|
-
if self._ref_schema:
|
|
64
|
-
# We skip version as that will always be missing in the reference
|
|
65
|
-
self._ref_views_by_id = {
|
|
66
|
-
dm.ViewId(view.space, view.external_id): view for view in self._ref_schema.views.values()
|
|
67
|
-
}
|
|
68
|
-
else:
|
|
69
|
-
self._ref_views_by_id = {} # type: ignore
|
|
64
|
+
self.remove_cdf_spaces = remove_cdf_spaces
|
|
70
65
|
|
|
71
66
|
def to_schema(self) -> DMSSchema:
|
|
72
67
|
rules = self.rules
|
|
@@ -78,7 +73,7 @@ class _DMSExporter:
|
|
|
78
73
|
view_properties_by_id, rules.views
|
|
79
74
|
)
|
|
80
75
|
|
|
81
|
-
views = self.
|
|
76
|
+
views = self._create_views(view_properties_by_id, view_properties_with_ancestors_by_id)
|
|
82
77
|
view_node_type_filters: set[dm.NodeId] = set()
|
|
83
78
|
for dms_view in rules.views:
|
|
84
79
|
if isinstance(dms_view.filter_, NodeTypeFilter):
|
|
@@ -89,21 +84,22 @@ class _DMSExporter:
|
|
|
89
84
|
+ [dm.NodeApply(node.space, node.external_id) for node in view_node_type_filters]
|
|
90
85
|
)
|
|
91
86
|
else:
|
|
92
|
-
node_types = NodeApplyDict(
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
node_types = NodeApplyDict(
|
|
88
|
+
[
|
|
89
|
+
dm.NodeApply(node.space, node.external_id)
|
|
90
|
+
for node in view_node_type_filters
|
|
91
|
+
if not (self.remove_cdf_spaces and node.space in COGNITE_SPACES)
|
|
92
|
+
]
|
|
93
|
+
)
|
|
95
94
|
|
|
96
|
-
views_not_in_model = {view.view.as_id() for view in rules.views if not view.in_model}
|
|
97
95
|
data_model = rules.metadata.as_data_model()
|
|
98
|
-
|
|
99
|
-
data_model_views = [view_id for view_id in views if view_id not in views_not_in_model]
|
|
100
|
-
|
|
101
96
|
# Sorting to ensure deterministic order
|
|
102
|
-
data_model.views = sorted(
|
|
103
|
-
|
|
97
|
+
data_model.views = sorted(
|
|
98
|
+
[dms_view.view.as_id() for dms_view in rules.views if dms_view.in_model],
|
|
99
|
+
key=lambda x: x.as_tuple(), # type: ignore[union-attr]
|
|
100
|
+
)
|
|
104
101
|
spaces = self._create_spaces(rules.metadata, containers, views, data_model)
|
|
105
|
-
|
|
106
|
-
output = DMSSchema(
|
|
102
|
+
return DMSSchema(
|
|
107
103
|
spaces=spaces,
|
|
108
104
|
data_model=data_model,
|
|
109
105
|
views=views,
|
|
@@ -111,12 +107,6 @@ class _DMSExporter:
|
|
|
111
107
|
node_types=node_types,
|
|
112
108
|
)
|
|
113
109
|
|
|
114
|
-
if self._ref_schema:
|
|
115
|
-
output.reference = self._ref_schema
|
|
116
|
-
if last_schema:
|
|
117
|
-
output.last = last_schema
|
|
118
|
-
return output
|
|
119
|
-
|
|
120
110
|
def _create_spaces(
|
|
121
111
|
self,
|
|
122
112
|
metadata: DMSMetadata,
|
|
@@ -136,14 +126,20 @@ class _DMSExporter:
|
|
|
136
126
|
spaces[self.instance_space] = dm.SpaceApply(space=self.instance_space, name=self.instance_space)
|
|
137
127
|
return spaces
|
|
138
128
|
|
|
139
|
-
def
|
|
129
|
+
def _create_views(
|
|
140
130
|
self,
|
|
141
131
|
view_properties_by_id: dict[dm.ViewId, list[DMSProperty]],
|
|
142
132
|
view_properties_with_ancestors_by_id: dict[dm.ViewId, list[DMSProperty]],
|
|
143
133
|
) -> ViewApplyDict:
|
|
144
134
|
input_views = list(self.rules.views)
|
|
145
135
|
|
|
146
|
-
views = ViewApplyDict(
|
|
136
|
+
views = ViewApplyDict(
|
|
137
|
+
[
|
|
138
|
+
dms_view.as_view()
|
|
139
|
+
for dms_view in input_views
|
|
140
|
+
if not (self.remove_cdf_spaces and dms_view.view.space in COGNITE_SPACES)
|
|
141
|
+
]
|
|
142
|
+
)
|
|
147
143
|
|
|
148
144
|
for view_id, view in views.items():
|
|
149
145
|
view.properties = {}
|
|
@@ -184,7 +180,13 @@ class _DMSExporter:
|
|
|
184
180
|
|
|
185
181
|
containers = list(self.rules.containers or [])
|
|
186
182
|
|
|
187
|
-
containers = dm.ContainerApplyList(
|
|
183
|
+
containers = dm.ContainerApplyList(
|
|
184
|
+
[
|
|
185
|
+
dms_container.as_container()
|
|
186
|
+
for dms_container in containers
|
|
187
|
+
if not (self.remove_cdf_spaces and dms_container.container.space in COGNITE_SPACES)
|
|
188
|
+
]
|
|
189
|
+
)
|
|
188
190
|
container_to_drop = set()
|
|
189
191
|
for container in containers:
|
|
190
192
|
container_id = container.as_id()
|
|
@@ -4,13 +4,12 @@ from typing import Any, ClassVar, Literal
|
|
|
4
4
|
|
|
5
5
|
import pandas as pd
|
|
6
6
|
from cognite.client import data_modeling as dm
|
|
7
|
-
from pydantic import Field, field_serializer, field_validator
|
|
7
|
+
from pydantic import Field, field_serializer, field_validator
|
|
8
8
|
from pydantic_core.core_schema import SerializationInfo, ValidationInfo
|
|
9
9
|
from rdflib import URIRef
|
|
10
10
|
|
|
11
11
|
from cognite.neat._client.data_classes.schema import DMSSchema
|
|
12
12
|
from cognite.neat._constants import COGNITE_SPACES
|
|
13
|
-
from cognite.neat._issues import MultiValueError
|
|
14
13
|
from cognite.neat._issues.errors import NeatValueError
|
|
15
14
|
from cognite.neat._issues.warnings import (
|
|
16
15
|
PrincipleMatchingSpaceAndVersionWarning,
|
|
@@ -339,9 +338,6 @@ class DMSRules(BaseRules):
|
|
|
339
338
|
containers: SheetList[DMSContainer] | None = Field(None, alias="Containers")
|
|
340
339
|
enum: SheetList[DMSEnum] | None = Field(None, alias="Enum")
|
|
341
340
|
nodes: SheetList[DMSNode] | None = Field(None, alias="Nodes")
|
|
342
|
-
# This is a hack to allow the post_validation to be turned off when needed
|
|
343
|
-
# Will likely be moved completely out of the rules in the future
|
|
344
|
-
post_validate: bool = Field(default=True, exclude=True, repr=False)
|
|
345
341
|
|
|
346
342
|
@field_validator("views")
|
|
347
343
|
def matching_version_and_space(cls, value: SheetList[DMSView], info: ValidationInfo) -> SheetList[DMSView]:
|
|
@@ -374,23 +370,10 @@ class DMSRules(BaseRules):
|
|
|
374
370
|
)
|
|
375
371
|
return value
|
|
376
372
|
|
|
377
|
-
|
|
378
|
-
def post_validation(self) -> "DMSRules":
|
|
379
|
-
from ._validation import DMSPostValidation
|
|
380
|
-
|
|
381
|
-
if not self.post_validate:
|
|
382
|
-
return self
|
|
383
|
-
issue_list = DMSPostValidation(self).validate()
|
|
384
|
-
if issue_list.warnings:
|
|
385
|
-
issue_list.trigger_warnings()
|
|
386
|
-
if issue_list.has_errors:
|
|
387
|
-
raise MultiValueError(issue_list.errors)
|
|
388
|
-
return self
|
|
389
|
-
|
|
390
|
-
def as_schema(self, include_pipeline: bool = False, instance_space: str | None = None) -> DMSSchema:
|
|
373
|
+
def as_schema(self, instance_space: str | None = None, remove_cdf_spaces: bool = False) -> DMSSchema:
|
|
391
374
|
from ._exporter import _DMSExporter
|
|
392
375
|
|
|
393
|
-
return _DMSExporter(self, instance_space).to_schema()
|
|
376
|
+
return _DMSExporter(self, instance_space, remove_cdf_spaces=remove_cdf_spaces).to_schema()
|
|
394
377
|
|
|
395
378
|
def _repr_html_(self) -> str:
|
|
396
379
|
summary = {
|
|
@@ -406,28 +389,3 @@ class DMSRules(BaseRules):
|
|
|
406
389
|
}
|
|
407
390
|
|
|
408
391
|
return pd.DataFrame([summary]).T.rename(columns={0: ""})._repr_html_() # type: ignore
|
|
409
|
-
|
|
410
|
-
def imported_views_and_containers_ids(
|
|
411
|
-
self, include_model_views_with_no_properties: bool = True
|
|
412
|
-
) -> tuple[set[dm.ViewId], set[dm.ContainerId]]:
|
|
413
|
-
existing_views = {view.view for view in self.views}
|
|
414
|
-
imported_views: set[dm.ViewId] = set()
|
|
415
|
-
for view in self.views:
|
|
416
|
-
for parent in view.implements or []:
|
|
417
|
-
if parent not in existing_views:
|
|
418
|
-
imported_views.add(parent.as_id())
|
|
419
|
-
existing_containers = {container.container for container in self.containers or []}
|
|
420
|
-
imported_containers: set[dm.ContainerId] = set()
|
|
421
|
-
view_with_properties: set[ViewEntity] = set()
|
|
422
|
-
for prop in self.properties:
|
|
423
|
-
if prop.container and prop.container not in existing_containers:
|
|
424
|
-
imported_containers.add(prop.container.as_id())
|
|
425
|
-
if prop.view not in existing_views:
|
|
426
|
-
imported_views.add(prop.view.as_id())
|
|
427
|
-
view_with_properties.add(prop.view)
|
|
428
|
-
|
|
429
|
-
if include_model_views_with_no_properties:
|
|
430
|
-
extra_views = existing_views - view_with_properties
|
|
431
|
-
imported_views.update({view.as_id() for view in extra_views})
|
|
432
|
-
|
|
433
|
-
return imported_views, imported_containers
|