cognite-neat 0.88.2__py3-none-any.whl → 0.89.0__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/constants.py +3 -0
- cognite/neat/graph/__init__.py +0 -3
- cognite/neat/graph/extractors/_mock_graph_generator.py +2 -1
- cognite/neat/graph/loaders/_base.py +3 -3
- cognite/neat/graph/loaders/_rdf2asset.py +24 -25
- cognite/neat/graph/loaders/_rdf2dms.py +20 -15
- cognite/neat/issues/__init__.py +1 -3
- cognite/neat/issues/_base.py +261 -71
- cognite/neat/issues/errors/__init__.py +73 -0
- cognite/neat/issues/errors/_external.py +67 -0
- cognite/neat/issues/errors/_general.py +35 -0
- cognite/neat/issues/errors/_properties.py +62 -0
- cognite/neat/issues/errors/_resources.py +111 -0
- cognite/neat/issues/errors/_workflow.py +36 -0
- cognite/neat/issues/formatters.py +1 -1
- cognite/neat/issues/warnings/__init__.py +66 -0
- cognite/neat/issues/warnings/_external.py +40 -0
- cognite/neat/issues/warnings/_general.py +29 -0
- cognite/neat/issues/warnings/_models.py +92 -0
- cognite/neat/issues/warnings/_properties.py +44 -0
- cognite/neat/issues/warnings/_resources.py +55 -0
- cognite/neat/issues/warnings/user_modeling.py +113 -0
- cognite/neat/rules/_shared.py +53 -2
- cognite/neat/rules/analysis/_base.py +1 -1
- cognite/neat/rules/exporters/_base.py +7 -18
- cognite/neat/rules/exporters/_rules2dms.py +17 -20
- cognite/neat/rules/exporters/_rules2excel.py +9 -16
- cognite/neat/rules/exporters/_rules2ontology.py +77 -64
- cognite/neat/rules/exporters/_rules2yaml.py +6 -9
- cognite/neat/rules/exporters/_validation.py +11 -96
- cognite/neat/rules/importers/_base.py +9 -58
- cognite/neat/rules/importers/_dms2rules.py +188 -135
- cognite/neat/rules/importers/_dtdl2rules/dtdl_converter.py +48 -35
- cognite/neat/rules/importers/_dtdl2rules/dtdl_importer.py +36 -45
- cognite/neat/rules/importers/_dtdl2rules/spec.py +7 -0
- cognite/neat/rules/importers/_rdf/_imf2rules/_imf2classes.py +8 -4
- cognite/neat/rules/importers/_rdf/_imf2rules/_imf2metadata.py +3 -3
- cognite/neat/rules/importers/_rdf/_imf2rules/_imf2properties.py +18 -11
- cognite/neat/rules/importers/_rdf/_imf2rules/_imf2rules.py +12 -19
- cognite/neat/rules/importers/_rdf/_inference2rules.py +14 -37
- cognite/neat/rules/importers/_rdf/_owl2rules/_owl2classes.py +1 -0
- cognite/neat/rules/importers/_rdf/_owl2rules/_owl2properties.py +1 -0
- cognite/neat/rules/importers/_rdf/_owl2rules/_owl2rules.py +9 -20
- cognite/neat/rules/importers/_rdf/_shared.py +4 -4
- cognite/neat/rules/importers/_spreadsheet2rules.py +46 -97
- cognite/neat/rules/importers/_yaml2rules.py +32 -58
- cognite/neat/rules/models/__init__.py +21 -5
- cognite/neat/rules/models/_base_input.py +162 -0
- cognite/neat/rules/models/{_base.py → _base_rules.py} +1 -12
- cognite/neat/rules/models/_rdfpath.py +4 -4
- cognite/neat/rules/models/{_types/_field.py → _types.py} +5 -10
- cognite/neat/rules/models/asset/__init__.py +5 -2
- cognite/neat/rules/models/asset/_rules.py +3 -23
- cognite/neat/rules/models/asset/_rules_input.py +40 -115
- cognite/neat/rules/models/asset/_validation.py +14 -10
- cognite/neat/rules/models/data_types.py +150 -44
- cognite/neat/rules/models/dms/__init__.py +19 -7
- cognite/neat/rules/models/dms/_exporter.py +102 -34
- cognite/neat/rules/models/dms/_rules.py +65 -162
- cognite/neat/rules/models/dms/_rules_input.py +186 -254
- cognite/neat/rules/models/dms/_schema.py +87 -78
- cognite/neat/rules/models/dms/_serializer.py +44 -3
- cognite/neat/rules/models/dms/_validation.py +106 -68
- cognite/neat/rules/models/domain.py +52 -1
- cognite/neat/rules/models/entities/__init__.py +63 -0
- cognite/neat/rules/models/entities/_constants.py +73 -0
- cognite/neat/rules/models/entities/_loaders.py +76 -0
- cognite/neat/rules/models/entities/_multi_value.py +67 -0
- cognite/neat/rules/models/{entities.py → entities/_single_value.py} +74 -232
- cognite/neat/rules/models/entities/_types.py +86 -0
- cognite/neat/rules/models/{wrapped_entities.py → entities/_wrapped.py} +1 -1
- cognite/neat/rules/models/information/__init__.py +10 -2
- cognite/neat/rules/models/information/_rules.py +10 -22
- cognite/neat/rules/models/information/_rules_input.py +57 -204
- cognite/neat/rules/models/information/_validation.py +48 -25
- cognite/neat/rules/transformers/__init__.py +21 -0
- cognite/neat/rules/transformers/_base.py +81 -0
- cognite/neat/rules/{models/information/_converter.py → transformers/_converters.py} +217 -21
- cognite/neat/rules/transformers/_map_onto.py +97 -0
- cognite/neat/rules/transformers/_pipelines.py +61 -0
- cognite/neat/rules/transformers/_verification.py +136 -0
- cognite/neat/{graph/stores → store}/_provenance.py +10 -1
- cognite/neat/utils/auxiliary.py +2 -35
- cognite/neat/utils/cdf/data_classes.py +20 -0
- cognite/neat/utils/regex_patterns.py +6 -0
- cognite/neat/utils/text.py +17 -0
- cognite/neat/workflows/base.py +4 -4
- cognite/neat/workflows/cdf_store.py +3 -3
- cognite/neat/workflows/steps/data_contracts.py +1 -1
- cognite/neat/workflows/steps/lib/current/graph_extractor.py +3 -3
- cognite/neat/workflows/steps/lib/current/graph_loader.py +2 -2
- cognite/neat/workflows/steps/lib/current/graph_store.py +1 -1
- cognite/neat/workflows/steps/lib/current/rules_exporter.py +116 -47
- cognite/neat/workflows/steps/lib/current/rules_importer.py +30 -28
- cognite/neat/workflows/steps/lib/current/rules_validator.py +5 -6
- cognite/neat/workflows/steps/lib/io/io_steps.py +5 -5
- cognite/neat/workflows/steps_registry.py +4 -5
- {cognite_neat-0.88.2.dist-info → cognite_neat-0.89.0.dist-info}/METADATA +1 -1
- {cognite_neat-0.88.2.dist-info → cognite_neat-0.89.0.dist-info}/RECORD +105 -106
- cognite/neat/exceptions.py +0 -145
- cognite/neat/graph/exceptions.py +0 -90
- cognite/neat/issues/errors/external.py +0 -21
- cognite/neat/issues/errors/properties.py +0 -75
- cognite/neat/issues/errors/resources.py +0 -123
- cognite/neat/issues/errors/schema.py +0 -0
- cognite/neat/issues/neat_warnings/__init__.py +0 -2
- cognite/neat/issues/neat_warnings/identifier.py +0 -27
- cognite/neat/issues/neat_warnings/models.py +0 -22
- cognite/neat/issues/neat_warnings/properties.py +0 -77
- cognite/neat/issues/neat_warnings/resources.py +0 -125
- cognite/neat/rules/issues/__init__.py +0 -22
- cognite/neat/rules/issues/base.py +0 -63
- cognite/neat/rules/issues/dms.py +0 -549
- cognite/neat/rules/issues/fileread.py +0 -197
- cognite/neat/rules/issues/ontology.py +0 -298
- cognite/neat/rules/issues/spreadsheet.py +0 -563
- cognite/neat/rules/issues/spreadsheet_file.py +0 -151
- cognite/neat/rules/issues/tables.py +0 -72
- cognite/neat/rules/models/_constants.py +0 -1
- cognite/neat/rules/models/_types/__init__.py +0 -19
- cognite/neat/rules/models/asset/_converter.py +0 -4
- cognite/neat/rules/models/dms/_converter.py +0 -145
- cognite/neat/workflows/_exceptions.py +0 -41
- /cognite/neat/{graph/stores → store}/__init__.py +0 -0
- /cognite/neat/{graph/stores → store}/_base.py +0 -0
- {cognite_neat-0.88.2.dist-info → cognite_neat-0.89.0.dist-info}/LICENSE +0 -0
- {cognite_neat-0.88.2.dist-info → cognite_neat-0.89.0.dist-info}/WHEEL +0 -0
- {cognite_neat-0.88.2.dist-info → cognite_neat-0.89.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import re
|
|
2
2
|
from dataclasses import dataclass
|
|
3
3
|
from datetime import datetime
|
|
4
|
-
from typing import Any, Literal
|
|
4
|
+
from typing import Any, Literal
|
|
5
5
|
|
|
6
|
-
from cognite.
|
|
6
|
+
from cognite.client import data_modeling as dm
|
|
7
|
+
|
|
8
|
+
from cognite.neat.rules.models._base_input import InputComponent, InputRules
|
|
7
9
|
from cognite.neat.rules.models.data_types import DataType
|
|
8
10
|
from cognite.neat.rules.models.entities import (
|
|
9
11
|
ClassEntity,
|
|
10
12
|
ContainerEntity,
|
|
13
|
+
DMSNodeEntity,
|
|
11
14
|
DMSUnknownEntity,
|
|
12
|
-
|
|
15
|
+
EdgeEntity,
|
|
16
|
+
ReverseConnectionEntity,
|
|
13
17
|
ViewEntity,
|
|
14
|
-
|
|
18
|
+
load_connection,
|
|
19
|
+
load_dms_value_type,
|
|
15
20
|
)
|
|
16
21
|
|
|
17
|
-
from ._rules import DMSContainer, DMSMetadata, DMSProperty, DMSRules, DMSView
|
|
22
|
+
from ._rules import _DEFAULT_VERSION, DMSContainer, DMSEnum, DMSMetadata, DMSNode, DMSProperty, DMSRules, DMSView
|
|
18
23
|
|
|
19
24
|
|
|
20
25
|
@dataclass
|
|
21
|
-
class
|
|
26
|
+
class DMSInputMetadata(InputComponent[DMSMetadata]):
|
|
22
27
|
schema_: Literal["complete", "partial", "extended"]
|
|
23
28
|
space: str
|
|
24
29
|
external_id: str
|
|
@@ -32,51 +37,57 @@ class DMSMetadataInput:
|
|
|
32
37
|
updated: datetime | str | None = None
|
|
33
38
|
|
|
34
39
|
@classmethod
|
|
35
|
-
def
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
def _get_verified_cls(cls) -> type[DMSMetadata]:
|
|
41
|
+
return DMSMetadata
|
|
42
|
+
|
|
43
|
+
def dump(self) -> dict[str, Any]: # type: ignore[override]
|
|
44
|
+
output = super().dump()
|
|
45
|
+
if self.created is None:
|
|
46
|
+
output["created"] = datetime.now()
|
|
47
|
+
if self.updated is None:
|
|
48
|
+
output["updated"] = datetime.now()
|
|
49
|
+
return output
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def from_data_model(cls, data_model: dm.DataModelApply, has_reference: bool) -> "DMSInputMetadata":
|
|
53
|
+
description, creator = cls._get_description_and_creator(data_model.description)
|
|
39
54
|
return cls(
|
|
40
|
-
schema_=
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
created=data.get("created"),
|
|
51
|
-
updated=data.get("updated"),
|
|
55
|
+
schema_="complete",
|
|
56
|
+
data_model_type="solution" if has_reference else "enterprise",
|
|
57
|
+
space=data_model.space,
|
|
58
|
+
name=data_model.name or None,
|
|
59
|
+
description=description,
|
|
60
|
+
external_id=data_model.external_id,
|
|
61
|
+
version=data_model.version,
|
|
62
|
+
creator=",".join(creator),
|
|
63
|
+
created=datetime.now(),
|
|
64
|
+
updated=datetime.now(),
|
|
52
65
|
)
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
description=
|
|
65
|
-
|
|
66
|
-
updated=self.updated or datetime.now(),
|
|
67
|
-
)
|
|
67
|
+
@classmethod
|
|
68
|
+
def _get_description_and_creator(cls, description_raw: str | None) -> tuple[str | None, list[str]]:
|
|
69
|
+
if description_raw and (description_match := re.search(r"Creator: (.+)", description_raw)):
|
|
70
|
+
creator = description_match.group(1).split(", ")
|
|
71
|
+
description = description_raw.replace(description_match.string, "").strip() or None
|
|
72
|
+
elif description_raw:
|
|
73
|
+
creator = ["MISSING"]
|
|
74
|
+
description = description_raw
|
|
75
|
+
else:
|
|
76
|
+
creator = ["MISSING"]
|
|
77
|
+
description = None
|
|
78
|
+
return description, creator
|
|
68
79
|
|
|
69
80
|
|
|
70
81
|
@dataclass
|
|
71
|
-
class
|
|
82
|
+
class DMSInputProperty(InputComponent[DMSProperty]):
|
|
72
83
|
view: str
|
|
73
84
|
view_property: str | None
|
|
74
|
-
value_type: str
|
|
75
|
-
property_: str | None
|
|
85
|
+
value_type: str | DataType | ViewEntity | DMSUnknownEntity
|
|
86
|
+
property_: str | None = None
|
|
76
87
|
class_: str | None = None
|
|
77
88
|
name: str | None = None
|
|
78
89
|
description: str | None = None
|
|
79
|
-
connection: Literal["direct"
|
|
90
|
+
connection: Literal["direct"] | ReverseConnectionEntity | EdgeEntity | str | None = None
|
|
80
91
|
nullable: bool | None = None
|
|
81
92
|
immutable: bool | None = None
|
|
82
93
|
is_list: bool | None = None
|
|
@@ -88,153 +99,76 @@ class DMSPropertyInput:
|
|
|
88
99
|
constraint: str | list[str] | None = None
|
|
89
100
|
|
|
90
101
|
@classmethod
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
cls, data: dict[str, Any] | list[dict[str, Any]] | None
|
|
105
|
-
) -> "DMSPropertyInput | list[DMSPropertyInput] | None":
|
|
106
|
-
if data is None:
|
|
107
|
-
return None
|
|
108
|
-
if isinstance(data, list) or (isinstance(data, dict) and isinstance(data.get("data"), list)):
|
|
109
|
-
items = cast(list[dict[str, Any]], data.get("data") if isinstance(data, dict) else data)
|
|
110
|
-
return [loaded for item in items if (loaded := cls.load(item)) is not None]
|
|
111
|
-
|
|
112
|
-
_add_alias(data, DMSProperty)
|
|
113
|
-
return cls(
|
|
114
|
-
view=data.get("view"), # type: ignore[arg-type]
|
|
115
|
-
view_property=data.get("view_property"), # type: ignore[arg-type]
|
|
116
|
-
value_type=data.get("value_type"), # type: ignore[arg-type]
|
|
117
|
-
property_=data.get("property_"),
|
|
118
|
-
class_=data.get("class_"),
|
|
119
|
-
name=data.get("name"),
|
|
120
|
-
description=data.get("description"),
|
|
121
|
-
connection=data.get("connection"),
|
|
122
|
-
nullable=data.get("nullable"),
|
|
123
|
-
immutable=data.get("immutable"),
|
|
124
|
-
is_list=data.get("is_list"),
|
|
125
|
-
default=data.get("default"),
|
|
126
|
-
reference=data.get("reference"),
|
|
127
|
-
container=data.get("container"),
|
|
128
|
-
container_property=data.get("container_property"),
|
|
129
|
-
index=data.get("index"),
|
|
130
|
-
constraint=data.get("constraint"),
|
|
102
|
+
def _get_verified_cls(cls) -> type[DMSProperty]:
|
|
103
|
+
return DMSProperty
|
|
104
|
+
|
|
105
|
+
def dump(self, default_space: str, default_version: str) -> dict[str, Any]: # type: ignore[override]
|
|
106
|
+
output = super().dump()
|
|
107
|
+
output["View"] = ViewEntity.load(self.view, space=default_space, version=default_version)
|
|
108
|
+
output["Value Type"] = load_dms_value_type(self.value_type, default_space, default_version)
|
|
109
|
+
output["Connection"] = load_connection(self.connection, default_space, default_version)
|
|
110
|
+
output["Property (linage)"] = self.property_ or self.view_property
|
|
111
|
+
output["Class (linage)"] = (
|
|
112
|
+
ClassEntity.load(self.class_ or self.view, prefix=default_space, version=default_version)
|
|
113
|
+
if self.class_ or self.view
|
|
114
|
+
else None
|
|
131
115
|
)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
value_type = DMSUnknownEntity()
|
|
139
|
-
else:
|
|
140
|
-
try:
|
|
141
|
-
value_type = ViewPropertyEntity.load(self.value_type, space=default_space, version=default_version)
|
|
142
|
-
except ValueError:
|
|
143
|
-
value_type = ViewEntity.load(self.value_type, space=default_space, version=default_version)
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
"View": ViewEntity.load(self.view, space=default_space, version=default_version),
|
|
147
|
-
"View Property": self.view_property,
|
|
148
|
-
"Value Type": value_type,
|
|
149
|
-
"Property (linage)": self.property_ or self.view_property,
|
|
150
|
-
"Class (linage)": (
|
|
151
|
-
ClassEntity.load(self.class_ or self.view, prefix=default_space, version=default_version)
|
|
152
|
-
if self.class_ or self.view
|
|
153
|
-
else None
|
|
154
|
-
),
|
|
155
|
-
"Name": self.name,
|
|
156
|
-
"Description": self.description,
|
|
157
|
-
"Connection": self.connection,
|
|
158
|
-
"Nullable": self.nullable,
|
|
159
|
-
"Immutable": self.immutable,
|
|
160
|
-
"Is List": self.is_list,
|
|
161
|
-
"Default": self.default,
|
|
162
|
-
"Reference": self.reference,
|
|
163
|
-
"Container": (
|
|
164
|
-
ContainerEntity.load(self.container, space=default_space, version=default_version)
|
|
165
|
-
if self.container
|
|
166
|
-
else None
|
|
167
|
-
),
|
|
168
|
-
"Container Property": self.container_property,
|
|
169
|
-
"Index": self.index,
|
|
170
|
-
"Constraint": self.constraint,
|
|
171
|
-
}
|
|
116
|
+
output["Container"] = (
|
|
117
|
+
ContainerEntity.load(self.container, space=default_space, version=default_version)
|
|
118
|
+
if self.container
|
|
119
|
+
else None
|
|
120
|
+
)
|
|
121
|
+
return output
|
|
172
122
|
|
|
173
123
|
|
|
174
124
|
@dataclass
|
|
175
|
-
class
|
|
125
|
+
class DMSInputContainer(InputComponent[DMSContainer]):
|
|
176
126
|
container: str
|
|
177
127
|
class_: str | None = None
|
|
178
128
|
name: str | None = None
|
|
179
129
|
description: str | None = None
|
|
180
130
|
reference: str | None = None
|
|
181
131
|
constraint: str | None = None
|
|
132
|
+
used_for: Literal["node", "edge", "all"] | None = None
|
|
182
133
|
|
|
183
134
|
@classmethod
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
@classmethod
|
|
188
|
-
@overload
|
|
189
|
-
def load(cls, data: dict[str, Any]) -> "DMSContainerInput": ...
|
|
135
|
+
def _get_verified_cls(cls) -> type[DMSContainer]:
|
|
136
|
+
return DMSContainer
|
|
190
137
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
138
|
+
def dump(self, default_space: str) -> dict[str, Any]: # type: ignore[override]
|
|
139
|
+
output = super().dump()
|
|
140
|
+
container = ContainerEntity.load(self.container, space=default_space)
|
|
141
|
+
output["Container"] = container
|
|
142
|
+
output["Class (linage)"] = (
|
|
143
|
+
ClassEntity.load(self.class_, prefix=default_space) if self.class_ else container.as_class()
|
|
144
|
+
)
|
|
145
|
+
output["Constraint"] = (
|
|
146
|
+
[ContainerEntity.load(constraint.strip(), space=default_space) for constraint in self.constraint.split(",")]
|
|
147
|
+
if self.constraint
|
|
148
|
+
else None
|
|
149
|
+
)
|
|
150
|
+
return output
|
|
194
151
|
|
|
195
152
|
@classmethod
|
|
196
|
-
def
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return [loaded for item in items if (loaded := cls.load(item)) is not None]
|
|
204
|
-
|
|
205
|
-
_add_alias(data, DMSContainer)
|
|
153
|
+
def from_container(cls, container: dm.ContainerApply) -> "DMSInputContainer":
|
|
154
|
+
constraints: list[str] = []
|
|
155
|
+
for _, constraint_obj in (container.constraints or {}).items():
|
|
156
|
+
if isinstance(constraint_obj, dm.RequiresConstraint):
|
|
157
|
+
constraints.append(str(ContainerEntity.from_id(constraint_obj.require)))
|
|
158
|
+
# UniquenessConstraint it handled in the properties
|
|
159
|
+
container_entity = ContainerEntity.from_id(container.as_id())
|
|
206
160
|
return cls(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
name=
|
|
210
|
-
description=
|
|
211
|
-
|
|
212
|
-
|
|
161
|
+
class_=str(container_entity.as_class()),
|
|
162
|
+
container=str(container_entity),
|
|
163
|
+
name=container.name or None,
|
|
164
|
+
description=container.description,
|
|
165
|
+
constraint=", ".join(constraints) or None,
|
|
166
|
+
used_for=container.used_for,
|
|
213
167
|
)
|
|
214
168
|
|
|
215
|
-
def dump(self, default_space: str) -> dict[str, Any]:
|
|
216
|
-
container = ContainerEntity.load(self.container, space=default_space)
|
|
217
|
-
return {
|
|
218
|
-
"Container": container,
|
|
219
|
-
"Class (linage)": (
|
|
220
|
-
ClassEntity.load(self.class_, prefix=default_space) if self.class_ else container.as_class()
|
|
221
|
-
),
|
|
222
|
-
"Name": self.name,
|
|
223
|
-
"Description": self.description,
|
|
224
|
-
"Reference": self.reference,
|
|
225
|
-
"Constraint": (
|
|
226
|
-
[
|
|
227
|
-
ContainerEntity.load(constraint.strip(), space=default_space)
|
|
228
|
-
for constraint in self.constraint.split(",")
|
|
229
|
-
]
|
|
230
|
-
if self.constraint
|
|
231
|
-
else None
|
|
232
|
-
),
|
|
233
|
-
}
|
|
234
|
-
|
|
235
169
|
|
|
236
170
|
@dataclass
|
|
237
|
-
class
|
|
171
|
+
class DMSInputView(InputComponent[DMSView]):
|
|
238
172
|
view: str
|
|
239
173
|
class_: str | None = None
|
|
240
174
|
name: str | None = None
|
|
@@ -245,117 +179,115 @@ class DMSViewInput:
|
|
|
245
179
|
in_model: bool = True
|
|
246
180
|
|
|
247
181
|
@classmethod
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
@classmethod
|
|
252
|
-
@overload
|
|
253
|
-
def load(cls, data: dict[str, Any]) -> "DMSViewInput": ...
|
|
182
|
+
def _get_verified_cls(cls) -> type[DMSView]:
|
|
183
|
+
return DMSView
|
|
254
184
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
185
|
+
def dump(self, default_space: str, default_version: str) -> dict[str, Any]: # type: ignore[override]
|
|
186
|
+
output = super().dump()
|
|
187
|
+
view = ViewEntity.load(self.view, space=default_space, version=default_version)
|
|
188
|
+
output["View"] = view
|
|
189
|
+
output["Class (linage)"] = (
|
|
190
|
+
ClassEntity.load(self.class_, prefix=default_space, version=default_version)
|
|
191
|
+
if self.class_
|
|
192
|
+
else view.as_class()
|
|
193
|
+
)
|
|
194
|
+
output["Implements"] = (
|
|
195
|
+
[
|
|
196
|
+
ViewEntity.load(implement, space=default_space, version=default_version)
|
|
197
|
+
for implement in self.implements.split(",")
|
|
198
|
+
]
|
|
199
|
+
if self.implements
|
|
200
|
+
else None
|
|
201
|
+
)
|
|
202
|
+
return output
|
|
258
203
|
|
|
259
204
|
@classmethod
|
|
260
|
-
def
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if isinstance(data, list) or (isinstance(data, dict) and isinstance(data.get("data"), list)):
|
|
264
|
-
items = cast(list[dict[str, Any]], data.get("data") if isinstance(data, dict) else data)
|
|
265
|
-
return [loaded for item in items if (loaded := cls.load(item)) is not None]
|
|
266
|
-
_add_alias(data, DMSView)
|
|
205
|
+
def from_view(cls, view: dm.ViewApply, in_model: bool) -> "DMSInputView":
|
|
206
|
+
view_entity = ViewEntity.from_id(view.as_id())
|
|
207
|
+
class_entity = view_entity.as_class(skip_version=True)
|
|
267
208
|
|
|
268
209
|
return cls(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
implements=
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
in_model=data.get("in_model", True),
|
|
210
|
+
class_=str(class_entity),
|
|
211
|
+
view=str(view_entity),
|
|
212
|
+
description=view.description,
|
|
213
|
+
name=view.name,
|
|
214
|
+
implements=", ".join([str(ViewEntity.from_id(parent, _DEFAULT_VERSION)) for parent in view.implements])
|
|
215
|
+
or None,
|
|
216
|
+
in_model=in_model,
|
|
277
217
|
)
|
|
278
218
|
|
|
279
|
-
def dump(self, default_space: str, default_version: str) -> dict[str, Any]:
|
|
280
|
-
view = ViewEntity.load(self.view, space=default_space, version=default_version)
|
|
281
|
-
return {
|
|
282
|
-
"View": view,
|
|
283
|
-
"Class (linage)": (
|
|
284
|
-
ClassEntity.load(self.class_, prefix=default_space, version=default_version)
|
|
285
|
-
if self.class_
|
|
286
|
-
else view.as_class()
|
|
287
|
-
),
|
|
288
|
-
"Name": self.name,
|
|
289
|
-
"Description": self.description,
|
|
290
|
-
"Implements": (
|
|
291
|
-
[
|
|
292
|
-
ViewEntity.load(implement, space=default_space, version=default_version)
|
|
293
|
-
for implement in self.implements.split(",")
|
|
294
|
-
]
|
|
295
|
-
if self.implements
|
|
296
|
-
else None
|
|
297
|
-
),
|
|
298
|
-
"Reference": self.reference,
|
|
299
|
-
"Filter": self.filter_,
|
|
300
|
-
"In Model": self.in_model,
|
|
301
|
-
}
|
|
302
|
-
|
|
303
219
|
|
|
304
220
|
@dataclass
|
|
305
|
-
class
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
last: "DMSRulesInput | DMSRules | None" = None
|
|
311
|
-
reference: "DMSRulesInput | DMSRules | None" = None
|
|
221
|
+
class DMSInputNode(InputComponent[DMSNode]):
|
|
222
|
+
node: str
|
|
223
|
+
usage: Literal["type", "collocation"]
|
|
224
|
+
name: str | None = None
|
|
225
|
+
description: str | None = None
|
|
312
226
|
|
|
313
227
|
@classmethod
|
|
314
|
-
|
|
315
|
-
|
|
228
|
+
def _get_verified_cls(cls) -> type[DMSNode]:
|
|
229
|
+
return DMSNode
|
|
316
230
|
|
|
317
231
|
@classmethod
|
|
318
|
-
|
|
319
|
-
|
|
232
|
+
def from_node_type(cls, node_type: dm.NodeApply) -> "DMSInputNode":
|
|
233
|
+
return cls(node=f"{node_type.space}:{node_type.external_id}", usage="type")
|
|
234
|
+
|
|
235
|
+
def dump(self, default_space: str, **_) -> dict[str, Any]: # type: ignore[override]
|
|
236
|
+
output = super().dump()
|
|
237
|
+
output["Node"] = DMSNodeEntity.load(self.node, space=default_space)
|
|
238
|
+
return output
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
@dataclass
|
|
242
|
+
class DMSInputEnum(InputComponent[DMSEnum]):
|
|
243
|
+
collection: str
|
|
244
|
+
value: str
|
|
245
|
+
name: str | None = None
|
|
246
|
+
description: str | None = None
|
|
320
247
|
|
|
321
248
|
@classmethod
|
|
322
|
-
def
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
_add_alias(data, DMSRules)
|
|
326
|
-
return cls(
|
|
327
|
-
metadata=DMSMetadataInput.load(data.get("metadata")), # type: ignore[arg-type]
|
|
328
|
-
properties=DMSPropertyInput.load(data.get("properties")), # type: ignore[arg-type]
|
|
329
|
-
views=DMSViewInput.load(data.get("views")), # type: ignore[arg-type]
|
|
330
|
-
containers=DMSContainerInput.load(data.get("containers")) or [],
|
|
331
|
-
last=DMSRulesInput.load(data.get("last")),
|
|
332
|
-
reference=DMSRulesInput.load(data.get("reference")),
|
|
333
|
-
)
|
|
249
|
+
def _get_verified_cls(cls) -> type[DMSEnum]:
|
|
250
|
+
return DMSEnum
|
|
251
|
+
|
|
334
252
|
|
|
335
|
-
|
|
336
|
-
|
|
253
|
+
@dataclass
|
|
254
|
+
class DMSInputRules(InputRules[DMSRules]):
|
|
255
|
+
metadata: DMSInputMetadata
|
|
256
|
+
properties: list[DMSInputProperty]
|
|
257
|
+
views: list[DMSInputView]
|
|
258
|
+
containers: list[DMSInputContainer] | None = None
|
|
259
|
+
enum: list[DMSInputEnum] | None = None
|
|
260
|
+
nodes: list[DMSInputNode] | None = None
|
|
261
|
+
last: "DMSInputRules | None" = None
|
|
262
|
+
reference: "DMSInputRules | None" = None
|
|
263
|
+
|
|
264
|
+
@classmethod
|
|
265
|
+
def _get_verified_cls(cls) -> type[DMSRules]:
|
|
266
|
+
return DMSRules
|
|
337
267
|
|
|
338
268
|
def dump(self) -> dict[str, Any]:
|
|
339
269
|
default_space = self.metadata.space
|
|
340
270
|
default_version = self.metadata.version
|
|
341
271
|
reference: dict[str, Any] | None = None
|
|
342
|
-
if isinstance(self.reference,
|
|
272
|
+
if isinstance(self.reference, DMSInputRules):
|
|
343
273
|
reference = self.reference.dump()
|
|
344
274
|
elif isinstance(self.reference, DMSRules):
|
|
345
275
|
# We need to load through the DMSRulesInput to set the correct default space and version
|
|
346
|
-
reference =
|
|
276
|
+
reference = DMSInputRules.load(self.reference.model_dump()).dump()
|
|
347
277
|
last: dict[str, Any] | None = None
|
|
348
|
-
if isinstance(self.last,
|
|
278
|
+
if isinstance(self.last, DMSInputRules):
|
|
349
279
|
last = self.last.dump()
|
|
350
280
|
elif isinstance(self.last, DMSRules):
|
|
351
281
|
# We need to load through the DMSRulesInput to set the correct default space and version
|
|
352
|
-
last =
|
|
353
|
-
|
|
354
|
-
return
|
|
355
|
-
Metadata
|
|
356
|
-
Properties
|
|
357
|
-
Views
|
|
358
|
-
Containers
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
282
|
+
last = DMSInputRules.load(self.last.model_dump()).dump()
|
|
283
|
+
|
|
284
|
+
return {
|
|
285
|
+
"Metadata": self.metadata.dump(),
|
|
286
|
+
"Properties": [prop.dump(default_space, default_version) for prop in self.properties],
|
|
287
|
+
"Views": [view.dump(default_space, default_version) for view in self.views],
|
|
288
|
+
"Containers": [container.dump(default_space) for container in self.containers or []] or None,
|
|
289
|
+
"Enum": [enum.dump() for enum in self.enum or []] or None,
|
|
290
|
+
"Nodes": [node_type.dump(default_space) for node_type in self.nodes or []] or None,
|
|
291
|
+
"Last": last,
|
|
292
|
+
"Reference": reference,
|
|
293
|
+
}
|