cognite-neat 0.123.1__py3-none-any.whl → 0.123.3__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 CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "0.123.1"
1
+ __version__ = "0.123.3"
2
2
  __engine__ = "^2.0.4"
@@ -2,7 +2,7 @@ from ._base import BaseImporter
2
2
  from ._dict2data_model import DictImporter
3
3
  from ._dms2data_model import DMSImporter
4
4
  from ._dtdl2data_model import DTDLImporter
5
- from ._rdf import IMFImporter, InferenceImporter, OWLImporter, SubclassInferenceImporter
5
+ from ._rdf import InferenceImporter, OWLImporter, SubclassInferenceImporter
6
6
  from ._spreadsheet2data_model import ExcelImporter
7
7
 
8
8
  __all__ = [
@@ -11,7 +11,6 @@ __all__ = [
11
11
  "DTDLImporter",
12
12
  "DictImporter",
13
13
  "ExcelImporter",
14
- "IMFImporter",
15
14
  "InferenceImporter",
16
15
  "OWLImporter",
17
16
  "SubclassInferenceImporter",
@@ -19,7 +18,6 @@ __all__ = [
19
18
 
20
19
  DataModelImporters = (
21
20
  OWLImporter
22
- | IMFImporter
23
21
  | DMSImporter
24
22
  | ExcelImporter
25
23
  | DTDLImporter
@@ -1,5 +1,4 @@
1
- from ._imf2data_model import IMFImporter
2
1
  from ._inference2rdata_model import InferenceImporter, SubclassInferenceImporter
3
2
  from ._owl2data_model import OWLImporter
4
3
 
5
- __all__ = ["IMFImporter", "InferenceImporter", "OWLImporter", "SubclassInferenceImporter"]
4
+ __all__ = ["InferenceImporter", "OWLImporter", "SubclassInferenceImporter"]
@@ -1,6 +1,6 @@
1
1
  from dataclasses import dataclass
2
2
 
3
- from cognite.neat.core._issues._base import NeatError
3
+ from cognite.neat.core._issues.errors import _NEAT_ERRORS_BY_NAME, NeatError
4
4
 
5
5
 
6
6
  @dataclass(unsafe_hash=True)
@@ -23,3 +23,13 @@ class PluginDuplicateError(PluginError):
23
23
  """Plugin of type '{plugin_type}' registered for under name '{plugin_name}' already exists"""
24
24
 
25
25
  ...
26
+
27
+
28
+ # Register the errors in the _NEAT_ERRORS_BY_NAME dictionary
29
+ _NEAT_ERRORS_BY_NAME.update(
30
+ {
31
+ "PluginError": PluginError,
32
+ "PluginLoadingError": PluginLoadingError,
33
+ "PluginDuplicateError": PluginDuplicateError,
34
+ }
35
+ )
@@ -1,7 +1,7 @@
1
1
  """Plugin manager for external plugins."""
2
2
 
3
3
  from importlib import metadata
4
- from typing import Any, ClassVar, TypeAlias
4
+ from typing import Any, ClassVar, TypeAlias, TypeVar, cast
5
5
 
6
6
  from ._issues import PluginDuplicateError, PluginError, PluginLoadingError
7
7
  from .data_model.importers import DataModelImporterPlugin
@@ -14,6 +14,9 @@ plugins_entry_points = {
14
14
  #: Type alias for all supported plugin types
15
15
  NeatPlugin: TypeAlias = DataModelImporterPlugin
16
16
 
17
+ # Generic type variable for plugin types
18
+ T_NeatPlugin = TypeVar("T_NeatPlugin", bound=NeatPlugin)
19
+
17
20
 
18
21
  class Plugin:
19
22
  """Plugin class for registering plugins registered via entry points (i.e. external plugins).
@@ -33,7 +36,7 @@ class Plugin:
33
36
  self.type_ = type_
34
37
  self.entry_point = entry_point
35
38
 
36
- def load(self) -> Any:
39
+ def load(self) -> type[NeatPlugin]:
37
40
  try:
38
41
  return self.entry_point.load()
39
42
  except Exception as e:
@@ -50,7 +53,7 @@ class PluginManager:
50
53
  def __init__(self, plugins: dict[tuple[str, type[NeatPlugin]], Any]) -> None:
51
54
  self._plugins = plugins
52
55
 
53
- def get(self, name: str, type_: type[NeatPlugin]) -> Any:
56
+ def get(self, name: str, type_: type[T_NeatPlugin]) -> type[T_NeatPlugin]:
54
57
  """
55
58
  Returns desired plugin
56
59
 
@@ -59,7 +62,8 @@ class PluginManager:
59
62
  type_ (type): The type of the plugin.
60
63
  """
61
64
  try:
62
- return self._plugins[(name, type_)]
65
+ plugin_class = self._plugins[(name, type_)]
66
+ return cast(type[T_NeatPlugin], plugin_class)
63
67
  except KeyError:
64
68
  raise PluginError(plugin_name=name, plugin_type=type_.__name__) from None
65
69
 
@@ -1,3 +1,4 @@
1
+ from pathlib import Path
1
2
  from typing import Any
2
3
 
3
4
  from cognite.neat.core._data_model.importers._base import BaseImporter
@@ -9,11 +10,11 @@ class DataModelImporterPlugin:
9
10
  It is expected to implement the `configure` method which returns a configured importer.
10
11
  """
11
12
 
12
- def configure(self, io: Any, **kwargs: Any) -> BaseImporter:
13
+ def configure(self, io: str | Path | None, **kwargs: Any) -> BaseImporter:
13
14
  """Return a configure plugin for data model import.
14
15
 
15
16
  Args:
16
- io (Any): The input/output interface for the plugin.
17
+ io (str | Path | None): The input/output interface for the plugin.
17
18
  **kwargs (Any): Additional keyword arguments for configuration.
18
19
 
19
20
  Returns:
@@ -30,6 +30,7 @@ from ._explore import ExploreAPI
30
30
  from ._fix import FixAPI
31
31
  from ._inspect import InspectAPI
32
32
  from ._mapping import MappingAPI
33
+ from ._plugin import PluginAPI
33
34
  from ._prepare import PrepareAPI
34
35
  from ._read import ReadAPI
35
36
  from ._set import SetAPI
@@ -108,6 +109,7 @@ class NeatSession:
108
109
  self.subset = SubsetAPI(self._state)
109
110
  self.template = TemplateAPI(self._state)
110
111
  self._explore = ExploreAPI(self._state)
112
+ self.plugins = PluginAPI(self._state)
111
113
  self.opt = OptAPI()
112
114
  self.opt._display()
113
115
  if load_engine != "skip" and (engine_version := load_neat_engine(client, load_engine)):
@@ -23,3 +23,4 @@ class ExperimentalFlags:
23
23
  csv_read = ExperimentalFeatureWarning("csv_read")
24
24
  to_ontology = ExperimentalFeatureWarning("to_ontology")
25
25
  extension = ExperimentalFeatureWarning("extension")
26
+ plugin = ExperimentalFeatureWarning("plugin")
@@ -0,0 +1,67 @@
1
+ import warnings
2
+ from pathlib import Path
3
+ from typing import Any
4
+
5
+ from cognite.neat.core._issues._base import IssueList
6
+ from cognite.neat.core._utils.reader._base import NeatReader
7
+ from cognite.neat.plugins import get_plugin_manager
8
+ from cognite.neat.plugins.data_model.importers._base import DataModelImporterPlugin
9
+ from cognite.neat.session._experimental import ExperimentalFlags
10
+
11
+ from ._state import SessionState
12
+ from .exceptions import session_class_wrapper
13
+
14
+
15
+ @session_class_wrapper
16
+ class PluginAPI:
17
+ """Read from a data source into NeatSession graph store."""
18
+
19
+ def __init__(self, state: SessionState) -> None:
20
+ self._state = state
21
+
22
+ self.data_model = DataModelPlugins(self._state)
23
+
24
+
25
+ @session_class_wrapper
26
+ class DataModelPlugins:
27
+ """Read from a data source into NeatSession graph store."""
28
+
29
+ def __init__(self, state: SessionState) -> None:
30
+ self._state = state
31
+
32
+ def read(self, name: str, io: str | Path | None = None, **kwargs: Any) -> IssueList:
33
+ """Provides access to the external plugins for data model importing.
34
+
35
+ Args:
36
+ name (str): The name of format (e.g. Excel) plugin is handling.
37
+ io (str | Path | None): The input/output interface for the plugin.
38
+ **kwargs (Any): Additional keyword arguments for the plugin.
39
+
40
+ !!! note "kwargs"
41
+ Users must consult the documentation of the plugin to understand
42
+ what keyword arguments are supported.
43
+ """
44
+ warnings.filterwarnings("default")
45
+ ExperimentalFlags.plugin.warn()
46
+
47
+ # Some plugins may not support the io argument
48
+ if io:
49
+ reader = NeatReader.create(io)
50
+ path = reader.materialize_path()
51
+ else:
52
+ path = None
53
+
54
+ self._state._raise_exception_if_condition_not_met(
55
+ "Data Model Read",
56
+ empty_data_model_store_required=True,
57
+ )
58
+
59
+ plugin_manager = get_plugin_manager()
60
+ plugin = plugin_manager.get(name, DataModelImporterPlugin)
61
+
62
+ print(
63
+ f"You are using an external plugin {plugin.__name__}, which is not developed by the NEAT team."
64
+ "\nUse it at your own risk."
65
+ )
66
+
67
+ return self._state.data_model_import(plugin().configure(io=path, **kwargs))
@@ -826,29 +826,6 @@ class RDFReadAPI(BaseReadAPI):
826
826
  importer = importers.OWLImporter.from_file(reader.materialize_path(), source_name=f"file {reader!s}")
827
827
  return self._state.data_model_import(importer)
828
828
 
829
- def imf(self, io: Any) -> IssueList:
830
- """Reads IMF Types provided as SHACL shapes into NeatSession.
831
-
832
- Args:
833
- io: file path or url to the IMF file
834
-
835
- Example:
836
- ```python
837
- neat.read.rdf.imf("url_or_path_to_imf_source")
838
- ```
839
- """
840
- warnings.filterwarnings("default")
841
- ExperimentalFlags.imf_read.warn()
842
-
843
- self._state._raise_exception_if_condition_not_met(
844
- "Read IMF file",
845
- empty_data_model_store_required=True,
846
- )
847
-
848
- reader = NeatReader.create(io)
849
- importer = importers.IMFImporter.from_file(reader.materialize_path(), source_name=f"file {reader!s}")
850
- return self._state.data_model_import(importer)
851
-
852
829
  def instances(self, io: Any) -> IssueList:
853
830
  self._state._raise_exception_if_condition_not_met(
854
831
  "Read RDF Instances",
@@ -6,6 +6,7 @@ from typing import Any, TypeVar
6
6
  from cognite.neat.core._issues.errors import CDFMissingClientError, NeatImportError
7
7
  from cognite.neat.core._issues.errors._external import OxigraphStorageLockedError
8
8
  from cognite.neat.core._issues.errors._general import NeatValueError, WillExceedLimitError
9
+ from cognite.neat.plugins._issues import PluginError
9
10
  from cognite.neat.session._experimental import ExperimentalFeatureWarning
10
11
 
11
12
  from ._collector import _COLLECTOR
@@ -50,6 +51,7 @@ def _session_method_wrapper(func: Callable, cls_name: str) -> Any:
50
51
  NeatImportError,
51
52
  NeatValueError,
52
53
  OxigraphStorageLockedError,
54
+ PluginError,
53
55
  WillExceedLimitError,
54
56
  ) as e:
55
57
  print(f"{_ERROR_PREFIX} {escape(e.as_message())}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognite-neat
3
- Version: 0.123.1
3
+ Version: 0.123.3
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=9xSFXBm0153-WkCC4TsK5hz4FpM0Eo8Z2KVqo6ptqSA,46
2
+ cognite/neat/_version.py,sha256=1LL2p_8I7bAAlssuMiKzpRCctloMXRPY6TNNhG3TaFQ,46
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
@@ -34,7 +34,7 @@ cognite/neat/core/_data_model/exporters/_data_model2excel.py,sha256=mRVJzUCEWfm2
34
34
  cognite/neat/core/_data_model/exporters/_data_model2instance_template.py,sha256=9k8A70b1paeOHjvJRtbl6Xror1GD8AIMdo3cCx5aejE,6103
35
35
  cognite/neat/core/_data_model/exporters/_data_model2ontology.py,sha256=YrLTwPAvOOyLFHFJaNs4I82HCp1llJnkF1BRdoIQMck,23409
36
36
  cognite/neat/core/_data_model/exporters/_data_model2yaml.py,sha256=1dlb-v4sV8BArnX_6J4wpjQT7r-FinFAvoPDoMNkHYw,3284
37
- cognite/neat/core/_data_model/importers/__init__.py,sha256=ipImLDSse0vAHX4AWvtPI-LnnkIPajA4mwuEvpSXPT0,1336
37
+ cognite/neat/core/_data_model/importers/__init__.py,sha256=4XxrVG5rb_3IjcRSzfC76dOX8b2tB6ar2ybQGrVQ5fg,1286
38
38
  cognite/neat/core/_data_model/importers/_base.py,sha256=pKe2OK86Wdj6CTj5bUgjY33ejZhRfD2eJbjcCapHD58,2013
39
39
  cognite/neat/core/_data_model/importers/_base_file_reader.py,sha256=m7CwMujEybYMfHWbTQOb7wBvLl2X1TmROkPelJMSaDA,1621
40
40
  cognite/neat/core/_data_model/importers/_dict2data_model.py,sha256=-1zmo8JkxJ9qiWuC7sUH7oSlpnPPKTMxZtm4WrRPO5A,4709
@@ -45,9 +45,8 @@ cognite/neat/core/_data_model/importers/_dtdl2data_model/_unit_lookup.py,sha256=
45
45
  cognite/neat/core/_data_model/importers/_dtdl2data_model/dtdl_converter.py,sha256=mjouy5XQCJoybUkCnEoZFrFtWBQrBQRPIM4DwfMDUkw,11879
46
46
  cognite/neat/core/_data_model/importers/_dtdl2data_model/dtdl_importer.py,sha256=t5EkawmYPuQ-dJ1J-IhqhdX_CkaCwQLQDAcpmx7QdS0,6288
47
47
  cognite/neat/core/_data_model/importers/_dtdl2data_model/spec.py,sha256=HnKUZbp42pl4DSexo0N6t_20tsvlsxyHHnNak5SVgzg,12182
48
- cognite/neat/core/_data_model/importers/_rdf/__init__.py,sha256=CYZd6Oj5PR2wv-eh4DYvKt4SDQgYRf1zW5QhN1Rg9AU,255
48
+ cognite/neat/core/_data_model/importers/_rdf/__init__.py,sha256=1yOjV2PKCxwH7uCTXVZhSdxtn5etmFX40cksvwtKcZ8,199
49
49
  cognite/neat/core/_data_model/importers/_rdf/_base.py,sha256=FKceKumKmhEGpMZvo1BwEewnUvfAsTF3Ax9fo1nxsGE,6020
50
- cognite/neat/core/_data_model/importers/_rdf/_imf2data_model.py,sha256=f5kAkv7-d5DtqzaACkyA-vLXrQ2xArwEd9zg7yX-MfA,3777
51
50
  cognite/neat/core/_data_model/importers/_rdf/_inference2rdata_model.py,sha256=PCgM9-qGSLlupN7tYCFLHjivgICtMiahNry1ub8JCYk,28934
52
51
  cognite/neat/core/_data_model/importers/_rdf/_owl2data_model.py,sha256=WmncZNpELeZnt6mdw6X8yWnr7XsFXZGfoVe5wTd0HH4,3438
53
52
  cognite/neat/core/_data_model/importers/_rdf/_shared.py,sha256=yB4BkupiPhizWSHNKdaspj3xE_6pKDiNG-_IHtTN1gI,5961
@@ -161,22 +160,23 @@ cognite/neat/core/_utils/xml_.py,sha256=FQkq84u35MUsnKcL6nTMJ9ajtG9D5i1u4VBnhGqP
161
160
  cognite/neat/core/_utils/reader/__init__.py,sha256=fPkrNB_9hLB7CyHTCFV_xEbIfOMqUQzNly5JN33-QfM,146
162
161
  cognite/neat/core/_utils/reader/_base.py,sha256=fRXxUWW8a3UFedeCLxDTDgFntWGlHaEGxmKLcITtiWE,5417
163
162
  cognite/neat/plugins/__init__.py,sha256=Q7r1FFbybOt71N9TjHjjk-1HguLRfHieLeiGVSG5HTY,75
164
- cognite/neat/plugins/_issues.py,sha256=Xd3YsIN0EZakvgCLm5ilantTv17dVUabXc61nFxriQM,671
165
- cognite/neat/plugins/_manager.py,sha256=LQlEGjRgn55nu-dad9LKpqIaYqM12OoKRYBepCQz_1c,3769
163
+ cognite/neat/plugins/_issues.py,sha256=jukeVjSs1DEzqtFuGRcIDbg7bNxZRxGPqnzumVRF-8c,940
164
+ cognite/neat/plugins/_manager.py,sha256=_eJa5_3UGoLVacSQgbDrE0eWcopjeXxgbfSmvujeSiU,3979
166
165
  cognite/neat/plugins/data_model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
167
166
  cognite/neat/plugins/data_model/importers/__init__.py,sha256=d4UJNCFR1DXPY7lv5LdCW2hiStEhvXiu2g_bRSIp1y0,89
168
- cognite/neat/plugins/data_model/importers/_base.py,sha256=S8VOw0eYJ94CDeOx7aTjBbBebNlpoWoGatpU5eOohtQ,981
167
+ cognite/neat/plugins/data_model/importers/_base.py,sha256=M9zXp7tEu1SfJZRAJAtLmqpssdFcoi2X-5e25q_n_h8,1034
169
168
  cognite/neat/session/__init__.py,sha256=fxQ5URVlUnmEGYyB8Baw7IDq-uYacqkigbc4b-Pr9Fw,58
170
- cognite/neat/session/_base.py,sha256=DqujVyC19Jg8hGxnw9TfCeF3BYOFuauk4yTTuAsjJz4,12807
169
+ cognite/neat/session/_base.py,sha256=vg8KgzpQxFnFCR4F0yRNSsRmrgYZQ77rW6eX4w7L9M4,12884
171
170
  cognite/neat/session/_collector.py,sha256=-icWXOT9YBjAOVZfpPtBx-D39kpRP2RaQKdPtcr7Xm8,4233
172
171
  cognite/neat/session/_drop.py,sha256=ipD8RS_ZebPNpeIkhC7yqSSeo7e57TXMRxrh5_6IRik,4239
173
- cognite/neat/session/_experimental.py,sha256=U_Wq3NWgnGaOJh5Fq8iO6HcYUhlG9RQIutT8e4LZL8o,1224
172
+ cognite/neat/session/_experimental.py,sha256=0peZPZ9JpmzQE05wHbng2tWmPPLLTAVfWZEEUhdnI6o,1274
174
173
  cognite/neat/session/_explore.py,sha256=PLxpHDqBk5B0Q4a5tJKnF6KzL4heQ77b2qUETbf6iVQ,1599
175
174
  cognite/neat/session/_fix.py,sha256=oJRXuRI4f_HgLYHkjbtPAwHK0vSDUYd19hIZeFaE7rQ,919
176
175
  cognite/neat/session/_inspect.py,sha256=AESQd2SOidR_pDTFk5B_JdPnKZ5PNNskdAQBepH2Mv0,10175
177
176
  cognite/neat/session/_mapping.py,sha256=ItEXhXo_8V3069hktHMxdpBsLNeTck3gZBvhlm12Oxw,2895
177
+ cognite/neat/session/_plugin.py,sha256=diFvZUFRvY037iVy_HxnIGMSfrauOpwYCSvFEPOzchQ,2282
178
178
  cognite/neat/session/_prepare.py,sha256=pskEVNgcnVJVRvYKk5xI55V89vKDO_kgjszj5flY8Zs,12778
179
- cognite/neat/session/_read.py,sha256=sKtSw7Ub--vR6wfEexNzzaEHb0MZCHj3kzCEnF5wjf0,35349
179
+ cognite/neat/session/_read.py,sha256=rd1MeXPt_fS50WYrpM6UqDTKOQkDrOIn8TPS0WOVoSw,34607
180
180
  cognite/neat/session/_set.py,sha256=PU4lKI-LGtKFVyvdtfZkk-zLw9e_rnFHzuV9IyrOrTM,4593
181
181
  cognite/neat/session/_show.py,sha256=YLt6K4ukG1s_I_FhuVrIVPtw_btvvOL50Rwrx-vo7VQ,10743
182
182
  cognite/neat/session/_state.py,sha256=DLEm9wn3GtOuTGhy5-M1IK2v9qvLnTYEruWPidzAP_Q,6580
@@ -184,13 +184,13 @@ cognite/neat/session/_subset.py,sha256=p7n6WmL0gZlUbqpVBgyPncQ6uWn_pi7FDSixDFrm7
184
184
  cognite/neat/session/_template.py,sha256=NCgrrwLT98DpLYoo3Wybr_OUXrEXpsJZjrJ83KqfyWc,9908
185
185
  cognite/neat/session/_to.py,sha256=_R-UB3iEIQoa12kTD7tuSrRDdbySQXQg_mzbn5t-7bg,19399
186
186
  cognite/neat/session/_wizard.py,sha256=hARNNzD5Zfkk_V147rIjOLVvrFaqzXGXWhZuH1NJG3M,1486
187
- cognite/neat/session/exceptions.py,sha256=lcO-qQcWkKeF2lvlIZngs358ClcNIH8i6LVW7ioSinQ,3397
187
+ cognite/neat/session/exceptions.py,sha256=z5jxwfVTXDCCFZKTTYVIaksNKqb9CMa2tyIZgyNL3Us,3475
188
188
  cognite/neat/session/_state/README.md,sha256=o6N7EL98lgyWffw8IoEUf2KG5uSKveD5__TW45YzVjA,902
189
189
  cognite/neat/session/engine/__init__.py,sha256=D3MxUorEs6-NtgoICqtZ8PISQrjrr4dvca6n48bu_bI,120
190
190
  cognite/neat/session/engine/_import.py,sha256=1QxA2_EK613lXYAHKQbZyw2yjo5P9XuiX4Z6_6-WMNQ,169
191
191
  cognite/neat/session/engine/_interface.py,sha256=3W-cYr493c_mW3P5O6MKN1xEQg3cA7NHR_ev3zdF9Vk,533
192
192
  cognite/neat/session/engine/_load.py,sha256=g52uYakQM03VqHt_RDHtpHso1-mFFifH5M4T2ScuH8A,5198
193
- cognite_neat-0.123.1.dist-info/METADATA,sha256=4NPwnKYbAwVmCTktDxLB82sU6BtQKaqOA9vRTxUJveU,9171
194
- cognite_neat-0.123.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
195
- cognite_neat-0.123.1.dist-info/licenses/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
196
- cognite_neat-0.123.1.dist-info/RECORD,,
193
+ cognite_neat-0.123.3.dist-info/METADATA,sha256=RxK8IrMcBxC0d31JMKtLG0vuPD62WQhOuHM5j11Nov4,9171
194
+ cognite_neat-0.123.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
195
+ cognite_neat-0.123.3.dist-info/licenses/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
196
+ cognite_neat-0.123.3.dist-info/RECORD,,
@@ -1,98 +0,0 @@
1
- """This module performs importing of various formats to one of serializations for which
2
- there are loaders to data model pydantic class."""
3
-
4
- from cognite.neat.core._data_model.importers._rdf._base import BaseRDFImporter
5
- from cognite.neat.core._data_model.importers._rdf._shared import (
6
- parse_concepts,
7
- parse_properties,
8
- )
9
-
10
- CLASSES_QUERY = """
11
- SELECT ?concept ?name ?description ?implements
12
- WHERE {{
13
- VALUES ?type {{ imf:BlockType imf:TerminalType imf:AttributeType }}
14
- ?concept a ?type .
15
-
16
- OPTIONAL {{?concept rdfs:subClassOf ?parent }}.
17
- OPTIONAL {{?concept rdfs:label|skos:prefLabel ?name }}.
18
- OPTIONAL {{?concept rdfs:comment|skos:definition ?description}}.
19
-
20
-
21
- # Add imf:Attribute as parent class when no parent is found
22
- BIND(IF(!bound(?parent) && ?type = imf:AttributeType, imf:Attribute, ?parent) AS ?implements)
23
-
24
- # FILTERS
25
- FILTER (!isBlank(?concept))
26
- FILTER (!bound(?implements) || !isBlank(?implements))
27
-
28
- FILTER (!bound(?name) || LANG(?name) = "" || LANGMATCHES(LANG(?name), "{language}"))
29
- FILTER (!bound(?description) || LANG(?description) = "" || LANGMATCHES(LANG(?description), "{language}"))
30
- }}
31
- """
32
-
33
- PROPERTIES_QUERY = """
34
- SELECT ?concept ?property_ ?name ?description ?value_type ?min_count ?max_count ?default
35
- WHERE
36
- {{
37
- # CASE 1: Handling Blocks and Terminals
38
- {{
39
- VALUES ?type {{ imf:BlockType imf:TerminalType }}
40
- ?concept a ?type ;
41
- sh:property ?propertyShape .
42
- ?propertyShape sh:path ?property_ .
43
-
44
- OPTIONAL {{ ?property_ skos:prefLabel ?name . }}
45
- OPTIONAL {{ ?property_ skos:definition ?description . }}
46
- OPTIONAL {{ ?property_ rdfs:range ?range . }}
47
-
48
- OPTIONAL {{ ?propertyShape sh:minCount ?min_count . }}
49
- OPTIONAL {{ ?propertyShape sh:maxCount ?max_count . }}
50
- OPTIONAL {{ ?propertyShape sh:hasValue ?default . }}
51
- OPTIONAL {{ ?propertyShape sh:class | sh:qualifiedValueShape/sh:class ?valueShape . }}
52
- }}
53
-
54
- UNION
55
-
56
- # CASE 2: Handling Attributes
57
- {{
58
- ?concept a imf:AttributeType .
59
- BIND(xsd:anyURI AS ?valueShape)
60
- BIND(imf:predicate AS ?property_)
61
- ?concept ?property_ ?defaultURI .
62
- BIND(STR(?defaultURI) AS ?default)
63
-
64
- }}
65
-
66
- # Set the value type for the property based on sh:class, sh:qualifiedValueType or rdfs:range
67
- BIND(IF(BOUND(?valueShape), ?valueShape, IF(BOUND(?range) , ?range , ?valueShape)) AS ?value_type)
68
-
69
- FILTER (!isBlank(?property_))
70
- FILTER (!bound(?concept) || !isBlank(?concept))
71
- FILTER (!bound(?name) || LANG(?name) = "" || LANGMATCHES(LANG(?name), "{language}"))
72
- FILTER (!bound(?description) || LANG(?description) = "" || LANGMATCHES(LANG(?description), "{language}"))
73
- }}
74
- """
75
-
76
-
77
- class IMFImporter(BaseRDFImporter):
78
- """Convert IMF Types provided as SHACL shapes to unverified data model."""
79
-
80
- @property
81
- def description(self) -> str:
82
- return f"IMF Types {self.source_name} read as unverified data model"
83
-
84
- def _to_data_model_components(
85
- self,
86
- ) -> dict:
87
- classes, issue_list = parse_concepts(self.graph, CLASSES_QUERY, self.language, self.issue_list)
88
- self.issue_list = issue_list
89
- properties, issue_list = parse_properties(self.graph, PROPERTIES_QUERY, self.language, self.issue_list)
90
- self.issue_list = issue_list
91
-
92
- components = {
93
- "Metadata": self._metadata,
94
- "Concepts": list(classes.values()) if classes else [],
95
- "Properties": list(properties.values()) if properties else [],
96
- }
97
-
98
- return components