cognite-neat 0.123.19__py3-none-any.whl → 0.123.20__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/session/_base.py +4 -0
- cognite/neat/session/_session/__init__.py +0 -0
- cognite/neat/session/_session/_data_model.py +154 -0
- {cognite_neat-0.123.19.dist-info → cognite_neat-0.123.20.dist-info}/METADATA +1 -1
- {cognite_neat-0.123.19.dist-info → cognite_neat-0.123.20.dist-info}/RECORD +8 -6
- {cognite_neat-0.123.19.dist-info → cognite_neat-0.123.20.dist-info}/WHEEL +0 -0
- {cognite_neat-0.123.19.dist-info → cognite_neat-0.123.20.dist-info}/licenses/LICENSE +0 -0
cognite/neat/_version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.123.
|
|
1
|
+
__version__ = "0.123.20"
|
|
2
2
|
__engine__ = "^2.0.4"
|
cognite/neat/session/_base.py
CHANGED
|
@@ -33,6 +33,7 @@ from ._mapping import MappingAPI
|
|
|
33
33
|
from ._plugin import PluginAPI
|
|
34
34
|
from ._prepare import PrepareAPI
|
|
35
35
|
from ._read import ReadAPI
|
|
36
|
+
from ._session._data_model import DataModelAPI
|
|
36
37
|
from ._set import SetAPI
|
|
37
38
|
from ._show import ShowAPI
|
|
38
39
|
from ._state import SessionState
|
|
@@ -115,6 +116,9 @@ class NeatSession:
|
|
|
115
116
|
if load_engine != "skip" and (engine_version := load_neat_engine(client, load_engine)):
|
|
116
117
|
print(f"Neat Engine {engine_version} loaded.")
|
|
117
118
|
|
|
119
|
+
# new API for data model operations
|
|
120
|
+
self.data_model = DataModelAPI(self._state)
|
|
121
|
+
|
|
118
122
|
def _select_most_performant_store(self) -> Literal["memory", "oxigraph"]:
|
|
119
123
|
"""Select the most performant store based on the current environment."""
|
|
120
124
|
|
|
File without changes
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from typing import Any, Literal
|
|
2
|
+
from zipfile import Path
|
|
3
|
+
|
|
4
|
+
from cognite.neat.core._data_model import importers
|
|
5
|
+
from cognite.neat.core._data_model.importers._base import BaseImporter
|
|
6
|
+
from cognite.neat.core._issues._base import IssueList
|
|
7
|
+
from cognite.neat.core._issues.errors._general import NeatValueError
|
|
8
|
+
from cognite.neat.core._issues.warnings._general import MissingCogniteClientWarning
|
|
9
|
+
from cognite.neat.core._utils.reader._base import NeatReader
|
|
10
|
+
from cognite.neat.plugins._manager import get_plugin_manager
|
|
11
|
+
from cognite.neat.plugins.data_model.importers._base import DataModelImporterPlugin
|
|
12
|
+
from cognite.neat.session._state import SessionState
|
|
13
|
+
from cognite.neat.session.exceptions import NeatSessionError, session_class_wrapper
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@session_class_wrapper
|
|
17
|
+
class DataModelAPI:
|
|
18
|
+
"""API for managing data models in NEAT session."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, state: SessionState) -> None:
|
|
21
|
+
self._state = state
|
|
22
|
+
self.read = ReadAPI(state)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@session_class_wrapper
|
|
26
|
+
class ReadAPI:
|
|
27
|
+
def __init__(self, state: SessionState) -> None:
|
|
28
|
+
self._state = state
|
|
29
|
+
|
|
30
|
+
def __call__(self, name: str, io: str | Path, **kwargs: Any) -> IssueList:
|
|
31
|
+
"""Provides access to the external plugins for data model importing.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
name (str): The name of format (e.g. Excel) plugin is handling.
|
|
35
|
+
io (str | Path | None): The input/output interface for the plugin.
|
|
36
|
+
**kwargs (Any): Additional keyword arguments for the plugin.
|
|
37
|
+
|
|
38
|
+
!!! note "kwargs"
|
|
39
|
+
Users must consult the documentation of the plugin to understand
|
|
40
|
+
what keyword arguments are supported.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
# These are internal readers that are not plugins
|
|
44
|
+
if name.strip().lower() == "excel":
|
|
45
|
+
return self.excel(io, **kwargs)
|
|
46
|
+
elif name.strip().lower() == "ontology":
|
|
47
|
+
return self.ontology(io)
|
|
48
|
+
elif name.strip().lower() == "yaml":
|
|
49
|
+
return self.yaml(io, **kwargs)
|
|
50
|
+
else:
|
|
51
|
+
return self._plugin(name, io, **kwargs)
|
|
52
|
+
|
|
53
|
+
def _plugin(self, name: str, io: str | Path, **kwargs: Any) -> IssueList:
|
|
54
|
+
"""Provides access to the external plugins for data model importing.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
name (str): The name of format (e.g. Excel) plugin is handling.
|
|
58
|
+
io (str | Path | None): The input/output interface for the plugin.
|
|
59
|
+
**kwargs (Any): Additional keyword arguments for the plugin.
|
|
60
|
+
|
|
61
|
+
!!! note "kwargs"
|
|
62
|
+
Users must consult the documentation of the plugin to understand
|
|
63
|
+
what keyword arguments are supported.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
# Some plugins may not support the io argument
|
|
67
|
+
reader = NeatReader.create(io)
|
|
68
|
+
path = reader.materialize_path()
|
|
69
|
+
|
|
70
|
+
self._state._raise_exception_if_condition_not_met(
|
|
71
|
+
"Data Model Read",
|
|
72
|
+
empty_data_model_store_required=True,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
plugin_manager = get_plugin_manager()
|
|
76
|
+
plugin = plugin_manager.get(name, DataModelImporterPlugin)
|
|
77
|
+
|
|
78
|
+
print(
|
|
79
|
+
f"You are using an external plugin {plugin.__name__}, which is not developed by the NEAT team."
|
|
80
|
+
"\nUse it at your own risk."
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
return self._state.data_model_import(plugin().configure(io=path, **kwargs))
|
|
84
|
+
|
|
85
|
+
def excel(self, io: str | Path, *, enable_manual_edit: bool = False) -> IssueList:
|
|
86
|
+
"""Reads a Neat Excel Data Model to the data model store.
|
|
87
|
+
The data model spreadsheets may contain conceptual or physical data model definitions.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
io: file path to the Excel sheet
|
|
91
|
+
enable_manual_edit: If True, the user will be able to re-import data model
|
|
92
|
+
which where edit outside of NeatSession
|
|
93
|
+
"""
|
|
94
|
+
reader = NeatReader.create(io)
|
|
95
|
+
path = reader.materialize_path()
|
|
96
|
+
|
|
97
|
+
self._state._raise_exception_if_condition_not_met(
|
|
98
|
+
"Read Excel Data Model",
|
|
99
|
+
empty_data_model_store_required=not enable_manual_edit,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
return self._state.data_model_import(importers.ExcelImporter(path), enable_manual_edit)
|
|
103
|
+
|
|
104
|
+
def ontology(self, io: str | Path) -> IssueList:
|
|
105
|
+
"""Reads an OWL ontology source into NeatSession.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
io: file path or url to the OWL file
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
self._state._raise_exception_if_condition_not_met(
|
|
112
|
+
"Read Ontology",
|
|
113
|
+
empty_data_model_store_required=True,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
reader = NeatReader.create(io)
|
|
117
|
+
importer = importers.OWLImporter.from_file(reader.materialize_path(), source_name=f"file {reader!s}")
|
|
118
|
+
return self._state.data_model_import(importer)
|
|
119
|
+
|
|
120
|
+
def yaml(self, io: str | Path, *, format: Literal["neat", "toolkit"] = "neat") -> IssueList:
|
|
121
|
+
"""Reads a yaml with either neat data mode, or several toolkit yaml files to
|
|
122
|
+
import Data Model(s) into NeatSession.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
io: File path to the Yaml file in the case of "neat" yaml, or path to a zip folder or directory with several
|
|
126
|
+
Yaml files in the case of "toolkit".
|
|
127
|
+
format: The format of the yaml file(s). Can be either "neat" or "toolkit".
|
|
128
|
+
|
|
129
|
+
Example:
|
|
130
|
+
```python
|
|
131
|
+
neat.read.yaml("path_to_toolkit_yamls")
|
|
132
|
+
```
|
|
133
|
+
"""
|
|
134
|
+
self._state._raise_exception_if_condition_not_met(
|
|
135
|
+
"Read YAML data model",
|
|
136
|
+
empty_data_model_store_required=True,
|
|
137
|
+
)
|
|
138
|
+
reader = NeatReader.create(io)
|
|
139
|
+
path = reader.materialize_path()
|
|
140
|
+
importer: BaseImporter
|
|
141
|
+
if format == "neat":
|
|
142
|
+
importer = importers.DictImporter.from_yaml_file(path, source_name=f"{reader!s}")
|
|
143
|
+
elif format == "toolkit":
|
|
144
|
+
dms_importer = importers.DMSImporter.from_path(path, self._state.client)
|
|
145
|
+
if dms_importer.issue_list.has_warning_type(MissingCogniteClientWarning):
|
|
146
|
+
raise NeatSessionError(
|
|
147
|
+
"No client provided. You are referencing Cognite containers in your data model, "
|
|
148
|
+
"NEAT needs a client to lookup the container definitions. "
|
|
149
|
+
"Please set the client in the session, NeatSession(client=client)."
|
|
150
|
+
)
|
|
151
|
+
importer = dms_importer
|
|
152
|
+
else:
|
|
153
|
+
raise NeatValueError(f"Unsupported YAML format: {format}")
|
|
154
|
+
return self._state.data_model_import(importer)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cognite-neat
|
|
3
|
-
Version: 0.123.
|
|
3
|
+
Version: 0.123.20
|
|
4
4
|
Summary: Knowledge graph transformation
|
|
5
5
|
Project-URL: Documentation, https://cognite-neat.readthedocs-hosted.com/
|
|
6
6
|
Project-URL: Homepage, https://cognite-neat.readthedocs-hosted.com/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
cognite/neat/__init__.py,sha256=12StS1dzH9_MElqxGvLWrNsxCJl9Hv8A2a9D0E5OD_U,193
|
|
2
|
-
cognite/neat/_version.py,sha256=
|
|
2
|
+
cognite/neat/_version.py,sha256=tUfZIhsXsTuZtKqqfKwmQe_3linzeB0aoFlEj2fZHAQ,47
|
|
3
3
|
cognite/neat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
cognite/neat/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
cognite/neat/core/_config.py,sha256=WT1BS8uADcFvGoUYOOfwFOVq_VBl472TisdoA3wLick,280
|
|
@@ -165,7 +165,7 @@ cognite/neat/plugins/data_model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
|
|
|
165
165
|
cognite/neat/plugins/data_model/importers/__init__.py,sha256=d4UJNCFR1DXPY7lv5LdCW2hiStEhvXiu2g_bRSIp1y0,89
|
|
166
166
|
cognite/neat/plugins/data_model/importers/_base.py,sha256=M9zXp7tEu1SfJZRAJAtLmqpssdFcoi2X-5e25q_n_h8,1034
|
|
167
167
|
cognite/neat/session/__init__.py,sha256=fxQ5URVlUnmEGYyB8Baw7IDq-uYacqkigbc4b-Pr9Fw,58
|
|
168
|
-
cognite/neat/session/_base.py,sha256=
|
|
168
|
+
cognite/neat/session/_base.py,sha256=yxAItY6663wcmlrwxmzWkJorrrrm9oahpYOP-5RGwvQ,13081
|
|
169
169
|
cognite/neat/session/_collector.py,sha256=-icWXOT9YBjAOVZfpPtBx-D39kpRP2RaQKdPtcr7Xm8,4233
|
|
170
170
|
cognite/neat/session/_drop.py,sha256=ipD8RS_ZebPNpeIkhC7yqSSeo7e57TXMRxrh5_6IRik,4239
|
|
171
171
|
cognite/neat/session/_experimental.py,sha256=0peZPZ9JpmzQE05wHbng2tWmPPLLTAVfWZEEUhdnI6o,1274
|
|
@@ -184,12 +184,14 @@ cognite/neat/session/_template.py,sha256=NCgrrwLT98DpLYoo3Wybr_OUXrEXpsJZjrJ83Kq
|
|
|
184
184
|
cognite/neat/session/_to.py,sha256=_R-UB3iEIQoa12kTD7tuSrRDdbySQXQg_mzbn5t-7bg,19399
|
|
185
185
|
cognite/neat/session/_wizard.py,sha256=hARNNzD5Zfkk_V147rIjOLVvrFaqzXGXWhZuH1NJG3M,1486
|
|
186
186
|
cognite/neat/session/exceptions.py,sha256=z5jxwfVTXDCCFZKTTYVIaksNKqb9CMa2tyIZgyNL3Us,3475
|
|
187
|
+
cognite/neat/session/_session/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
188
|
+
cognite/neat/session/_session/_data_model.py,sha256=id2chqUIA8tkxc9tTT7RiGWs-GzHC4LnzNkq-mfBIW4,6347
|
|
187
189
|
cognite/neat/session/_state/README.md,sha256=o6N7EL98lgyWffw8IoEUf2KG5uSKveD5__TW45YzVjA,902
|
|
188
190
|
cognite/neat/session/engine/__init__.py,sha256=D3MxUorEs6-NtgoICqtZ8PISQrjrr4dvca6n48bu_bI,120
|
|
189
191
|
cognite/neat/session/engine/_import.py,sha256=1QxA2_EK613lXYAHKQbZyw2yjo5P9XuiX4Z6_6-WMNQ,169
|
|
190
192
|
cognite/neat/session/engine/_interface.py,sha256=3W-cYr493c_mW3P5O6MKN1xEQg3cA7NHR_ev3zdF9Vk,533
|
|
191
193
|
cognite/neat/session/engine/_load.py,sha256=g52uYakQM03VqHt_RDHtpHso1-mFFifH5M4T2ScuH8A,5198
|
|
192
|
-
cognite_neat-0.123.
|
|
193
|
-
cognite_neat-0.123.
|
|
194
|
-
cognite_neat-0.123.
|
|
195
|
-
cognite_neat-0.123.
|
|
194
|
+
cognite_neat-0.123.20.dist-info/METADATA,sha256=O8qdN1hncWgpZrnj6h4aeeoZlbtTG2Loe7qTGpHUuzA,9172
|
|
195
|
+
cognite_neat-0.123.20.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
196
|
+
cognite_neat-0.123.20.dist-info/licenses/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
|
|
197
|
+
cognite_neat-0.123.20.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|