cognite-neat 0.98.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/__init__.py +4 -0
- cognite/neat/_client/_api/data_modeling_loaders.py +585 -0
- cognite/neat/_client/_api/schema.py +111 -0
- cognite/neat/_client/_api_client.py +17 -0
- cognite/neat/_client/data_classes/__init__.py +0 -0
- cognite/neat/{_utils/cdf/data_classes.py → _client/data_classes/data_modeling.py} +8 -135
- cognite/neat/_client/data_classes/schema.py +495 -0
- cognite/neat/_constants.py +27 -4
- cognite/neat/_graph/_shared.py +14 -15
- cognite/neat/_graph/extractors/_classic_cdf/_assets.py +14 -154
- cognite/neat/_graph/extractors/_classic_cdf/_base.py +154 -7
- cognite/neat/_graph/extractors/_classic_cdf/_classic.py +25 -14
- cognite/neat/_graph/extractors/_classic_cdf/_data_sets.py +17 -92
- cognite/neat/_graph/extractors/_classic_cdf/_events.py +13 -162
- cognite/neat/_graph/extractors/_classic_cdf/_files.py +15 -179
- cognite/neat/_graph/extractors/_classic_cdf/_labels.py +32 -100
- cognite/neat/_graph/extractors/_classic_cdf/_relationships.py +27 -178
- cognite/neat/_graph/extractors/_classic_cdf/_sequences.py +14 -139
- cognite/neat/_graph/extractors/_classic_cdf/_timeseries.py +15 -173
- cognite/neat/_graph/extractors/_rdf_file.py +6 -7
- cognite/neat/_graph/loaders/_rdf2dms.py +2 -2
- cognite/neat/_graph/queries/_base.py +17 -1
- cognite/neat/_graph/transformers/_classic_cdf.py +74 -147
- cognite/neat/_graph/transformers/_prune_graph.py +1 -1
- cognite/neat/_graph/transformers/_rdfpath.py +1 -1
- 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 +8 -0
- cognite/neat/_issues/warnings/_external.py +16 -0
- cognite/neat/_issues/warnings/_properties.py +16 -0
- cognite/neat/_issues/warnings/_resources.py +26 -2
- cognite/neat/_issues/warnings/user_modeling.py +4 -4
- cognite/neat/_rules/_constants.py +8 -11
- cognite/neat/_rules/analysis/_base.py +8 -4
- cognite/neat/_rules/exporters/_base.py +3 -4
- cognite/neat/_rules/exporters/_rules2dms.py +33 -46
- cognite/neat/_rules/importers/__init__.py +1 -3
- cognite/neat/_rules/importers/_base.py +1 -1
- cognite/neat/_rules/importers/_dms2rules.py +6 -29
- 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 +43 -35
- cognite/neat/_rules/importers/_rdf/_owl2rules.py +80 -0
- cognite/neat/_rules/importers/_rdf/_shared.py +138 -441
- cognite/neat/_rules/models/__init__.py +1 -1
- cognite/neat/_rules/models/_base_rules.py +22 -12
- cognite/neat/_rules/models/dms/__init__.py +4 -2
- cognite/neat/_rules/models/dms/_exporter.py +45 -48
- cognite/neat/_rules/models/dms/_rules.py +20 -17
- cognite/neat/_rules/models/dms/_rules_input.py +52 -8
- cognite/neat/_rules/models/dms/_validation.py +391 -119
- cognite/neat/_rules/models/entities/_single_value.py +32 -4
- cognite/neat/_rules/models/information/__init__.py +2 -0
- cognite/neat/_rules/models/information/_rules.py +0 -67
- cognite/neat/_rules/models/information/_validation.py +9 -9
- cognite/neat/_rules/models/mapping/__init__.py +2 -3
- cognite/neat/_rules/models/mapping/_classic2core.py +36 -146
- cognite/neat/_rules/models/mapping/_classic2core.yaml +343 -0
- cognite/neat/_rules/transformers/__init__.py +2 -2
- cognite/neat/_rules/transformers/_converters.py +110 -11
- cognite/neat/_rules/transformers/_mapping.py +105 -30
- cognite/neat/_rules/transformers/_pipelines.py +1 -1
- cognite/neat/_rules/transformers/_verification.py +31 -3
- cognite/neat/_session/_base.py +24 -8
- cognite/neat/_session/_drop.py +35 -0
- cognite/neat/_session/_inspect.py +17 -5
- cognite/neat/_session/_mapping.py +39 -0
- cognite/neat/_session/_prepare.py +219 -23
- cognite/neat/_session/_read.py +49 -12
- cognite/neat/_session/_to.py +8 -5
- cognite/neat/_session/exceptions.py +4 -0
- cognite/neat/_store/_base.py +27 -24
- cognite/neat/_utils/rdf_.py +34 -5
- cognite/neat/_version.py +1 -1
- cognite/neat/_workflows/steps/lib/current/rules_exporter.py +5 -88
- cognite/neat/_workflows/steps/lib/current/rules_importer.py +3 -14
- cognite/neat/_workflows/steps/lib/current/rules_validator.py +6 -7
- {cognite_neat-0.98.0.dist-info → cognite_neat-0.99.1.dist-info}/METADATA +3 -3
- {cognite_neat-0.98.0.dist-info → cognite_neat-0.99.1.dist-info}/RECORD +87 -92
- 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/_rules/models/dms/_schema.py +0 -1101
- cognite/neat/_rules/models/mapping/_base.py +0 -131
- cognite/neat/_utils/cdf/loaders/__init__.py +0 -25
- cognite/neat/_utils/cdf/loaders/_base.py +0 -54
- cognite/neat/_utils/cdf/loaders/_data_modeling.py +0 -339
- cognite/neat/_utils/cdf/loaders/_ingestion.py +0 -167
- /cognite/neat/{_utils/cdf → _client/_api}/__init__.py +0 -0
- {cognite_neat-0.98.0.dist-info → cognite_neat-0.99.1.dist-info}/LICENSE +0 -0
- {cognite_neat-0.98.0.dist-info → cognite_neat-0.99.1.dist-info}/WHEEL +0 -0
- {cognite_neat-0.98.0.dist-info → cognite_neat-0.99.1.dist-info}/entry_points.txt +0 -0
|
@@ -5,6 +5,7 @@ from ._rules_input import (
|
|
|
5
5
|
InformationInputProperty,
|
|
6
6
|
InformationInputRules,
|
|
7
7
|
)
|
|
8
|
+
from ._validation import InformationValidation
|
|
8
9
|
|
|
9
10
|
__all__ = [
|
|
10
11
|
"InformationRules",
|
|
@@ -15,4 +16,5 @@ __all__ = [
|
|
|
15
16
|
"InformationInputMetadata",
|
|
16
17
|
"InformationInputClass",
|
|
17
18
|
"InformationInputProperty",
|
|
19
|
+
"InformationValidation",
|
|
18
20
|
]
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import math
|
|
2
|
-
import sys
|
|
3
2
|
from collections.abc import Hashable
|
|
4
3
|
from typing import TYPE_CHECKING, Any, ClassVar
|
|
5
4
|
|
|
@@ -14,9 +13,7 @@ from cognite.neat._rules._constants import EntityTypes
|
|
|
14
13
|
from cognite.neat._rules.models._base_rules import (
|
|
15
14
|
BaseMetadata,
|
|
16
15
|
BaseRules,
|
|
17
|
-
ClassRef,
|
|
18
16
|
DataModelAspect,
|
|
19
|
-
PropertyRef,
|
|
20
17
|
RoleTypes,
|
|
21
18
|
SheetList,
|
|
22
19
|
SheetRow,
|
|
@@ -36,8 +33,6 @@ from cognite.neat._rules.models.entities import (
|
|
|
36
33
|
ClassEntity,
|
|
37
34
|
ClassEntityList,
|
|
38
35
|
Entity,
|
|
39
|
-
MultiValueTypeInfo,
|
|
40
|
-
Undefined,
|
|
41
36
|
UnknownEntity,
|
|
42
37
|
)
|
|
43
38
|
|
|
@@ -45,12 +40,6 @@ if TYPE_CHECKING:
|
|
|
45
40
|
from cognite.neat._rules.models import DMSRules
|
|
46
41
|
|
|
47
42
|
|
|
48
|
-
if sys.version_info >= (3, 11):
|
|
49
|
-
from typing import Self
|
|
50
|
-
else:
|
|
51
|
-
from typing_extensions import Self
|
|
52
|
-
|
|
53
|
-
|
|
54
43
|
class InformationMetadata(BaseMetadata):
|
|
55
44
|
role: ClassVar[RoleTypes] = RoleTypes.information
|
|
56
45
|
aspect: ClassVar[DataModelAspect] = DataModelAspect.logical
|
|
@@ -103,9 +92,6 @@ class InformationClass(SheetRow):
|
|
|
103
92
|
)
|
|
104
93
|
return ",".join(str(value) for value in value)
|
|
105
94
|
|
|
106
|
-
def as_reference(self) -> ClassRef:
|
|
107
|
-
return ClassRef(Class=self.class_)
|
|
108
|
-
|
|
109
95
|
|
|
110
96
|
class InformationProperty(SheetRow):
|
|
111
97
|
"""
|
|
@@ -160,21 +146,6 @@ class InformationProperty(SheetRow):
|
|
|
160
146
|
else:
|
|
161
147
|
raise NeatValueError(f"Invalid RDF Path: {value!s}")
|
|
162
148
|
|
|
163
|
-
@model_validator(mode="after")
|
|
164
|
-
def set_default_as_list(self):
|
|
165
|
-
if (
|
|
166
|
-
self.type_ == EntityTypes.data_property
|
|
167
|
-
and self.default
|
|
168
|
-
and self.is_list
|
|
169
|
-
and not isinstance(self.default, list)
|
|
170
|
-
):
|
|
171
|
-
if isinstance(self.default, str):
|
|
172
|
-
if self.default:
|
|
173
|
-
self.default = self.default.replace(", ", ",").split(",")
|
|
174
|
-
else:
|
|
175
|
-
self.default = [self.default]
|
|
176
|
-
return self
|
|
177
|
-
|
|
178
149
|
@model_validator(mode="after")
|
|
179
150
|
def set_type_for_default(self):
|
|
180
151
|
if self.type_ == EntityTypes.data_property and self.default:
|
|
@@ -233,9 +204,6 @@ class InformationProperty(SheetRow):
|
|
|
233
204
|
isinstance(self.max_count, int | float) and self.max_count > 1
|
|
234
205
|
)
|
|
235
206
|
|
|
236
|
-
def as_reference(self) -> PropertyRef:
|
|
237
|
-
return PropertyRef(Class=self.class_, Property=self.property_)
|
|
238
|
-
|
|
239
207
|
|
|
240
208
|
class InformationRules(BaseRules):
|
|
241
209
|
metadata: InformationMetadata = Field(alias="Metadata")
|
|
@@ -251,41 +219,6 @@ class InformationRules(BaseRules):
|
|
|
251
219
|
values = get_default_prefixes()
|
|
252
220
|
return values
|
|
253
221
|
|
|
254
|
-
@model_validator(mode="after")
|
|
255
|
-
def update_entities_prefix(self) -> Self:
|
|
256
|
-
# update expected_value_types
|
|
257
|
-
for property_ in self.properties:
|
|
258
|
-
if isinstance(property_.value_type, ClassEntity) and property_.value_type.prefix is Undefined:
|
|
259
|
-
property_.value_type.prefix = self.metadata.prefix
|
|
260
|
-
|
|
261
|
-
if isinstance(property_.value_type, MultiValueTypeInfo):
|
|
262
|
-
property_.value_type.set_default_prefix(self.metadata.prefix)
|
|
263
|
-
|
|
264
|
-
if property_.class_.prefix is Undefined:
|
|
265
|
-
property_.class_.prefix = self.metadata.prefix
|
|
266
|
-
|
|
267
|
-
# update implements
|
|
268
|
-
for class_ in self.classes:
|
|
269
|
-
if class_.implements:
|
|
270
|
-
for parent in class_.implements:
|
|
271
|
-
if not isinstance(parent.prefix, str):
|
|
272
|
-
parent.prefix = self.metadata.prefix
|
|
273
|
-
if class_.class_.prefix is Undefined:
|
|
274
|
-
class_.class_.prefix = self.metadata.prefix
|
|
275
|
-
|
|
276
|
-
return self
|
|
277
|
-
|
|
278
|
-
@model_validator(mode="after")
|
|
279
|
-
def post_validation(self) -> "InformationRules":
|
|
280
|
-
from ._validation import InformationPostValidation
|
|
281
|
-
|
|
282
|
-
issue_list = InformationPostValidation(self).validate()
|
|
283
|
-
if issue_list.warnings:
|
|
284
|
-
issue_list.trigger_warnings()
|
|
285
|
-
if issue_list.has_errors:
|
|
286
|
-
raise issue_list.as_exception()
|
|
287
|
-
return self
|
|
288
|
-
|
|
289
222
|
def as_dms_rules(self) -> "DMSRules":
|
|
290
223
|
from cognite.neat._rules.transformers._converters import _InformationRulesConverter
|
|
291
224
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import itertools
|
|
2
2
|
from collections import Counter
|
|
3
|
-
from typing import cast
|
|
4
3
|
|
|
5
4
|
from cognite.neat._issues import IssueList
|
|
6
|
-
from cognite.neat._issues.errors import NeatValueError
|
|
5
|
+
from cognite.neat._issues.errors import NeatValueError
|
|
7
6
|
from cognite.neat._issues.warnings._models import UndefinedClassWarning
|
|
7
|
+
from cognite.neat._issues.warnings._resources import ResourceNotDefinedWarning
|
|
8
8
|
from cognite.neat._rules._constants import EntityTypes
|
|
9
9
|
from cognite.neat._rules.models.entities import ClassEntity, UnknownEntity
|
|
10
10
|
|
|
11
11
|
from ._rules import InformationRules
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
class
|
|
14
|
+
class InformationValidation:
|
|
15
15
|
"""This class does all the validation of the Information rules that have dependencies
|
|
16
16
|
between components."""
|
|
17
17
|
|
|
@@ -44,10 +44,10 @@ class InformationPostValidation:
|
|
|
44
44
|
# same prefix, meaning same space
|
|
45
45
|
if not class_parent_pairs[class_] and class_.prefix == self.metadata.prefix:
|
|
46
46
|
self.issue_list.append(
|
|
47
|
-
|
|
47
|
+
ResourceNotDefinedWarning(
|
|
48
48
|
resource_type="class",
|
|
49
49
|
identifier=class_,
|
|
50
|
-
location="
|
|
50
|
+
location="Properties sheet",
|
|
51
51
|
)
|
|
52
52
|
)
|
|
53
53
|
|
|
@@ -63,7 +63,7 @@ class InformationPostValidation:
|
|
|
63
63
|
self.issue_list.append(UndefinedClassWarning(class_id=str(parent)))
|
|
64
64
|
else:
|
|
65
65
|
self.issue_list.append(
|
|
66
|
-
|
|
66
|
+
ResourceNotDefinedWarning(
|
|
67
67
|
resource_type="class",
|
|
68
68
|
identifier=parent,
|
|
69
69
|
location="Classes sheet",
|
|
@@ -79,7 +79,7 @@ class InformationPostValidation:
|
|
|
79
79
|
if missing_classes := classes_with_explicit_properties.difference(defined_classes):
|
|
80
80
|
for class_ in missing_classes:
|
|
81
81
|
self.issue_list.append(
|
|
82
|
-
|
|
82
|
+
ResourceNotDefinedWarning(
|
|
83
83
|
resource_type="class",
|
|
84
84
|
identifier=class_,
|
|
85
85
|
location="Classes sheet",
|
|
@@ -99,9 +99,9 @@ class InformationPostValidation:
|
|
|
99
99
|
# Todo: include row and column number
|
|
100
100
|
for missing in missing_value_types:
|
|
101
101
|
self.issue_list.append(
|
|
102
|
-
|
|
102
|
+
ResourceNotDefinedWarning(
|
|
103
103
|
resource_type="class",
|
|
104
|
-
identifier=
|
|
104
|
+
identifier=missing,
|
|
105
105
|
location="Classes sheet",
|
|
106
106
|
)
|
|
107
107
|
)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
from .
|
|
2
|
-
from ._classic2core import create_classic_to_core_mapping
|
|
1
|
+
from ._classic2core import load_classic_to_core_mapping
|
|
3
2
|
|
|
4
|
-
__all__ = ["
|
|
3
|
+
__all__ = ["load_classic_to_core_mapping"]
|
|
@@ -1,150 +1,40 @@
|
|
|
1
|
-
from
|
|
1
|
+
from functools import lru_cache
|
|
2
|
+
from pathlib import Path
|
|
2
3
|
|
|
4
|
+
import yaml
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
from cognite.neat._issues.errors import NeatValueError
|
|
7
|
+
from cognite.neat._rules._shared import ReadRules
|
|
8
|
+
from cognite.neat._rules.models.dms import DMSInputRules, DMSRules
|
|
6
9
|
|
|
10
|
+
_CLASSIC_TO_CORE_MAPPING = Path(__file__).resolve().parent / "_classic2core.yaml"
|
|
7
11
|
|
|
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
|
-
"destination": {"Class": "cdf_cdm:CogniteAsset", "Property": "tag"},
|
|
39
|
-
"source": {"Class": "classic:Asset", "Property": "labels"},
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "externalId"},
|
|
43
|
-
"source": {"Class": "classic:DataSet", "Property": "externalId"},
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "name"},
|
|
47
|
-
"source": {"Class": "classic:DataSet", "Property": "name"},
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "description"},
|
|
51
|
-
"source": {"Class": "classic:DataSet", "Property": "description"},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "metadata"},
|
|
55
|
-
"source": {"Class": "classic:DataSet", "Property": "metadata"},
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "writeProtected"},
|
|
59
|
-
"source": {"Class": "classic:DataSet", "Property": "writeProtected"},
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"destination": {"Class": "cdf_cdm:CogniteActivity", "Property": "externalId"},
|
|
63
|
-
"source": {"Class": "classic:Event", "Property": "externalId"},
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"destination": {"Class": "cdf_cdm:CogniteSchedulable", "Property": "startTime"},
|
|
67
|
-
"source": {"Class": "classic:Event", "Property": "startTime"},
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"destination": {"Class": "cdf_cdm:CogniteSchedulable", "Property": "endTime"},
|
|
71
|
-
"source": {"Class": "classic:Event", "Property": "endTime"},
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
"destination": {"Class": "cdf_cdm:CogniteActivity", "Property": "description"},
|
|
75
|
-
"source": {"Class": "classic:Event", "Property": "description"},
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"destination": {"Class": "cdf_cdm:CogniteActivity", "Property": "assets"},
|
|
79
|
-
"source": {"Class": "classic:Event", "Property": "assetIds"},
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"destination": {"Class": "cdf_cdm:CogniteSourceSystem", "Property": "name"},
|
|
83
|
-
"source": {"Class": "classic:Event", "Property": "source"},
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "externalId"},
|
|
87
|
-
"source": {"Class": "classic:File", "Property": "externalId"},
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "name"},
|
|
91
|
-
"source": {"Class": "classic:File", "Property": "name"},
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "directory"},
|
|
95
|
-
"source": {"Class": "classic:File", "Property": "directory"},
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
"destination": {"Class": "cdf_cdm:CogniteSourceSystem", "Property": "name"},
|
|
99
|
-
"source": {"Class": "classic:File", "Property": "source"},
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "mimeType"},
|
|
103
|
-
"source": {"Class": "classic:File", "Property": "mimeType"},
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "assets"},
|
|
107
|
-
"source": {"Class": "classic:File", "Property": "assetIds"},
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "sourceCreatedTime"},
|
|
111
|
-
"source": {"Class": "classic:File", "Property": "sourceCreatedTime"},
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "sourceUpdatedTime"},
|
|
115
|
-
"source": {"Class": "classic:File", "Property": "sourceModifiedTime"},
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "externalId"},
|
|
119
|
-
"source": {"Class": "classic:TimeSeries", "Property": "externalId"},
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "name"},
|
|
123
|
-
"source": {"Class": "classic:TimeSeries", "Property": "name"},
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "type"},
|
|
127
|
-
"source": {"Class": "classic:TimeSeries", "Property": "isString"},
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "sourceUnit"},
|
|
131
|
-
"source": {"Class": "classic:TimeSeries", "Property": "unit"},
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "unit"},
|
|
135
|
-
"source": {"Class": "classic:TimeSeries", "Property": "unitExternalId"},
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "assets"},
|
|
139
|
-
"source": {"Class": "classic:TimeSeries", "Property": "assetId"},
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "isStep"},
|
|
143
|
-
"source": {"Class": "classic:TimeSeries", "Property": "isStep"},
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "description"},
|
|
147
|
-
"source": {"Class": "classic:TimeSeries", "Property": "description"},
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
}
|
|
12
|
+
|
|
13
|
+
@lru_cache(maxsize=1)
|
|
14
|
+
def _read_source_file() -> str:
|
|
15
|
+
return _CLASSIC_TO_CORE_MAPPING.read_text()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def load_classic_to_core_mapping(org_name: str, source_space: str, source_version: str) -> DMSRules:
|
|
19
|
+
if not org_name:
|
|
20
|
+
raise NeatValueError("Organization name must be provided.")
|
|
21
|
+
|
|
22
|
+
from cognite.neat._rules.importers import YAMLImporter
|
|
23
|
+
from cognite.neat._rules.transformers import VerifyDMSRules
|
|
24
|
+
|
|
25
|
+
raw_str = _read_source_file().replace("Classic", org_name)
|
|
26
|
+
|
|
27
|
+
loaded = yaml.safe_load(raw_str)
|
|
28
|
+
loaded["metadata"]["space"] = source_space
|
|
29
|
+
loaded["metadata"]["version"] = source_version
|
|
30
|
+
|
|
31
|
+
read: ReadRules[DMSInputRules] = YAMLImporter(loaded).to_rules()
|
|
32
|
+
if not isinstance(read.rules, DMSInputRules):
|
|
33
|
+
raise NeatValueError(f"Expected DMS rules, but got {type(read.rules).__name__}")
|
|
34
|
+
|
|
35
|
+
verified = VerifyDMSRules(errors="raise", validate=False).transform(read)
|
|
36
|
+
|
|
37
|
+
if verified.rules is None:
|
|
38
|
+
raise NeatValueError("Failed to verify the rules.")
|
|
39
|
+
|
|
40
|
+
return verified.rules
|