cognite-neat 0.121.0__py3-none-any.whl → 0.121.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.
- cognite/neat/_version.py +1 -1
- cognite/neat/core/_client/_api/statistics.py +91 -0
- cognite/neat/core/_client/_api_client.py +2 -0
- cognite/neat/core/_client/data_classes/statistics.py +125 -0
- cognite/neat/core/_client/testing.py +4 -0
- cognite/neat/core/_constants.py +6 -7
- cognite/neat/core/{_rules → _data_model}/_constants.py +25 -18
- cognite/neat/core/_data_model/_shared.py +59 -0
- cognite/neat/core/_data_model/analysis/__init__.py +3 -0
- cognite/neat/core/{_rules → _data_model}/analysis/_base.py +202 -195
- cognite/neat/core/{_rules → _data_model}/catalog/__init__.py +1 -1
- cognite/neat/core/{_rules → _data_model}/exporters/__init__.py +5 -5
- cognite/neat/core/{_rules → _data_model}/exporters/_base.py +10 -8
- cognite/neat/core/{_rules/exporters/_rules2dms.py → _data_model/exporters/_data_model2dms.py} +22 -18
- cognite/neat/core/{_rules/exporters/_rules2excel.py → _data_model/exporters/_data_model2excel.py} +61 -56
- cognite/neat/core/{_rules/exporters/_rules2instance_template.py → _data_model/exporters/_data_model2instance_template.py} +11 -9
- cognite/neat/core/{_rules/exporters/_rules2ontology.py → _data_model/exporters/_data_model2ontology.py} +64 -61
- cognite/neat/core/{_rules/exporters/_rules2yaml.py → _data_model/exporters/_data_model2yaml.py} +21 -18
- cognite/neat/core/{_rules → _data_model}/importers/__init__.py +6 -8
- cognite/neat/core/{_rules → _data_model}/importers/_base.py +8 -6
- cognite/neat/core/_data_model/importers/_base_file_reader.py +56 -0
- cognite/neat/core/{_rules/importers/_yaml2rules.py → _data_model/importers/_dict2data_model.py} +41 -21
- cognite/neat/core/{_rules/importers/_dms2rules.py → _data_model/importers/_dms2data_model.py} +79 -66
- cognite/neat/core/{_rules/importers/_dtdl2rules → _data_model/importers/_dtdl2data_model}/dtdl_converter.py +41 -41
- cognite/neat/core/{_rules/importers/_dtdl2rules → _data_model/importers/_dtdl2data_model}/dtdl_importer.py +16 -16
- cognite/neat/core/{_rules/importers/_dtdl2rules → _data_model/importers/_dtdl2data_model}/spec.py +3 -3
- cognite/neat/core/{_rules → _data_model}/importers/_rdf/_base.py +18 -16
- cognite/neat/core/{_rules → _data_model}/importers/_rdf/_imf2rules.py +17 -17
- cognite/neat/core/{_rules → _data_model}/importers/_rdf/_inference2rules.py +50 -50
- cognite/neat/core/{_rules → _data_model}/importers/_rdf/_owl2rules.py +14 -14
- cognite/neat/core/{_rules → _data_model}/importers/_rdf/_shared.py +25 -25
- cognite/neat/core/{_rules/importers/_spreadsheet2rules.py → _data_model/importers/_spreadsheet2data_model.py} +69 -38
- cognite/neat/core/_data_model/models/__init__.py +36 -0
- cognite/neat/core/{_rules/models/_base_input.py → _data_model/models/_base_unverified.py} +12 -12
- cognite/neat/core/{_rules/models/_base_rules.py → _data_model/models/_base_verified.py} +13 -13
- cognite/neat/core/{_rules → _data_model}/models/_types.py +13 -13
- cognite/neat/core/_data_model/models/conceptual/__init__.py +25 -0
- cognite/neat/core/{_rules/models/information/_rules_input.py → _data_model/models/conceptual/_unverified.py} +46 -43
- cognite/neat/core/{_rules/models/information → _data_model/models/conceptual}/_validation.py +93 -79
- cognite/neat/core/{_rules/models/information/_rules.py → _data_model/models/conceptual/_verified.py} +83 -83
- cognite/neat/core/{_rules → _data_model}/models/data_types.py +4 -4
- cognite/neat/core/{_rules → _data_model}/models/entities/__init__.py +8 -8
- cognite/neat/core/{_rules → _data_model}/models/entities/_loaders.py +12 -11
- cognite/neat/core/{_rules → _data_model}/models/entities/_multi_value.py +7 -7
- cognite/neat/core/{_rules → _data_model}/models/entities/_single_value.py +45 -39
- cognite/neat/core/{_rules → _data_model}/models/entities/_types.py +9 -3
- cognite/neat/core/{_rules → _data_model}/models/entities/_wrapped.py +3 -3
- cognite/neat/core/{_rules → _data_model}/models/mapping/_classic2core.py +12 -9
- cognite/neat/core/_data_model/models/physical/__init__.py +40 -0
- cognite/neat/core/{_rules/models/dms → _data_model/models/physical}/_exporter.py +83 -64
- cognite/neat/core/{_rules/models/dms/_rules_input.py → _data_model/models/physical/_unverified.py} +56 -44
- cognite/neat/core/{_rules/models/dms → _data_model/models/physical}/_validation.py +20 -17
- cognite/neat/core/{_rules/models/dms/_rules.py → _data_model/models/physical/_verified.py} +79 -71
- cognite/neat/core/{_rules → _data_model}/transformers/__init__.py +27 -23
- cognite/neat/core/{_rules → _data_model}/transformers/_base.py +29 -19
- cognite/neat/core/{_rules → _data_model}/transformers/_converters.py +758 -659
- cognite/neat/core/{_rules → _data_model}/transformers/_mapping.py +79 -60
- cognite/neat/core/_data_model/transformers/_verification.py +120 -0
- cognite/neat/core/{_graph → _instances}/extractors/_base.py +2 -2
- cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_base.py +1 -1
- cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_classic.py +17 -11
- cognite/neat/core/{_graph → _instances}/extractors/_dms_graph.py +47 -39
- cognite/neat/core/{_graph → _instances}/extractors/_mock_graph_generator.py +102 -99
- cognite/neat/core/{_graph → _instances}/extractors/_rdf_file.py +2 -2
- cognite/neat/core/{_graph → _instances}/loaders/_base.py +2 -2
- cognite/neat/core/{_graph → _instances}/loaders/_rdf2dms.py +16 -14
- cognite/neat/core/{_graph → _instances}/transformers/_base.py +7 -4
- cognite/neat/core/{_graph → _instances}/transformers/_classic_cdf.py +1 -1
- cognite/neat/core/{_graph → _instances}/transformers/_value_type.py +2 -6
- cognite/neat/core/_issues/_base.py +4 -4
- cognite/neat/core/_issues/errors/__init__.py +2 -2
- cognite/neat/core/_issues/errors/_wrapper.py +2 -2
- cognite/neat/core/_issues/warnings/__init__.py +2 -0
- cognite/neat/core/_issues/warnings/_models.py +4 -4
- cognite/neat/core/_issues/warnings/_properties.py +7 -0
- cognite/neat/core/_store/__init__.py +3 -3
- cognite/neat/core/_store/{_rules_store.py → _data_model.py} +128 -121
- cognite/neat/core/_store/{_graph_store.py → _instance.py} +7 -8
- cognite/neat/core/_store/_provenance.py +2 -2
- cognite/neat/core/_store/exceptions.py +4 -4
- cognite/neat/core/_utils/rdf_.py +14 -0
- cognite/neat/core/_utils/spreadsheet.py +1 -1
- cognite/neat/core/_utils/text.py +2 -2
- cognite/neat/session/_base.py +29 -25
- cognite/neat/session/_drop.py +3 -3
- cognite/neat/session/_fix.py +2 -2
- cognite/neat/session/_inspect.py +5 -5
- cognite/neat/session/_mapping.py +11 -9
- cognite/neat/session/_prepare.py +4 -4
- cognite/neat/session/_read.py +15 -15
- cognite/neat/session/_set.py +5 -5
- cognite/neat/session/_show.py +11 -11
- cognite/neat/session/_state.py +17 -17
- cognite/neat/session/_subset.py +14 -11
- cognite/neat/session/_template.py +19 -19
- cognite/neat/session/_to.py +21 -21
- cognite/neat/session/_wizard.py +1 -1
- {cognite_neat-0.121.0.dist-info → cognite_neat-0.121.2.dist-info}/METADATA +1 -1
- cognite_neat-0.121.2.dist-info/RECORD +189 -0
- cognite/neat/core/_rules/_shared.py +0 -43
- cognite/neat/core/_rules/analysis/__init__.py +0 -3
- cognite/neat/core/_rules/exporters/_validation.py +0 -14
- cognite/neat/core/_rules/models/__init__.py +0 -34
- cognite/neat/core/_rules/models/dms/__init__.py +0 -32
- cognite/neat/core/_rules/models/information/__init__.py +0 -20
- cognite/neat/core/_rules/transformers/_verification.py +0 -111
- cognite_neat-0.121.0.dist-info/RECORD +0 -187
- /cognite/neat/core/{_graph → _data_model}/__init__.py +0 -0
- /cognite/neat/core/{_rules → _data_model}/catalog/classic_model.xlsx +0 -0
- /cognite/neat/core/{_rules/catalog/info-rules-imf.xlsx → _data_model/catalog/conceptual-imf-data-model.xlsx} +0 -0
- /cognite/neat/core/{_rules → _data_model}/catalog/hello_world_pump.xlsx +0 -0
- /cognite/neat/core/{_rules/importers/_dtdl2rules → _data_model/importers/_dtdl2data_model}/__init__.py +0 -0
- /cognite/neat/core/{_rules/importers/_dtdl2rules → _data_model/importers/_dtdl2data_model}/_unit_lookup.py +0 -0
- /cognite/neat/core/{_rules → _data_model}/importers/_rdf/__init__.py +0 -0
- /cognite/neat/core/{_rules → _data_model}/models/entities/_constants.py +0 -0
- /cognite/neat/core/{_rules → _data_model}/models/mapping/__init__.py +0 -0
- /cognite/neat/core/{_rules → _data_model}/models/mapping/_classic2core.yaml +0 -0
- /cognite/neat/core/{_graph/extractors/_classic_cdf → _instances}/__init__.py +0 -0
- /cognite/neat/core/{_graph → _instances}/_shared.py +0 -0
- /cognite/neat/core/{_graph → _instances}/_tracking/__init__.py +0 -0
- /cognite/neat/core/{_graph → _instances}/_tracking/base.py +0 -0
- /cognite/neat/core/{_graph → _instances}/_tracking/log.py +0 -0
- /cognite/neat/core/{_graph → _instances}/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -0
- /cognite/neat/core/{_graph → _instances}/examples/Knowledge-Graph-Nordic44.xml +0 -0
- /cognite/neat/core/{_graph → _instances}/examples/__init__.py +0 -0
- /cognite/neat/core/{_graph → _instances}/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/__init__.py +0 -0
- /cognite/neat/core/{_rules → _instances/extractors/_classic_cdf}/__init__.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_assets.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_data_sets.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_events.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_files.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_labels.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_relationships.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_sequences.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_classic_cdf/_timeseries.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_dict.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_dms.py +0 -0
- /cognite/neat/core/{_graph → _instances}/extractors/_raw.py +0 -0
- /cognite/neat/core/{_graph → _instances}/loaders/__init__.py +0 -0
- /cognite/neat/core/{_graph → _instances}/queries/__init__.py +0 -0
- /cognite/neat/core/{_graph → _instances}/queries/_base.py +0 -0
- /cognite/neat/core/{_graph → _instances}/queries/_queries.py +0 -0
- /cognite/neat/core/{_graph → _instances}/queries/_select.py +0 -0
- /cognite/neat/core/{_graph → _instances}/queries/_update.py +0 -0
- /cognite/neat/core/{_graph → _instances}/transformers/__init__.py +0 -0
- /cognite/neat/core/{_graph → _instances}/transformers/_prune_graph.py +0 -0
- /cognite/neat/core/{_graph → _instances}/transformers/_rdfpath.py +0 -0
- {cognite_neat-0.121.0.dist-info → cognite_neat-0.121.2.dist-info}/WHEEL +0 -0
- {cognite_neat-0.121.0.dist-info → cognite_neat-0.121.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -11,12 +11,12 @@ from pydantic.functional_validators import ModelWrapValidatorHandler
|
|
|
11
11
|
from rdflib import URIRef
|
|
12
12
|
|
|
13
13
|
from cognite.neat.core._constants import XML_SCHEMA_NAMESPACE
|
|
14
|
-
from cognite.neat.core.
|
|
14
|
+
from cognite.neat.core._data_model._constants import (
|
|
15
15
|
SPLIT_ON_COMMA_PATTERN,
|
|
16
16
|
SPLIT_ON_EQUAL_PATTERN,
|
|
17
17
|
)
|
|
18
|
-
from cognite.neat.core.
|
|
19
|
-
|
|
18
|
+
from cognite.neat.core._data_model.models.entities._single_value import (
|
|
19
|
+
ConceptEntity,
|
|
20
20
|
UnitEntity,
|
|
21
21
|
)
|
|
22
22
|
|
|
@@ -397,7 +397,7 @@ class Enum(DataType):
|
|
|
397
397
|
|
|
398
398
|
name: typing.Literal["enum"] = "enum"
|
|
399
399
|
|
|
400
|
-
collection:
|
|
400
|
+
collection: ConceptEntity
|
|
401
401
|
unknown_value: str | None = Field(None, alias="unknownValue")
|
|
402
402
|
|
|
403
403
|
|
|
@@ -4,15 +4,15 @@ from ._multi_value import MultiValueTypeInfo
|
|
|
4
4
|
from ._single_value import (
|
|
5
5
|
AssetEntity,
|
|
6
6
|
AssetFields,
|
|
7
|
-
|
|
7
|
+
ConceptEntity,
|
|
8
|
+
ConceptualEntity,
|
|
8
9
|
ContainerEntity,
|
|
9
10
|
DataModelEntity,
|
|
10
|
-
DMSEntity,
|
|
11
11
|
DMSNodeEntity,
|
|
12
|
-
DMSUnknownEntity,
|
|
13
12
|
DMSVersionedEntity,
|
|
14
13
|
EdgeEntity,
|
|
15
|
-
|
|
14
|
+
PhysicalEntity,
|
|
15
|
+
PhysicalUnknownEntity,
|
|
16
16
|
ReferenceEntity,
|
|
17
17
|
RelationshipEntity,
|
|
18
18
|
ReverseConnectionEntity,
|
|
@@ -28,21 +28,21 @@ __all__ = [
|
|
|
28
28
|
"AssetEntity",
|
|
29
29
|
"AssetFields",
|
|
30
30
|
"CdfResourceEntityList",
|
|
31
|
-
"ClassEntity",
|
|
32
31
|
"ClassEntityList",
|
|
32
|
+
"ConceptEntity",
|
|
33
|
+
"ConceptualEntity",
|
|
33
34
|
"ContainerEntity",
|
|
34
35
|
"ContainerEntityList",
|
|
35
|
-
"DMSEntity",
|
|
36
36
|
"DMSFilter",
|
|
37
37
|
"DMSNodeEntity",
|
|
38
|
-
"DMSUnknownEntity",
|
|
39
38
|
"DMSVersionedEntity",
|
|
40
39
|
"DataModelEntity",
|
|
41
40
|
"EdgeEntity",
|
|
42
|
-
"Entity",
|
|
43
41
|
"HasDataFilter",
|
|
44
42
|
"MultiValueTypeInfo",
|
|
45
43
|
"NodeTypeFilter",
|
|
44
|
+
"PhysicalEntity",
|
|
45
|
+
"PhysicalUnknownEntity",
|
|
46
46
|
"RawFilter",
|
|
47
47
|
"ReferenceEntity",
|
|
48
48
|
"RelationshipEntity",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
from typing import Literal
|
|
2
2
|
|
|
3
|
+
from cognite.neat.core._data_model.models.data_types import DataType
|
|
3
4
|
from cognite.neat.core._issues.errors import NeatTypeError
|
|
4
|
-
from cognite.neat.core._rules.models.data_types import DataType
|
|
5
5
|
|
|
6
6
|
from ._multi_value import MultiValueTypeInfo
|
|
7
7
|
from ._single_value import (
|
|
8
|
-
|
|
9
|
-
DMSUnknownEntity,
|
|
8
|
+
ConceptEntity,
|
|
10
9
|
EdgeEntity,
|
|
10
|
+
PhysicalUnknownEntity,
|
|
11
11
|
ReverseConnectionEntity,
|
|
12
12
|
Unknown,
|
|
13
13
|
UnknownEntity,
|
|
@@ -16,9 +16,10 @@ from ._single_value import (
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def load_value_type(
|
|
19
|
-
raw: str | MultiValueTypeInfo | DataType |
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
raw: str | MultiValueTypeInfo | DataType | ConceptEntity | UnknownEntity,
|
|
20
|
+
default_prefix: str,
|
|
21
|
+
) -> MultiValueTypeInfo | DataType | ConceptEntity | UnknownEntity:
|
|
22
|
+
if isinstance(raw, MultiValueTypeInfo | DataType | ConceptEntity | UnknownEntity):
|
|
22
23
|
return raw
|
|
23
24
|
elif isinstance(raw, str):
|
|
24
25
|
# property holding xsd data type
|
|
@@ -36,23 +37,23 @@ def load_value_type(
|
|
|
36
37
|
|
|
37
38
|
# property holding link to class
|
|
38
39
|
else:
|
|
39
|
-
return
|
|
40
|
+
return ConceptEntity.load(raw, prefix=default_prefix)
|
|
40
41
|
else:
|
|
41
42
|
raise NeatTypeError(f"Invalid value type: {type(raw)}")
|
|
42
43
|
|
|
43
44
|
|
|
44
45
|
def load_dms_value_type(
|
|
45
|
-
raw: str | DataType | ViewEntity |
|
|
46
|
+
raw: str | DataType | ViewEntity | PhysicalUnknownEntity,
|
|
46
47
|
default_space: str,
|
|
47
48
|
default_version: str,
|
|
48
|
-
) -> DataType | ViewEntity |
|
|
49
|
-
if isinstance(raw, DataType | ViewEntity |
|
|
49
|
+
) -> DataType | ViewEntity | PhysicalUnknownEntity:
|
|
50
|
+
if isinstance(raw, DataType | ViewEntity | PhysicalUnknownEntity):
|
|
50
51
|
return raw
|
|
51
52
|
elif isinstance(raw, str):
|
|
52
53
|
if DataType.is_data_type(raw):
|
|
53
54
|
return DataType.load(raw)
|
|
54
55
|
elif raw == str(Unknown):
|
|
55
|
-
return
|
|
56
|
+
return PhysicalUnknownEntity()
|
|
56
57
|
else:
|
|
57
58
|
return ViewEntity.load(raw, space=default_space, version=default_version)
|
|
58
59
|
raise NeatTypeError(f"Invalid value type: {type(raw)}")
|
|
@@ -6,16 +6,16 @@ from pydantic import (
|
|
|
6
6
|
model_validator,
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
from cognite.neat.core.
|
|
10
|
-
from cognite.neat.core.
|
|
9
|
+
from cognite.neat.core._data_model._constants import EntityTypes
|
|
10
|
+
from cognite.neat.core._data_model.models.data_types import DataType
|
|
11
11
|
|
|
12
12
|
from ._constants import _PARSE, Undefined
|
|
13
|
-
from ._single_value import
|
|
13
|
+
from ._single_value import ConceptEntity, UnknownEntity
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class MultiValueTypeInfo(BaseModel):
|
|
17
17
|
type_: ClassVar[EntityTypes] = EntityTypes.multi_value_type
|
|
18
|
-
types: list[DataType |
|
|
18
|
+
types: list[DataType | ConceptEntity]
|
|
19
19
|
|
|
20
20
|
def __str__(self) -> str:
|
|
21
21
|
return ", ".join([str(t) for t in self.types])
|
|
@@ -57,19 +57,19 @@ class MultiValueTypeInfo(BaseModel):
|
|
|
57
57
|
else:
|
|
58
58
|
return {
|
|
59
59
|
"types": [
|
|
60
|
-
(DataType.load(type_) if DataType.is_data_type(type_) else
|
|
60
|
+
(DataType.load(type_) if DataType.is_data_type(type_) else ConceptEntity.load(type_))
|
|
61
61
|
for type_ in types
|
|
62
62
|
]
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
def set_default_prefix(self, prefix: str) -> None:
|
|
66
66
|
for type_ in self.types:
|
|
67
|
-
if isinstance(type_,
|
|
67
|
+
if isinstance(type_, ConceptEntity) and type_.prefix is Undefined:
|
|
68
68
|
type_.prefix = prefix
|
|
69
69
|
|
|
70
70
|
def is_multi_object_type(self) -> bool:
|
|
71
71
|
"""Will signalize to DMS converter to create connection to unknown Node type"""
|
|
72
|
-
return all(isinstance(t,
|
|
72
|
+
return all(isinstance(t, ConceptEntity) for t in self.types)
|
|
73
73
|
|
|
74
74
|
def is_multi_data_type(self) -> bool:
|
|
75
75
|
"""Will signalize to DMS converter to attempt to find the best data type for value"""
|
|
@@ -32,7 +32,7 @@ else:
|
|
|
32
32
|
from backports.strenum import StrEnum
|
|
33
33
|
from typing_extensions import Self
|
|
34
34
|
|
|
35
|
-
from cognite.neat.core.
|
|
35
|
+
from cognite.neat.core._data_model._constants import (
|
|
36
36
|
ENTITY_PATTERN,
|
|
37
37
|
SPLIT_ON_COMMA_PATTERN,
|
|
38
38
|
SPLIT_ON_EDGE_ENTITY_ARGS_PATTERN,
|
|
@@ -50,8 +50,8 @@ from ._constants import (
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
@total_ordering
|
|
53
|
-
class
|
|
54
|
-
"""Entity is a class or property in
|
|
53
|
+
class ConceptualEntity(BaseModel, extra="ignore"):
|
|
54
|
+
"""Conceptual Entity is a concept, class or property in semantics sense."""
|
|
55
55
|
|
|
56
56
|
type_: ClassVar[EntityTypes] = EntityTypes.undefined
|
|
57
57
|
prefix: str | _UndefinedType = Undefined
|
|
@@ -64,7 +64,10 @@ class Entity(BaseModel, extra="ignore"):
|
|
|
64
64
|
@classmethod
|
|
65
65
|
@overload
|
|
66
66
|
def load(
|
|
67
|
-
cls: "type[T_Entity]",
|
|
67
|
+
cls: "type[T_Entity]",
|
|
68
|
+
data: Any,
|
|
69
|
+
strict: Literal[False] = False,
|
|
70
|
+
**defaults: Any,
|
|
68
71
|
) -> "T_Entity | UnknownEntity": ...
|
|
69
72
|
|
|
70
73
|
@classmethod
|
|
@@ -85,7 +88,7 @@ class Entity(BaseModel, extra="ignore"):
|
|
|
85
88
|
return cls.model_validate(data)
|
|
86
89
|
|
|
87
90
|
@model_validator(mode="before")
|
|
88
|
-
def _load(cls, data: Any) -> "dict |
|
|
91
|
+
def _load(cls, data: Any) -> "dict | ConceptualEntity":
|
|
89
92
|
defaults = {}
|
|
90
93
|
if isinstance(data, dict) and _PARSE in data:
|
|
91
94
|
defaults = data.get("defaults", {})
|
|
@@ -157,7 +160,7 @@ class Entity(BaseModel, extra="ignore"):
|
|
|
157
160
|
if isinstance(annotation, UnionType) or get_origin(annotation) is Union:
|
|
158
161
|
annotation = get_args(annotation)[0]
|
|
159
162
|
|
|
160
|
-
if inspect.isclass(annotation) and issubclass(annotation,
|
|
163
|
+
if inspect.isclass(annotation) and issubclass(annotation, ConceptualEntity): # type: ignore[arg-type]
|
|
161
164
|
extra_args[key] = annotation.load(extra_args[key], **defaults) # type: ignore[union-attr, assignment]
|
|
162
165
|
return dict(prefix=prefix, suffix=suffix, **extra_args)
|
|
163
166
|
|
|
@@ -179,12 +182,12 @@ class Entity(BaseModel, extra="ignore"):
|
|
|
179
182
|
return self.prefix, str(self.suffix), *extra
|
|
180
183
|
|
|
181
184
|
def __lt__(self, other: object) -> bool:
|
|
182
|
-
if not isinstance(other,
|
|
185
|
+
if not isinstance(other, ConceptualEntity):
|
|
183
186
|
return NotImplemented
|
|
184
187
|
return self.as_tuple() < other.as_tuple()
|
|
185
188
|
|
|
186
189
|
def __eq__(self, other: object) -> bool:
|
|
187
|
-
if not isinstance(other,
|
|
190
|
+
if not isinstance(other, ConceptualEntity):
|
|
188
191
|
return NotImplemented
|
|
189
192
|
return self.as_tuple() == other.as_tuple()
|
|
190
193
|
|
|
@@ -207,7 +210,7 @@ class Entity(BaseModel, extra="ignore"):
|
|
|
207
210
|
def _as_str(self, **defaults: Any) -> str:
|
|
208
211
|
# We have overwritten the serialization to str, so we need to do it manually
|
|
209
212
|
model_dump = {
|
|
210
|
-
field.alias or field_name: v.dump(**defaults) if isinstance(v,
|
|
213
|
+
field.alias or field_name: v.dump(**defaults) if isinstance(v, ConceptualEntity) else v
|
|
211
214
|
for field_name, field in self.model_fields.items()
|
|
212
215
|
if (v := getattr(self, field_name)) is not None and field_name not in {"prefix", "suffix"}
|
|
213
216
|
}
|
|
@@ -263,11 +266,11 @@ class Entity(BaseModel, extra="ignore"):
|
|
|
263
266
|
return new_entity
|
|
264
267
|
|
|
265
268
|
|
|
266
|
-
T_Entity = TypeVar("T_Entity", bound=
|
|
269
|
+
T_Entity = TypeVar("T_Entity", bound=ConceptualEntity)
|
|
267
270
|
|
|
268
271
|
|
|
269
|
-
class
|
|
270
|
-
type_: ClassVar[EntityTypes] = EntityTypes.
|
|
272
|
+
class ConceptEntity(ConceptualEntity):
|
|
273
|
+
type_: ClassVar[EntityTypes] = EntityTypes.concept
|
|
271
274
|
version: str | None = None
|
|
272
275
|
|
|
273
276
|
def as_view_entity(self, default_space: str, default_version: str) -> "ViewEntity":
|
|
@@ -283,7 +286,7 @@ class ClassEntity(Entity):
|
|
|
283
286
|
return ContainerEntity(space=space, externalId=str(self.suffix))
|
|
284
287
|
|
|
285
288
|
|
|
286
|
-
class UnknownEntity(
|
|
289
|
+
class UnknownEntity(ConceptEntity):
|
|
287
290
|
type_: ClassVar[EntityTypes] = EntityTypes.undefined
|
|
288
291
|
prefix: _UndefinedType = Undefined
|
|
289
292
|
suffix: _UnknownType = Unknown # type: ignore[assignment]
|
|
@@ -293,7 +296,7 @@ class UnknownEntity(ClassEntity):
|
|
|
293
296
|
return str(Unknown)
|
|
294
297
|
|
|
295
298
|
|
|
296
|
-
class UnitEntity(
|
|
299
|
+
class UnitEntity(ConceptualEntity):
|
|
297
300
|
type_: ClassVar[EntityTypes] = EntityTypes.unit
|
|
298
301
|
prefix: str
|
|
299
302
|
suffix: str
|
|
@@ -310,14 +313,14 @@ class AssetFields(StrEnum):
|
|
|
310
313
|
metadata = "metadata"
|
|
311
314
|
|
|
312
315
|
|
|
313
|
-
class AssetEntity(
|
|
316
|
+
class AssetEntity(ConceptualEntity):
|
|
314
317
|
type_: ClassVar[EntityTypes] = EntityTypes.asset
|
|
315
318
|
suffix: str = "Asset"
|
|
316
319
|
prefix: _UndefinedType = Undefined
|
|
317
320
|
property_: AssetFields = Field(alias="property")
|
|
318
321
|
|
|
319
322
|
|
|
320
|
-
class RelationshipEntity(
|
|
323
|
+
class RelationshipEntity(ConceptualEntity):
|
|
321
324
|
type_: ClassVar[EntityTypes] = EntityTypes.relationship
|
|
322
325
|
suffix: str = "Relationship"
|
|
323
326
|
prefix: _UndefinedType = Undefined
|
|
@@ -327,7 +330,7 @@ class RelationshipEntity(Entity):
|
|
|
327
330
|
T_ID = TypeVar("T_ID", bound=ContainerId | ViewId | DataModelId | PropertyId | NodeId | None)
|
|
328
331
|
|
|
329
332
|
|
|
330
|
-
class
|
|
333
|
+
class PhysicalEntity(ConceptualEntity, Generic[T_ID], ABC):
|
|
331
334
|
type_: ClassVar[EntityTypes] = EntityTypes.undefined
|
|
332
335
|
prefix: str = Field(alias="space")
|
|
333
336
|
suffix: str = Field(alias="externalId")
|
|
@@ -344,17 +347,20 @@ class DMSEntity(Entity, Generic[T_ID], ABC):
|
|
|
344
347
|
@classmethod
|
|
345
348
|
@overload
|
|
346
349
|
def load(
|
|
347
|
-
cls: "type[T_DMSEntity]",
|
|
348
|
-
|
|
350
|
+
cls: "type[T_DMSEntity]",
|
|
351
|
+
data: Any,
|
|
352
|
+
strict: Literal[False] = False,
|
|
353
|
+
**defaults: Any,
|
|
354
|
+
) -> "T_DMSEntity | PhysicalUnknownEntity": ...
|
|
349
355
|
|
|
350
356
|
@classmethod
|
|
351
357
|
def load(
|
|
352
358
|
cls: "type[T_DMSEntity]", data: Any, strict: bool = False, **defaults: Any
|
|
353
|
-
) -> "T_DMSEntity |
|
|
359
|
+
) -> "T_DMSEntity | PhysicalUnknownEntity": # type: ignore
|
|
354
360
|
if isinstance(data, str) and data == str(Unknown):
|
|
355
361
|
if strict:
|
|
356
362
|
raise NeatValueError(f"Failed to load entity {data!s}")
|
|
357
|
-
return
|
|
363
|
+
return PhysicalUnknownEntity.from_id(None)
|
|
358
364
|
return cast(T_DMSEntity, super().load(data, **defaults))
|
|
359
365
|
|
|
360
366
|
@property
|
|
@@ -376,8 +382,8 @@ class DMSEntity(Entity, Generic[T_ID], ABC):
|
|
|
376
382
|
def from_id(cls, id: T_ID) -> Self:
|
|
377
383
|
raise NotImplementedError("Method from_id must be implemented in subclasses")
|
|
378
384
|
|
|
379
|
-
def
|
|
380
|
-
return
|
|
385
|
+
def as_concept_entity(self) -> ConceptEntity:
|
|
386
|
+
return ConceptEntity(prefix=self.space, suffix=self.external_id)
|
|
381
387
|
|
|
382
388
|
def as_dms_compliant_entity(self) -> "Self":
|
|
383
389
|
new_entity = self.model_copy(deep=True)
|
|
@@ -385,10 +391,10 @@ class DMSEntity(Entity, Generic[T_ID], ABC):
|
|
|
385
391
|
return new_entity
|
|
386
392
|
|
|
387
393
|
|
|
388
|
-
T_DMSEntity = TypeVar("T_DMSEntity", bound=
|
|
394
|
+
T_DMSEntity = TypeVar("T_DMSEntity", bound=PhysicalEntity)
|
|
389
395
|
|
|
390
396
|
|
|
391
|
-
class ContainerEntity(
|
|
397
|
+
class ContainerEntity(PhysicalEntity[ContainerId]):
|
|
392
398
|
type_: ClassVar[EntityTypes] = EntityTypes.container
|
|
393
399
|
|
|
394
400
|
def as_id(self) -> ContainerId:
|
|
@@ -399,13 +405,13 @@ class ContainerEntity(DMSEntity[ContainerId]):
|
|
|
399
405
|
return cls(space=id.space, externalId=id.external_id)
|
|
400
406
|
|
|
401
407
|
|
|
402
|
-
class DMSVersionedEntity(
|
|
408
|
+
class DMSVersionedEntity(PhysicalEntity[T_ID], ABC):
|
|
403
409
|
version: str
|
|
404
410
|
|
|
405
|
-
def
|
|
411
|
+
def as_concept_entity(self, skip_version: bool = False) -> ConceptEntity:
|
|
406
412
|
if skip_version:
|
|
407
|
-
return
|
|
408
|
-
return
|
|
413
|
+
return ConceptEntity(prefix=self.space, suffix=self.external_id)
|
|
414
|
+
return ConceptEntity(prefix=self.space, suffix=self.external_id, version=self.version)
|
|
409
415
|
|
|
410
416
|
|
|
411
417
|
class ViewEntity(DMSVersionedEntity[ViewId]):
|
|
@@ -429,7 +435,7 @@ class ViewEntity(DMSVersionedEntity[ViewId]):
|
|
|
429
435
|
raise ValueError("Version must be specified")
|
|
430
436
|
|
|
431
437
|
|
|
432
|
-
class
|
|
438
|
+
class PhysicalUnknownEntity(PhysicalEntity[None]):
|
|
433
439
|
"""This is a special entity that represents an unknown entity.
|
|
434
440
|
|
|
435
441
|
The use case is for direct relations where the source is not known."""
|
|
@@ -442,7 +448,7 @@ class DMSUnknownEntity(DMSEntity[None]):
|
|
|
442
448
|
return None
|
|
443
449
|
|
|
444
450
|
@classmethod
|
|
445
|
-
def from_id(cls, id: None) -> "
|
|
451
|
+
def from_id(cls, id: None) -> "PhysicalUnknownEntity":
|
|
446
452
|
return cls(space=Undefined, externalId=Unknown)
|
|
447
453
|
|
|
448
454
|
@property
|
|
@@ -463,7 +469,7 @@ class DataModelEntity(DMSVersionedEntity[DataModelId]):
|
|
|
463
469
|
return cls(space=id.space, externalId=id.external_id, version=id.version)
|
|
464
470
|
|
|
465
471
|
|
|
466
|
-
class DMSNodeEntity(
|
|
472
|
+
class DMSNodeEntity(PhysicalEntity[NodeId]):
|
|
467
473
|
type_: ClassVar[EntityTypes] = EntityTypes.dms_node
|
|
468
474
|
|
|
469
475
|
def as_id(self) -> NodeId:
|
|
@@ -481,7 +487,7 @@ class DMSNodeEntity(DMSEntity[NodeId]):
|
|
|
481
487
|
return cls(space=ref.space, externalId=ref.external_id)
|
|
482
488
|
|
|
483
489
|
|
|
484
|
-
class EdgeEntity(
|
|
490
|
+
class EdgeEntity(PhysicalEntity[None]):
|
|
485
491
|
type_: ClassVar[EntityTypes] = EntityTypes.edge
|
|
486
492
|
prefix: _UndefinedType = Undefined # type: ignore[assignment]
|
|
487
493
|
suffix: Literal["edge"] = "edge"
|
|
@@ -501,21 +507,21 @@ class EdgeEntity(DMSEntity[None]):
|
|
|
501
507
|
return cls()
|
|
502
508
|
|
|
503
509
|
|
|
504
|
-
class ReverseConnectionEntity(
|
|
510
|
+
class ReverseConnectionEntity(ConceptualEntity):
|
|
505
511
|
type_: ClassVar[EntityTypes] = EntityTypes.reverse
|
|
506
512
|
prefix: _UndefinedType = Undefined
|
|
507
513
|
suffix: Literal["reverse"] = "reverse"
|
|
508
514
|
property_: str = Field(alias="property")
|
|
509
515
|
|
|
510
516
|
|
|
511
|
-
class ReferenceEntity(
|
|
517
|
+
class ReferenceEntity(ConceptEntity):
|
|
512
518
|
type_: ClassVar[EntityTypes] = EntityTypes.reference_entity
|
|
513
519
|
prefix: str
|
|
514
520
|
property_: str | None = Field(None, alias="property")
|
|
515
521
|
|
|
516
522
|
@classmethod
|
|
517
|
-
def from_entity(cls, entity:
|
|
518
|
-
if isinstance(entity,
|
|
523
|
+
def from_entity(cls, entity: ConceptualEntity, property_: str) -> "ReferenceEntity":
|
|
524
|
+
if isinstance(entity, ConceptEntity):
|
|
519
525
|
return cls(
|
|
520
526
|
prefix=str(entity.prefix),
|
|
521
527
|
suffix=entity.suffix,
|
|
@@ -541,5 +547,5 @@ class ReferenceEntity(ClassEntity):
|
|
|
541
547
|
def as_node_entity(self) -> DMSNodeEntity:
|
|
542
548
|
return DMSNodeEntity(space=self.prefix, externalId=self.suffix)
|
|
543
549
|
|
|
544
|
-
def
|
|
545
|
-
return
|
|
550
|
+
def as_concept_entity(self) -> ConceptEntity:
|
|
551
|
+
return ConceptEntity(prefix=self.prefix, suffix=self.suffix, version=self.version)
|
|
@@ -6,7 +6,13 @@ from pydantic import (
|
|
|
6
6
|
PlainSerializer,
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
from ._single_value import
|
|
9
|
+
from ._single_value import (
|
|
10
|
+
AssetEntity,
|
|
11
|
+
ConceptEntity,
|
|
12
|
+
ContainerEntity,
|
|
13
|
+
RelationshipEntity,
|
|
14
|
+
ViewEntity,
|
|
15
|
+
)
|
|
10
16
|
|
|
11
17
|
|
|
12
18
|
def _split_str(v: Any) -> list[str]:
|
|
@@ -15,7 +21,7 @@ def _split_str(v: Any) -> list[str]:
|
|
|
15
21
|
return v
|
|
16
22
|
|
|
17
23
|
|
|
18
|
-
def _join_str(v: list[
|
|
24
|
+
def _join_str(v: list[ConceptEntity]) -> str | None:
|
|
19
25
|
return ",".join([entry.id for entry in v]) if v else None
|
|
20
26
|
|
|
21
27
|
|
|
@@ -39,7 +45,7 @@ def _generate_cdf_resource_list(v: Any) -> list[AssetEntity | RelationshipEntity
|
|
|
39
45
|
|
|
40
46
|
|
|
41
47
|
ClassEntityList = Annotated[
|
|
42
|
-
list[
|
|
48
|
+
list[ConceptEntity],
|
|
43
49
|
BeforeValidator(_split_str),
|
|
44
50
|
]
|
|
45
51
|
|
|
@@ -8,14 +8,14 @@ from cognite.client import data_modeling as dm
|
|
|
8
8
|
from cognite.client.data_classes.data_modeling import ContainerId, NodeId
|
|
9
9
|
from pydantic import BaseModel, model_serializer, model_validator
|
|
10
10
|
|
|
11
|
-
from ._single_value import ContainerEntity, DMSNodeEntity,
|
|
11
|
+
from ._single_value import ConceptualEntity, ContainerEntity, DMSNodeEntity, ViewEntity
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
@total_ordering
|
|
15
15
|
class WrappedEntity(BaseModel, ABC):
|
|
16
16
|
name: ClassVar[str]
|
|
17
|
-
_inner_cls: ClassVar[type[
|
|
18
|
-
inner: list[
|
|
17
|
+
_inner_cls: ClassVar[type[ConceptualEntity]]
|
|
18
|
+
inner: list[ConceptualEntity] | None
|
|
19
19
|
|
|
20
20
|
@classmethod
|
|
21
21
|
def load(cls: "type[T_WrappedEntity]", data: Any) -> "T_WrappedEntity":
|
|
@@ -3,9 +3,12 @@ from pathlib import Path
|
|
|
3
3
|
|
|
4
4
|
import yaml
|
|
5
5
|
|
|
6
|
+
from cognite.neat.core._data_model._shared import ImportedDataModel
|
|
7
|
+
from cognite.neat.core._data_model.models.physical import (
|
|
8
|
+
PhysicalDataModel,
|
|
9
|
+
UnverifiedPhysicalDataModel,
|
|
10
|
+
)
|
|
6
11
|
from cognite.neat.core._issues.errors import NeatValueError
|
|
7
|
-
from cognite.neat.core._rules._shared import ReadRules
|
|
8
|
-
from cognite.neat.core._rules.models.dms import DMSInputRules, DMSRules
|
|
9
12
|
|
|
10
13
|
_CLASSIC_TO_CORE_MAPPING = Path(__file__).resolve().parent / "_classic2core.yaml"
|
|
11
14
|
|
|
@@ -15,9 +18,9 @@ def _read_source_file() -> str:
|
|
|
15
18
|
return _CLASSIC_TO_CORE_MAPPING.read_text()
|
|
16
19
|
|
|
17
20
|
|
|
18
|
-
def load_classic_to_core_mapping(org_name: str | None, source_space: str, source_version: str) ->
|
|
19
|
-
from cognite.neat.core.
|
|
20
|
-
from cognite.neat.core.
|
|
21
|
+
def load_classic_to_core_mapping(org_name: str | None, source_space: str, source_version: str) -> PhysicalDataModel:
|
|
22
|
+
from cognite.neat.core._data_model.importers import DictImporter
|
|
23
|
+
from cognite.neat.core._data_model.transformers import VerifyPhysicalDataModel
|
|
21
24
|
|
|
22
25
|
raw_str = _read_source_file()
|
|
23
26
|
if org_name is not None:
|
|
@@ -27,10 +30,10 @@ def load_classic_to_core_mapping(org_name: str | None, source_space: str, source
|
|
|
27
30
|
loaded["metadata"]["space"] = source_space
|
|
28
31
|
loaded["metadata"]["version"] = source_version
|
|
29
32
|
|
|
30
|
-
read:
|
|
31
|
-
if not isinstance(read.
|
|
32
|
-
raise NeatValueError(f"Expected DMS rules, but got {type(read.
|
|
33
|
+
read: ImportedDataModel[UnverifiedPhysicalDataModel] = DictImporter(loaded).to_data_model()
|
|
34
|
+
if not isinstance(read.unverified_data_model, UnverifiedPhysicalDataModel):
|
|
35
|
+
raise NeatValueError(f"Expected DMS rules, but got {type(read.unverified_data_model).__name__}")
|
|
33
36
|
|
|
34
|
-
verified =
|
|
37
|
+
verified = VerifyPhysicalDataModel(validate=False).transform(read)
|
|
35
38
|
|
|
36
39
|
return verified
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from cognite.neat.core._client.data_classes.schema import DMSSchema
|
|
2
|
+
|
|
3
|
+
from ._unverified import (
|
|
4
|
+
UnverifiedPhysicalContainer,
|
|
5
|
+
UnverifiedPhysicalDataModel,
|
|
6
|
+
UnverifiedPhysicalEnum,
|
|
7
|
+
UnverifiedPhysicalMetadata,
|
|
8
|
+
UnverifiedPhysicalNodeType,
|
|
9
|
+
UnverifiedPhysicalProperty,
|
|
10
|
+
UnverifiedPhysicalView,
|
|
11
|
+
)
|
|
12
|
+
from ._validation import PhysicalValidation
|
|
13
|
+
from ._verified import (
|
|
14
|
+
PhysicalContainer,
|
|
15
|
+
PhysicalDataModel,
|
|
16
|
+
PhysicalEnum,
|
|
17
|
+
PhysicalMetadata,
|
|
18
|
+
PhysicalNodeType,
|
|
19
|
+
PhysicalProperty,
|
|
20
|
+
PhysicalView,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"DMSSchema",
|
|
25
|
+
"PhysicalContainer",
|
|
26
|
+
"PhysicalDataModel",
|
|
27
|
+
"PhysicalEnum",
|
|
28
|
+
"PhysicalMetadata",
|
|
29
|
+
"PhysicalNodeType",
|
|
30
|
+
"PhysicalProperty",
|
|
31
|
+
"PhysicalValidation",
|
|
32
|
+
"PhysicalView",
|
|
33
|
+
"UnverifiedPhysicalContainer",
|
|
34
|
+
"UnverifiedPhysicalDataModel",
|
|
35
|
+
"UnverifiedPhysicalEnum",
|
|
36
|
+
"UnverifiedPhysicalMetadata",
|
|
37
|
+
"UnverifiedPhysicalNodeType",
|
|
38
|
+
"UnverifiedPhysicalProperty",
|
|
39
|
+
"UnverifiedPhysicalView",
|
|
40
|
+
]
|