cognite-neat 0.117.6__py3-none-any.whl → 0.117.7__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/data_classes/schema.py +3 -1
- cognite/neat/_graph/extractors/_classic_cdf/_base.py +4 -3
- cognite/neat/_graph/extractors/_classic_cdf/_classic.py +42 -24
- cognite/neat/_graph/extractors/_classic_cdf/_sequences.py +4 -3
- cognite/neat/_graph/extractors/_dexpi.py +4 -3
- cognite/neat/_graph/extractors/_iodd.py +4 -3
- cognite/neat/_graph/extractors/_mock_graph_generator.py +1 -1
- cognite/neat/_graph/extractors/_rdf_file.py +2 -1
- cognite/neat/_graph/loaders/_rdf2dms.py +6 -6
- cognite/neat/_graph/transformers/_iodd.py +2 -2
- cognite/neat/_graph/transformers/_prune_graph.py +9 -7
- cognite/neat/_graph/transformers/_value_type.py +5 -4
- cognite/neat/_issues/formatters.py +1 -1
- cognite/neat/_rules/_shared.py +1 -1
- cognite/neat/_rules/exporters/_rules2dms.py +1 -1
- cognite/neat/_rules/exporters/_rules2excel.py +1 -1
- cognite/neat/_rules/exporters/_rules2instance_template.py +6 -6
- cognite/neat/_rules/exporters/_rules2ontology.py +6 -6
- cognite/neat/_rules/importers/_dms2rules.py +1 -1
- cognite/neat/_rules/importers/_dtdl2rules/dtdl_converter.py +1 -1
- cognite/neat/_rules/importers/_dtdl2rules/spec.py +1 -1
- cognite/neat/_rules/importers/_rdf/_base.py +5 -3
- cognite/neat/_rules/importers/_rdf/_inference2rules.py +5 -5
- cognite/neat/_rules/importers/_rdf/_shared.py +1 -1
- cognite/neat/_rules/models/_base_input.py +1 -1
- cognite/neat/_rules/models/_base_rules.py +5 -15
- cognite/neat/_rules/models/_types.py +1 -1
- cognite/neat/_rules/models/dms/_rules_input.py +3 -3
- cognite/neat/_rules/models/entities/_constants.py +1 -1
- cognite/neat/_rules/models/entities/_multi_value.py +1 -1
- cognite/neat/_rules/models/entities/_single_value.py +9 -7
- cognite/neat/_rules/models/entities/_wrapped.py +2 -2
- cognite/neat/_rules/models/information/_rules.py +6 -5
- cognite/neat/_rules/models/information/_rules_input.py +4 -4
- cognite/neat/_rules/transformers/_mapping.py +2 -1
- cognite/neat/_session/_collector.py +1 -1
- cognite/neat/_session/_read.py +1 -1
- cognite/neat/_session/exceptions.py +4 -4
- cognite/neat/_store/_provenance.py +3 -3
- cognite/neat/_store/_rules_store.py +3 -3
- cognite/neat/_store/exceptions.py +3 -3
- cognite/neat/_utils/auth.py +1 -1
- cognite/neat/_utils/auxiliary.py +6 -4
- cognite/neat/_utils/rdf_.py +4 -4
- cognite/neat/_utils/reader/_base.py +1 -1
- cognite/neat/_utils/spreadsheet.py +1 -1
- cognite/neat/_utils/text.py +1 -1
- cognite/neat/_utils/time_.py +1 -1
- cognite/neat/_version.py +1 -1
- {cognite_neat-0.117.6.dist-info → cognite_neat-0.117.7.dist-info}/METADATA +1 -1
- {cognite_neat-0.117.6.dist-info → cognite_neat-0.117.7.dist-info}/RECORD +54 -54
- {cognite_neat-0.117.6.dist-info → cognite_neat-0.117.7.dist-info}/LICENSE +0 -0
- {cognite_neat-0.117.6.dist-info → cognite_neat-0.117.7.dist-info}/WHEEL +0 -0
- {cognite_neat-0.117.6.dist-info → cognite_neat-0.117.7.dist-info}/entry_points.txt +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
from pathlib import Path
|
|
3
|
+
from typing import Any
|
|
3
4
|
|
|
4
5
|
from cognite.client import data_modeling as dm
|
|
5
6
|
from rdflib import Graph, Namespace, URIRef
|
|
7
|
+
from typing_extensions import Self
|
|
6
8
|
|
|
7
9
|
from cognite.neat._constants import get_default_prefixes_and_namespaces
|
|
8
10
|
from cognite.neat._issues import IssueList, MultiValueError
|
|
@@ -69,7 +71,7 @@ class BaseRDFImporter(BaseImporter[InformationInputRules]):
|
|
|
69
71
|
max_number_of_instance: int = -1,
|
|
70
72
|
non_existing_node_type: UnknownEntity | AnyURI = DEFAULT_NON_EXISTING_NODE_TYPE,
|
|
71
73
|
language: str = "en",
|
|
72
|
-
):
|
|
74
|
+
) -> Self:
|
|
73
75
|
return cls(
|
|
74
76
|
IssueList(title=f"{cls.__name__} issues"),
|
|
75
77
|
store.dataset,
|
|
@@ -88,7 +90,7 @@ class BaseRDFImporter(BaseImporter[InformationInputRules]):
|
|
|
88
90
|
non_existing_node_type: UnknownEntity | AnyURI = DEFAULT_NON_EXISTING_NODE_TYPE,
|
|
89
91
|
language: str = "en",
|
|
90
92
|
source_name: str = "Unknown",
|
|
91
|
-
):
|
|
93
|
+
) -> Self:
|
|
92
94
|
issue_list = IssueList(title=f"{cls.__name__} issues")
|
|
93
95
|
|
|
94
96
|
graph = Graph()
|
|
@@ -132,7 +134,7 @@ class BaseRDFImporter(BaseImporter[InformationInputRules]):
|
|
|
132
134
|
raise NotImplementedError()
|
|
133
135
|
|
|
134
136
|
@classmethod
|
|
135
|
-
def _add_uri_namespace_to_prefixes(cls, URI: URIRef, prefixes: dict[str, Namespace]):
|
|
137
|
+
def _add_uri_namespace_to_prefixes(cls: Any, URI: URIRef, prefixes: dict[str, Namespace]) -> None:
|
|
136
138
|
"""Add URI to prefixes dict if not already present
|
|
137
139
|
|
|
138
140
|
Args:
|
|
@@ -264,24 +264,24 @@ class InferenceImporter(BaseRDFImporter):
|
|
|
264
264
|
property_["value_type"] = next(iter(property_["value_type"]))
|
|
265
265
|
|
|
266
266
|
return {
|
|
267
|
-
"metadata": self._default_metadata()
|
|
267
|
+
"metadata": self._default_metadata(),
|
|
268
268
|
"classes": list(classes.values()),
|
|
269
269
|
"properties": list(properties.values()),
|
|
270
270
|
"prefixes": prefixes,
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
def _default_metadata(self):
|
|
273
|
+
def _default_metadata(self) -> dict[str, Any]:
|
|
274
274
|
now = datetime.now(timezone.utc)
|
|
275
275
|
return InformationMetadata(
|
|
276
276
|
space=self.data_model_id.space,
|
|
277
277
|
external_id=self.data_model_id.external_id,
|
|
278
|
-
version=self.data_model_id.version,
|
|
278
|
+
version=cast(str, self.data_model_id.version),
|
|
279
279
|
name="Inferred Model",
|
|
280
|
-
creator="NEAT",
|
|
280
|
+
creator=["NEAT"],
|
|
281
281
|
created=now,
|
|
282
282
|
updated=now,
|
|
283
283
|
description="Inferred model from knowledge graph",
|
|
284
|
-
)
|
|
284
|
+
).model_dump()
|
|
285
285
|
|
|
286
286
|
@property
|
|
287
287
|
def source_uri(self) -> URIRef:
|
|
@@ -170,7 +170,7 @@ class InputComponent(ABC, Generic[T_RuleModel]):
|
|
|
170
170
|
args[field_name] = data[field_.alias]
|
|
171
171
|
return cls(**args)
|
|
172
172
|
|
|
173
|
-
def dump(self, **kwargs) -> dict[str, Any]:
|
|
173
|
+
def dump(self, **kwargs: Any) -> dict[str, Any]:
|
|
174
174
|
return {
|
|
175
175
|
field_.alias or name: getattr(self, name)
|
|
176
176
|
for name, field_ in self._get_verified_cls().model_fields.items()
|
|
@@ -8,17 +8,7 @@ import types
|
|
|
8
8
|
from abc import ABC, abstractmethod
|
|
9
9
|
from collections.abc import Callable, Hashable, Iterator, MutableSequence, Sequence
|
|
10
10
|
from datetime import datetime
|
|
11
|
-
from typing import
|
|
12
|
-
Annotated,
|
|
13
|
-
Any,
|
|
14
|
-
ClassVar,
|
|
15
|
-
Literal,
|
|
16
|
-
SupportsIndex,
|
|
17
|
-
TypeVar,
|
|
18
|
-
get_args,
|
|
19
|
-
get_origin,
|
|
20
|
-
overload,
|
|
21
|
-
)
|
|
11
|
+
from typing import Annotated, Any, ClassVar, Literal, SupportsIndex, TypeVar, get_args, get_origin, overload
|
|
22
12
|
|
|
23
13
|
import pandas as pd
|
|
24
14
|
from cognite.client import data_modeling as dm
|
|
@@ -128,7 +118,7 @@ class SchemaModel(BaseModel):
|
|
|
128
118
|
)
|
|
129
119
|
|
|
130
120
|
@classmethod
|
|
131
|
-
def mandatory_fields(cls, use_alias=False) -> set[str]:
|
|
121
|
+
def mandatory_fields(cls: Any, use_alias: bool = False) -> set[str]:
|
|
132
122
|
"""Returns a set of mandatory fields for the model."""
|
|
133
123
|
return _get_required_fields(cls, use_alias)
|
|
134
124
|
|
|
@@ -193,7 +183,7 @@ class BaseMetadata(SchemaModel):
|
|
|
193
183
|
return value
|
|
194
184
|
|
|
195
185
|
@field_validator("description", mode="before")
|
|
196
|
-
def nan_as_none(cls, value):
|
|
186
|
+
def nan_as_none(cls: Any, value: Any) -> Any:
|
|
197
187
|
if isinstance(value, float) and math.isnan(value):
|
|
198
188
|
return None
|
|
199
189
|
return value
|
|
@@ -207,7 +197,7 @@ class BaseMetadata(SchemaModel):
|
|
|
207
197
|
return self.to_pandas().to_frame("value")._repr_html_() # type: ignore[operator]
|
|
208
198
|
|
|
209
199
|
@classmethod
|
|
210
|
-
def mandatory_fields(cls, use_alias=False) -> set[str]:
|
|
200
|
+
def mandatory_fields(cls: Any, use_alias: bool = False) -> set[str]:
|
|
211
201
|
"""Returns a set of mandatory fields for the model."""
|
|
212
202
|
return _get_required_fields(cls, use_alias)
|
|
213
203
|
|
|
@@ -293,7 +283,7 @@ class BaseRules(SchemaModel, ABC):
|
|
|
293
283
|
return headers_by_sheet
|
|
294
284
|
|
|
295
285
|
@property
|
|
296
|
-
def display_name(self):
|
|
286
|
+
def display_name(self) -> str:
|
|
297
287
|
return uri_display_name(self.metadata.identifier)
|
|
298
288
|
|
|
299
289
|
def dump(
|
|
@@ -110,7 +110,7 @@ VersionType = Annotated[
|
|
|
110
110
|
]
|
|
111
111
|
|
|
112
112
|
|
|
113
|
-
def _external_id_validation_factory(entity_type: EntityTypes, location: str):
|
|
113
|
+
def _external_id_validation_factory(entity_type: EntityTypes, location: str) -> Callable:
|
|
114
114
|
def _external_id_validation(value: str) -> str:
|
|
115
115
|
compiled_regex = PATTERNS.entity_pattern(entity_type)
|
|
116
116
|
if not compiled_regex.match(value):
|
|
@@ -253,7 +253,7 @@ class DMSInputView(InputComponent[DMSView]):
|
|
|
253
253
|
neatId: str | URIRef | None = None
|
|
254
254
|
logical: str | URIRef | None = None
|
|
255
255
|
|
|
256
|
-
def __post_init__(self):
|
|
256
|
+
def __post_init__(self) -> None:
|
|
257
257
|
if self.in_model is None:
|
|
258
258
|
self.in_model = True
|
|
259
259
|
|
|
@@ -316,7 +316,7 @@ class DMSInputNode(InputComponent[DMSNode]):
|
|
|
316
316
|
def from_node_type(cls, node_type: dm.NodeApply) -> "DMSInputNode":
|
|
317
317
|
return cls(node=f"{node_type.space}:{node_type.external_id}", usage="type")
|
|
318
318
|
|
|
319
|
-
def dump(self, default_space: str, **_) -> dict[str, Any]: # type: ignore
|
|
319
|
+
def dump(self, default_space: str, **_) -> dict[str, Any]: # type: ignore
|
|
320
320
|
output = super().dump()
|
|
321
321
|
output["Node"] = DMSNodeEntity.load(self.node, space=default_space)
|
|
322
322
|
return output
|
|
@@ -366,7 +366,7 @@ class DMSInputRules(InputRules[DMSRules]):
|
|
|
366
366
|
return "UnverifiedDMSModel"
|
|
367
367
|
|
|
368
368
|
@property
|
|
369
|
-
def display_name(self):
|
|
369
|
+
def display_name(self) -> str:
|
|
370
370
|
return uri_display_name(self.metadata.identifier)
|
|
371
371
|
|
|
372
372
|
def _repr_html_(self) -> str:
|
|
@@ -62,7 +62,7 @@ class MultiValueTypeInfo(BaseModel):
|
|
|
62
62
|
]
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
def set_default_prefix(self, prefix: str):
|
|
65
|
+
def set_default_prefix(self, prefix: str) -> None:
|
|
66
66
|
for type_ in self.types:
|
|
67
67
|
if isinstance(type_, ClassEntity) and type_.prefix is Undefined:
|
|
68
68
|
type_.prefix = prefix
|
|
@@ -59,16 +59,16 @@ class Entity(BaseModel, extra="ignore"):
|
|
|
59
59
|
|
|
60
60
|
@classmethod
|
|
61
61
|
@overload
|
|
62
|
-
def load(cls: "type[T_Entity]", data: Any, strict: Literal[True], **defaults) -> "T_Entity": ...
|
|
62
|
+
def load(cls: "type[T_Entity]", data: Any, strict: Literal[True], **defaults: Any) -> "T_Entity": ...
|
|
63
63
|
|
|
64
64
|
@classmethod
|
|
65
65
|
@overload
|
|
66
66
|
def load(
|
|
67
|
-
cls: "type[T_Entity]", data: Any, strict: Literal[False] = False, **defaults
|
|
67
|
+
cls: "type[T_Entity]", data: Any, strict: Literal[False] = False, **defaults: Any
|
|
68
68
|
) -> "T_Entity | UnknownEntity": ...
|
|
69
69
|
|
|
70
70
|
@classmethod
|
|
71
|
-
def load(cls: "type[T_Entity]", data: Any, strict: bool = False, **defaults) -> "T_Entity | UnknownEntity":
|
|
71
|
+
def load(cls: "type[T_Entity]", data: Any, strict: bool = False, **defaults: Any) -> "T_Entity | UnknownEntity":
|
|
72
72
|
if isinstance(data, cls):
|
|
73
73
|
return data
|
|
74
74
|
elif isinstance(data, str) and data == str(Unknown):
|
|
@@ -270,7 +270,7 @@ class ClassEntity(Entity):
|
|
|
270
270
|
type_: ClassVar[EntityTypes] = EntityTypes.class_
|
|
271
271
|
version: str | None = None
|
|
272
272
|
|
|
273
|
-
def as_view_entity(self, default_space: str, default_version) -> "ViewEntity":
|
|
273
|
+
def as_view_entity(self, default_space: str, default_version: str) -> "ViewEntity":
|
|
274
274
|
if self.version is None:
|
|
275
275
|
version = default_version
|
|
276
276
|
else:
|
|
@@ -339,16 +339,18 @@ class DMSEntity(Entity, Generic[T_ID], ABC):
|
|
|
339
339
|
|
|
340
340
|
@classmethod # type: ignore[override]
|
|
341
341
|
@overload
|
|
342
|
-
def load(cls: "type[T_DMSEntity]", data: Any, strict: Literal[True], **defaults) -> "T_DMSEntity": ...
|
|
342
|
+
def load(cls: "type[T_DMSEntity]", data: Any, strict: Literal[True], **defaults: Any) -> "T_DMSEntity": ...
|
|
343
343
|
|
|
344
344
|
@classmethod
|
|
345
345
|
@overload
|
|
346
346
|
def load(
|
|
347
|
-
cls: "type[T_DMSEntity]", data: Any, strict: Literal[False] = False, **defaults
|
|
347
|
+
cls: "type[T_DMSEntity]", data: Any, strict: Literal[False] = False, **defaults: Any
|
|
348
348
|
) -> "T_DMSEntity | DMSUnknownEntity": ...
|
|
349
349
|
|
|
350
350
|
@classmethod
|
|
351
|
-
def load(
|
|
351
|
+
def load(
|
|
352
|
+
cls: "type[T_DMSEntity]", data: Any, strict: bool = False, **defaults: Any
|
|
353
|
+
) -> "T_DMSEntity | DMSUnknownEntity": # type: ignore
|
|
352
354
|
if isinstance(data, str) and data == str(Unknown):
|
|
353
355
|
if strict:
|
|
354
356
|
raise NeatValueError(f"Failed to load entity {data!s}")
|
|
@@ -57,7 +57,7 @@ class WrappedEntity(BaseModel, ABC):
|
|
|
57
57
|
def as_str(self) -> str:
|
|
58
58
|
return str(self)
|
|
59
59
|
|
|
60
|
-
def __str__(self):
|
|
60
|
+
def __str__(self) -> str:
|
|
61
61
|
return self.id
|
|
62
62
|
|
|
63
63
|
@property
|
|
@@ -206,5 +206,5 @@ class RawFilter(DMSFilter):
|
|
|
206
206
|
def __repr__(self) -> str:
|
|
207
207
|
return self.filter
|
|
208
208
|
|
|
209
|
-
def __str__(self):
|
|
209
|
+
def __str__(self) -> str:
|
|
210
210
|
return f"{self.name}({self.filter})"
|
|
@@ -186,26 +186,27 @@ class InformationProperty(SheetRow):
|
|
|
186
186
|
return value
|
|
187
187
|
|
|
188
188
|
@model_validator(mode="after")
|
|
189
|
-
def set_type_for_default(self):
|
|
189
|
+
def set_type_for_default(self) -> Any:
|
|
190
190
|
if self.type_ == EntityTypes.data_property and self.default:
|
|
191
191
|
default_value = self.default[0] if isinstance(self.default, list) else self.default
|
|
192
192
|
|
|
193
|
-
if type(default_value) is not self.value_type.python:
|
|
193
|
+
if type(default_value) is not self.value_type.python: # type: ignore
|
|
194
194
|
try:
|
|
195
195
|
if isinstance(self.default, list):
|
|
196
196
|
updated_list = []
|
|
197
197
|
for value in self.default:
|
|
198
|
-
updated_list.append(self.value_type.python(value))
|
|
198
|
+
updated_list.append(self.value_type.python(value)) # type: ignore
|
|
199
199
|
self.default = updated_list
|
|
200
200
|
else:
|
|
201
|
-
self.default = self.value_type.python(self.default)
|
|
201
|
+
self.default = self.value_type.python(self.default) # type: ignore
|
|
202
202
|
|
|
203
|
+
# this value_type.python does not seems correct. Need to check this further
|
|
203
204
|
except Exception:
|
|
204
205
|
raise PropertyDefinitionError(
|
|
205
206
|
self.class_,
|
|
206
207
|
"Class",
|
|
207
208
|
self.property_,
|
|
208
|
-
f"Default value {self.default} is not of type {self.value_type.python}",
|
|
209
|
+
f"Default value {self.default} is not of type {self.value_type.python}", # type: ignore
|
|
209
210
|
) from None
|
|
210
211
|
return self
|
|
211
212
|
|
|
@@ -43,7 +43,7 @@ class InformationInputMetadata(InputComponent[InformationMetadata]):
|
|
|
43
43
|
def _get_verified_cls(cls) -> type[InformationMetadata]:
|
|
44
44
|
return InformationMetadata
|
|
45
45
|
|
|
46
|
-
def dump(self, **kwargs) -> dict[str, Any]:
|
|
46
|
+
def dump(self, **kwargs: Any) -> dict[str, Any]:
|
|
47
47
|
output = super().dump()
|
|
48
48
|
if self.created is None:
|
|
49
49
|
output["created"] = datetime.now()
|
|
@@ -97,7 +97,7 @@ class InformationInputProperty(InputComponent[InformationProperty]):
|
|
|
97
97
|
def _get_verified_cls(cls) -> type[InformationProperty]:
|
|
98
98
|
return InformationProperty
|
|
99
99
|
|
|
100
|
-
def dump(self, default_prefix: str, **kwargs) -> dict[str, Any]: # type: ignore
|
|
100
|
+
def dump(self, default_prefix: str, **kwargs) -> dict[str, Any]: # type: ignore
|
|
101
101
|
output = super().dump()
|
|
102
102
|
output["Class"] = ClassEntity.load(self.class_, prefix=default_prefix)
|
|
103
103
|
output["Value Type"] = load_value_type(self.value_type, default_prefix)
|
|
@@ -124,7 +124,7 @@ class InformationInputClass(InputComponent[InformationClass]):
|
|
|
124
124
|
def class_str(self) -> str:
|
|
125
125
|
return str(self.class_)
|
|
126
126
|
|
|
127
|
-
def dump(self, default_prefix: str, **kwargs) -> dict[str, Any]: # type: ignore
|
|
127
|
+
def dump(self, default_prefix: str, **kwargs) -> dict[str, Any]: # type: ignore
|
|
128
128
|
output = super().dump()
|
|
129
129
|
parent: list[ClassEntity] | None = None
|
|
130
130
|
if isinstance(self.implements, str):
|
|
@@ -163,7 +163,7 @@ class InformationInputRules(InputRules[InformationRules]):
|
|
|
163
163
|
return "UnverifiedInformationModel"
|
|
164
164
|
|
|
165
165
|
@property
|
|
166
|
-
def display_name(self):
|
|
166
|
+
def display_name(self) -> str:
|
|
167
167
|
return uri_display_name(self.metadata.identifier)
|
|
168
168
|
|
|
169
169
|
def _repr_html_(self) -> str:
|
|
@@ -346,7 +346,8 @@ class AsParentPropertyId(VerifiedRulesTransformer[DMSRules, DMSRules]):
|
|
|
346
346
|
|
|
347
347
|
@staticmethod
|
|
348
348
|
def _get_parent_view_property_by_container_property(
|
|
349
|
-
path_by_view
|
|
349
|
+
path_by_view: dict[ViewEntity, list[ViewEntity]],
|
|
350
|
+
view_by_container_properties: dict[tuple[ContainerEntity, str], list[tuple[ViewEntity, str]]],
|
|
350
351
|
) -> dict[tuple[ContainerEntity, str], str]:
|
|
351
352
|
parent_name_by_container_property: dict[tuple[ContainerEntity, str], str] = {}
|
|
352
353
|
for (container, container_property), view_properties in view_by_container_properties.items():
|
|
@@ -49,7 +49,7 @@ class Collector:
|
|
|
49
49
|
return "notebook"
|
|
50
50
|
return "python"
|
|
51
51
|
|
|
52
|
-
def track_session_command(self, command: str, *args, **kwargs) -> None:
|
|
52
|
+
def track_session_command(self, command: str, *args: Any, **kwargs: Any) -> None:
|
|
53
53
|
event_information = {
|
|
54
54
|
"neatVersion": __version__,
|
|
55
55
|
"$os": platform.system(),
|
cognite/neat/_session/_read.py
CHANGED
|
@@ -616,7 +616,7 @@ class XMLReadAPI(BaseReadAPI):
|
|
|
616
616
|
for transformer in transformers:
|
|
617
617
|
self._state.instances.store.transform(cast(Transformers, transformer))
|
|
618
618
|
|
|
619
|
-
def aml(self, io: Any):
|
|
619
|
+
def aml(self, io: Any) -> None:
|
|
620
620
|
"""Reads an AML file into NeatSession and executes a set of predefined transformations.
|
|
621
621
|
|
|
622
622
|
Args:
|
|
@@ -30,9 +30,9 @@ class NeatSessionError(Exception):
|
|
|
30
30
|
...
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def _session_method_wrapper(func: Callable, cls_name: str):
|
|
33
|
+
def _session_method_wrapper(func: Callable, cls_name: str) -> Any:
|
|
34
34
|
@functools.wraps(func)
|
|
35
|
-
def wrapper(*args: Any, **kwargs: Any):
|
|
35
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
36
36
|
_COLLECTOR.track_session_command(f"{cls_name}.{func.__name__}", *args, **kwargs)
|
|
37
37
|
try:
|
|
38
38
|
with warnings.catch_warnings(record=True) as w:
|
|
@@ -59,7 +59,7 @@ def _session_method_wrapper(func: Callable, cls_name: str):
|
|
|
59
59
|
else:
|
|
60
60
|
raise e
|
|
61
61
|
|
|
62
|
-
def _get_action():
|
|
62
|
+
def _get_action() -> str:
|
|
63
63
|
action = func.__name__
|
|
64
64
|
if action == "__call__":
|
|
65
65
|
action = func.__qualname__.removesuffix(".__call__").removesuffix("API")
|
|
@@ -68,7 +68,7 @@ def _session_method_wrapper(func: Callable, cls_name: str):
|
|
|
68
68
|
return wrapper
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
def session_class_wrapper(cls: type):
|
|
71
|
+
def session_class_wrapper(cls: type) -> type:
|
|
72
72
|
"""This decorator wraps all methods of a class.
|
|
73
73
|
|
|
74
74
|
It should be used with all composition classes used with the NeatSession class.
|
|
@@ -20,7 +20,7 @@ import uuid
|
|
|
20
20
|
from collections.abc import Iterable, Sequence
|
|
21
21
|
from dataclasses import dataclass, field
|
|
22
22
|
from datetime import datetime
|
|
23
|
-
from typing import Generic, TypeVar
|
|
23
|
+
from typing import Any, Generic, TypeVar
|
|
24
24
|
|
|
25
25
|
from rdflib import PROV, RDF, Literal, URIRef
|
|
26
26
|
|
|
@@ -178,10 +178,10 @@ class Provenance(NeatList[Change[T_Entity]]):
|
|
|
178
178
|
def activity_took_place(self, activity: str) -> bool:
|
|
179
179
|
return any(change.activity.used == activity for change in self)
|
|
180
180
|
|
|
181
|
-
def __delitem__(self, *args, **kwargs):
|
|
181
|
+
def __delitem__(self, *args: Any, **kwargs: Any) -> None:
|
|
182
182
|
raise TypeError("Cannot delete change from provenance")
|
|
183
183
|
|
|
184
|
-
def __setitem__(self, *args, **kwargs):
|
|
184
|
+
def __setitem__(self, *args: Any, **kwargs: Any) -> None:
|
|
185
185
|
raise TypeError("Cannot modify change from provenance")
|
|
186
186
|
|
|
187
187
|
def _repr_html_(self) -> str:
|
|
@@ -221,7 +221,7 @@ class NeatRulesStore:
|
|
|
221
221
|
for agent_tool in transformer:
|
|
222
222
|
|
|
223
223
|
def action(
|
|
224
|
-
transformer_item=agent_tool,
|
|
224
|
+
transformer_item: VerifiedRulesTransformer = agent_tool,
|
|
225
225
|
) -> tuple[InformationRules, DMSRules | None]:
|
|
226
226
|
last_change = self.provenance[-1]
|
|
227
227
|
source_entity = last_change.target_entity
|
|
@@ -255,7 +255,7 @@ class NeatRulesStore:
|
|
|
255
255
|
self,
|
|
256
256
|
action: Callable[[], tuple[InformationRules, DMSRules | None]],
|
|
257
257
|
agent_tool: BaseImporter | VerifiedRulesTransformer | KnowledgeGraphExtractor,
|
|
258
|
-
):
|
|
258
|
+
) -> IssueList:
|
|
259
259
|
result, issue_list, start, end = self._do_activity(action)
|
|
260
260
|
self._last_issues = issue_list
|
|
261
261
|
|
|
@@ -312,7 +312,7 @@ class NeatRulesStore:
|
|
|
312
312
|
def _do_activity(
|
|
313
313
|
self,
|
|
314
314
|
action: Callable[[], tuple[InformationRules, DMSRules | None]],
|
|
315
|
-
):
|
|
315
|
+
) -> tuple[tuple[InformationRules, DMSRules | None], IssueList, datetime, datetime]:
|
|
316
316
|
"""This private method is used to execute an activity and return the result and issues."""
|
|
317
317
|
start = datetime.now(timezone.utc)
|
|
318
318
|
result: tuple[InformationRules, DMSRules | None] | None = None
|
|
@@ -13,7 +13,7 @@ from ._provenance import Activity
|
|
|
13
13
|
class NeatStoreError(Exception):
|
|
14
14
|
"""Base class for all exceptions in the store module"""
|
|
15
15
|
|
|
16
|
-
def __str__(self):
|
|
16
|
+
def __str__(self) -> str:
|
|
17
17
|
return type(self).__name__
|
|
18
18
|
|
|
19
19
|
|
|
@@ -30,7 +30,7 @@ class ActivityFailed(NeatStoreError):
|
|
|
30
30
|
self.issue_list = issue_list
|
|
31
31
|
self.tool = tool
|
|
32
32
|
|
|
33
|
-
def __str__(self):
|
|
33
|
+
def __str__(self) -> str:
|
|
34
34
|
return self.tool.description
|
|
35
35
|
|
|
36
36
|
|
|
@@ -49,7 +49,7 @@ class InvalidActivityOutput(NeatStoreError):
|
|
|
49
49
|
self.activity = activity
|
|
50
50
|
self.output = output
|
|
51
51
|
|
|
52
|
-
def __str__(self):
|
|
52
|
+
def __str__(self) -> str:
|
|
53
53
|
return f"{super().__str__()}: {self.activity.id_} -> {self.output}"
|
|
54
54
|
|
|
55
55
|
|
cognite/neat/_utils/auth.py
CHANGED
|
@@ -106,7 +106,7 @@ class EnvironmentVariables:
|
|
|
106
106
|
CDF_TIMEOUT: int | None = None
|
|
107
107
|
CDF_REDIRECT_PORT: int = 53_000
|
|
108
108
|
|
|
109
|
-
def __post_init__(self):
|
|
109
|
+
def __post_init__(self) -> None:
|
|
110
110
|
if self.LOGIN_FLOW.lower() not in _VALID_LOGIN_FLOWS:
|
|
111
111
|
raise ValueError(f"LOGIN_FLOW must be one of {_VALID_LOGIN_FLOWS}")
|
|
112
112
|
if self.IDP_TOKEN_URL and not self.IDP_TENANT_ID:
|
cognite/neat/_utils/auxiliary.py
CHANGED
|
@@ -7,6 +7,7 @@ from collections.abc import Callable
|
|
|
7
7
|
from datetime import datetime
|
|
8
8
|
from functools import wraps
|
|
9
9
|
from types import ModuleType
|
|
10
|
+
from typing import Any
|
|
10
11
|
|
|
11
12
|
from cognite.client.exceptions import CogniteDuplicatedError, CogniteReadTimeout
|
|
12
13
|
|
|
@@ -42,10 +43,10 @@ def class_html_doc(cls: type, include_factory_methods: bool = True) -> str:
|
|
|
42
43
|
return f"<h3>{cls.__name__}</h3><p>{docstring}</p>"
|
|
43
44
|
|
|
44
45
|
|
|
45
|
-
def retry_decorator(max_retries=2, retry_delay=3, component_name=""):
|
|
46
|
-
def decorator(func):
|
|
46
|
+
def retry_decorator(max_retries: int = 2, retry_delay: int = 3, component_name: str = "") -> Any:
|
|
47
|
+
def decorator(func: Callable) -> Any:
|
|
47
48
|
@wraps(func)
|
|
48
|
-
def wrapper(*args, **kwargs):
|
|
49
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
49
50
|
previous_exception = None
|
|
50
51
|
for attempt in range(max_retries + 1):
|
|
51
52
|
try:
|
|
@@ -89,7 +90,8 @@ def retry_decorator(max_retries=2, retry_delay=3, component_name=""):
|
|
|
89
90
|
raise e
|
|
90
91
|
|
|
91
92
|
except Exception as e:
|
|
92
|
-
|
|
93
|
+
# Deliberately ignoring here, this should be refactored.
|
|
94
|
+
previous_exception = e # type: ignore
|
|
93
95
|
if attempt < max_retries:
|
|
94
96
|
logging.error(
|
|
95
97
|
f"Retry attempt {attempt + 1} failed for {component_name}. "
|
cognite/neat/_utils/rdf_.py
CHANGED
|
@@ -67,7 +67,7 @@ def remove_namespace_from_uri(
|
|
|
67
67
|
# Assume that all elements in the tuple are of the same type following type hint
|
|
68
68
|
uris = URI
|
|
69
69
|
else:
|
|
70
|
-
raise TypeError(f"URI must be of type URIRef or str, got {type(URI)}")
|
|
70
|
+
raise TypeError(f"URI must be of type URIRef or str, got {type(URI)}: {URI}")
|
|
71
71
|
|
|
72
72
|
output = []
|
|
73
73
|
for u in uris:
|
|
@@ -218,7 +218,7 @@ def add_triples_in_batch(graph: Graph, triples: Iterable[Triple], batch_size: in
|
|
|
218
218
|
commit_counter = 0
|
|
219
219
|
number_of_written_triples = 0
|
|
220
220
|
|
|
221
|
-
def check_commit(force_commit: bool = False):
|
|
221
|
+
def check_commit(force_commit: bool = False) -> None:
|
|
222
222
|
"""Commit nodes to the graph if batch counter is reached or if force_commit is True"""
|
|
223
223
|
nonlocal commit_counter
|
|
224
224
|
nonlocal number_of_written_triples
|
|
@@ -248,7 +248,7 @@ def remove_triples_in_batch(graph: Graph, triples: Iterable[Triple], batch_size:
|
|
|
248
248
|
"""
|
|
249
249
|
batch_count = 0
|
|
250
250
|
|
|
251
|
-
def check_commit(force_commit: bool = False):
|
|
251
|
+
def check_commit(force_commit: bool = False) -> None:
|
|
252
252
|
"""Commit nodes to the graph if batch counter is reached or if force_commit is True"""
|
|
253
253
|
nonlocal batch_count
|
|
254
254
|
batch_count += 1
|
|
@@ -274,7 +274,7 @@ def remove_instance_ids_in_batch(graph: Graph, instance_ids: Iterable[URIRef], b
|
|
|
274
274
|
"""
|
|
275
275
|
batch_count = 0
|
|
276
276
|
|
|
277
|
-
def check_commit(force_commit: bool = False):
|
|
277
|
+
def check_commit(force_commit: bool = False) -> None:
|
|
278
278
|
"""Commit nodes to the graph if batch counter is reached or if force_commit is True"""
|
|
279
279
|
nonlocal batch_count
|
|
280
280
|
batch_count += 1
|
|
@@ -24,7 +24,7 @@ class SpreadsheetRead:
|
|
|
24
24
|
skipped_rows: list[int] = field(default_factory=list)
|
|
25
25
|
is_one_indexed: bool = True
|
|
26
26
|
|
|
27
|
-
def __post_init__(self):
|
|
27
|
+
def __post_init__(self) -> None:
|
|
28
28
|
self.empty_rows = sorted(self.empty_rows)
|
|
29
29
|
|
|
30
30
|
def adjusted_row_number(self, row_no: int) -> int:
|
cognite/neat/_utils/text.py
CHANGED
|
@@ -63,7 +63,7 @@ def to_camel_case(string: str) -> str:
|
|
|
63
63
|
return _to_camel_case(string, is_all_upper, is_first_upper)
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def _to_camel_case(string, is_all_upper: bool, is_first_upper: bool):
|
|
66
|
+
def _to_camel_case(string: str, is_all_upper: bool, is_first_upper: bool) -> str:
|
|
67
67
|
if "_" in string:
|
|
68
68
|
pascal_splits = [
|
|
69
69
|
_to_pascal_case(part, is_all_upper, is_first_upper and no == 0)
|
cognite/neat/_utils/time_.py
CHANGED
cognite/neat/_version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.117.
|
|
1
|
+
__version__ = "0.117.7"
|
|
2
2
|
__engine__ = "^2.0.4"
|