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
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
from collections.abc import Iterable, Sequence
|
|
2
|
-
from itertools import groupby
|
|
3
|
-
from typing import cast, overload
|
|
4
|
-
|
|
5
|
-
from cognite.client.data_classes import (
|
|
6
|
-
Database,
|
|
7
|
-
DatabaseList,
|
|
8
|
-
DatabaseWrite,
|
|
9
|
-
DatabaseWriteList,
|
|
10
|
-
Transformation,
|
|
11
|
-
TransformationList,
|
|
12
|
-
TransformationWrite,
|
|
13
|
-
TransformationWriteList,
|
|
14
|
-
)
|
|
15
|
-
from cognite.client.exceptions import CogniteAPIError
|
|
16
|
-
from cognite.client.utils.useful_types import SequenceNotStr
|
|
17
|
-
|
|
18
|
-
from cognite.neat._utils.cdf.data_classes import RawTable, RawTableID, RawTableList, RawTableWrite, RawTableWriteList
|
|
19
|
-
|
|
20
|
-
from ._base import ResourceLoader
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class TransformationLoader(
|
|
24
|
-
ResourceLoader[str, TransformationWrite, Transformation, TransformationWriteList, TransformationList]
|
|
25
|
-
):
|
|
26
|
-
resource_name = "transformations"
|
|
27
|
-
|
|
28
|
-
@classmethod
|
|
29
|
-
def get_id(cls, item: Transformation | TransformationWrite | str | dict) -> str:
|
|
30
|
-
if isinstance(item, Transformation | TransformationWrite):
|
|
31
|
-
if item.external_id is None:
|
|
32
|
-
raise ValueError(f"Transformation {item} does not have an external_id")
|
|
33
|
-
return item.external_id
|
|
34
|
-
if isinstance(item, dict):
|
|
35
|
-
if item.get("externalId") is None:
|
|
36
|
-
raise ValueError(f"Transformation {item} does not have an external_id")
|
|
37
|
-
return item["externalId"]
|
|
38
|
-
return item
|
|
39
|
-
|
|
40
|
-
def create(self, items: Sequence[TransformationWrite]) -> TransformationList:
|
|
41
|
-
return self.client.transformations.create(items)
|
|
42
|
-
|
|
43
|
-
def retrieve(self, ids: SequenceNotStr[str]) -> TransformationList:
|
|
44
|
-
return self.client.transformations.retrieve_multiple(external_ids=ids, ignore_unknown_ids=True)
|
|
45
|
-
|
|
46
|
-
def update(self, items: Sequence[TransformationWrite]) -> TransformationList:
|
|
47
|
-
return self.client.transformations.update(items)
|
|
48
|
-
|
|
49
|
-
def delete(self, ids: SequenceNotStr[str]) -> list[str]:
|
|
50
|
-
existing = self.retrieve(ids)
|
|
51
|
-
self.client.transformations.delete(external_id=ids, ignore_unknown_ids=True)
|
|
52
|
-
return existing.as_external_ids()
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class RawDatabaseLoader(ResourceLoader[str, DatabaseWrite, Database, DatabaseWriteList, DatabaseList]):
|
|
56
|
-
resource_name = "databases"
|
|
57
|
-
|
|
58
|
-
@classmethod
|
|
59
|
-
def get_id(cls, item: Database | DatabaseWrite | str | dict) -> str:
|
|
60
|
-
if isinstance(item, Database | DatabaseWrite):
|
|
61
|
-
if item.name is None:
|
|
62
|
-
raise ValueError(f"Database {item} does not have a name")
|
|
63
|
-
return item.name
|
|
64
|
-
if isinstance(item, dict):
|
|
65
|
-
if item.get("name") is None:
|
|
66
|
-
raise ValueError(f"Database {item} does not have a name")
|
|
67
|
-
return item["name"]
|
|
68
|
-
return item
|
|
69
|
-
|
|
70
|
-
def create(self, items: Sequence[DatabaseWrite]) -> DatabaseList:
|
|
71
|
-
return self.client.raw.databases.create([item.name for item in items if item.name is not None])
|
|
72
|
-
|
|
73
|
-
def retrieve(self, ids: SequenceNotStr[str]) -> DatabaseList:
|
|
74
|
-
all_databases = self.client.raw.databases.list(limit=-1)
|
|
75
|
-
return DatabaseList([db for db in all_databases if db.name in ids])
|
|
76
|
-
|
|
77
|
-
def update(self, items: Sequence[DatabaseWrite]) -> DatabaseList:
|
|
78
|
-
if not items:
|
|
79
|
-
return DatabaseList([])
|
|
80
|
-
raise NotImplementedError("The CDF API does not support updating a RAW database.")
|
|
81
|
-
|
|
82
|
-
def delete(self, ids: SequenceNotStr[str]) -> list[str]:
|
|
83
|
-
existing_databases = self.retrieve(ids)
|
|
84
|
-
existing_names = {item.name for item in existing_databases}
|
|
85
|
-
self.client.raw.databases.delete([name for name in ids if name in existing_names])
|
|
86
|
-
return existing_databases.as_names()
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
class RawTableLoader(ResourceLoader[RawTableID, RawTableWrite, RawTable, RawTableWriteList, RawTableList]):
|
|
90
|
-
resource_name = "tables"
|
|
91
|
-
|
|
92
|
-
@classmethod
|
|
93
|
-
def get_id(cls, item: RawTable | RawTableWrite | RawTableID | dict) -> RawTableID:
|
|
94
|
-
if isinstance(item, RawTable | RawTableWrite):
|
|
95
|
-
return item.as_id()
|
|
96
|
-
if isinstance(item, dict):
|
|
97
|
-
return RawTableID(database=item["database"], table=item["name"])
|
|
98
|
-
return item
|
|
99
|
-
|
|
100
|
-
@overload
|
|
101
|
-
def _groupby_database(self, items: Sequence[RawTableWrite]) -> Iterable[tuple[str, Iterable[RawTableWrite]]]: ...
|
|
102
|
-
|
|
103
|
-
@overload
|
|
104
|
-
def _groupby_database(self, items: SequenceNotStr[RawTableID]) -> Iterable[tuple[str, Iterable[RawTableID]]]: ...
|
|
105
|
-
|
|
106
|
-
def _groupby_database(
|
|
107
|
-
self, items: Sequence[RawTableWrite] | SequenceNotStr[RawTableID]
|
|
108
|
-
) -> Iterable[tuple[str, Iterable[RawTableWrite] | Iterable[RawTableID]]]:
|
|
109
|
-
return cast(
|
|
110
|
-
Iterable[tuple[str, Iterable[RawTableID] | Iterable[RawTableWrite]]],
|
|
111
|
-
groupby(sorted(items, key=lambda x: x.database or ""), lambda x: x.database or ""),
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
def create(self, items: Sequence[RawTableWrite]) -> RawTableList:
|
|
115
|
-
existing = set(self.retrieve([table.as_id() for table in items]).as_ids())
|
|
116
|
-
output = RawTableList([])
|
|
117
|
-
for db_name, tables in self._groupby_database(items):
|
|
118
|
-
to_create = [table.name for table in tables if table.name if table.as_id() not in existing]
|
|
119
|
-
if not to_create:
|
|
120
|
-
continue
|
|
121
|
-
created = self.client.raw.tables.create(db_name=db_name, name=to_create)
|
|
122
|
-
for table in created:
|
|
123
|
-
output.append(
|
|
124
|
-
RawTable(
|
|
125
|
-
name=table.name, database=db_name, created_time=table.created_time, cognite_client=self.client
|
|
126
|
-
)
|
|
127
|
-
)
|
|
128
|
-
return output
|
|
129
|
-
|
|
130
|
-
def retrieve(self, ids: SequenceNotStr[RawTableID]) -> RawTableList:
|
|
131
|
-
output = RawTableList([])
|
|
132
|
-
for db_name, id_group in self._groupby_database(ids):
|
|
133
|
-
try:
|
|
134
|
-
all_tables = self.client.raw.tables.list(db_name, limit=-1)
|
|
135
|
-
except CogniteAPIError as e:
|
|
136
|
-
if e.code == 404 and e.message.startswith("Following databases not found"):
|
|
137
|
-
continue
|
|
138
|
-
looking_for = {table_id.table for table_id in id_group if table_id.table is not None}
|
|
139
|
-
output.extend(
|
|
140
|
-
[
|
|
141
|
-
RawTable(
|
|
142
|
-
name=table.name, database=db_name, created_time=table.created_time, cognite_client=self.client
|
|
143
|
-
)
|
|
144
|
-
for table in all_tables
|
|
145
|
-
if table.name in looking_for
|
|
146
|
-
]
|
|
147
|
-
)
|
|
148
|
-
return output
|
|
149
|
-
|
|
150
|
-
def update(self, items: Sequence[RawTableWrite]) -> RawTableList:
|
|
151
|
-
if not items:
|
|
152
|
-
return RawTableList([])
|
|
153
|
-
raise NotImplementedError("The CDF API does not support updating a RAW table.")
|
|
154
|
-
|
|
155
|
-
def delete(self, ids: SequenceNotStr[RawTableID]) -> list[RawTableID]:
|
|
156
|
-
existing_tables = self.retrieve(ids)
|
|
157
|
-
existing_names = {item.name for item in existing_tables}
|
|
158
|
-
for db_name, id_group in self._groupby_database(ids):
|
|
159
|
-
self.client.raw.tables.delete(
|
|
160
|
-
db_name=db_name,
|
|
161
|
-
name=[
|
|
162
|
-
table_id.table
|
|
163
|
-
for table_id in id_group
|
|
164
|
-
if table_id.table is not None and table_id.table in existing_names
|
|
165
|
-
],
|
|
166
|
-
)
|
|
167
|
-
return existing_tables.as_ids()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|