cognite-neat 0.123.41__py3-none-any.whl → 0.123.43__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.

@@ -0,0 +1,51 @@
1
+ from collections import Counter
2
+
3
+ from pydantic import Field, ValidationInfo, field_validator
4
+
5
+ from cognite.neat._data_model.models.entities._constants import PREFIX_PATTERN, SUFFIX_PATTERN, VERSION_PATTERN
6
+ from cognite.neat._utils.text import humanize_collection
7
+ from cognite.neat.v0.core._data_model.models.entities._single_value import ConceptEntity
8
+
9
+ from ._base import ResourceMetadata
10
+ from ._concept import Concept
11
+
12
+
13
+ class DataModel(ResourceMetadata):
14
+ space: str = Field(
15
+ description="Id of the space that the concept belongs to.",
16
+ min_length=1,
17
+ max_length=43,
18
+ pattern=PREFIX_PATTERN,
19
+ alias="prefix",
20
+ )
21
+ external_id: str = Field(
22
+ description="External-id of the concept.",
23
+ min_length=1,
24
+ max_length=255,
25
+ pattern=SUFFIX_PATTERN,
26
+ alias="suffix",
27
+ )
28
+ version: str = Field(
29
+ description="Version of the concept.",
30
+ max_length=43,
31
+ pattern=VERSION_PATTERN,
32
+ )
33
+
34
+ concepts: list[Concept] = Field(
35
+ description="References to the concepts from where this concept will inherit properties.",
36
+ )
37
+
38
+ @field_validator("concepts", mode="after")
39
+ def cannot_have_duplicates(cls, value: list[Concept], info: ValidationInfo) -> list[Concept]:
40
+ concept_ids = [
41
+ ConceptEntity(prefix=concept.space, suffix=concept.external_id, version=concept.version)
42
+ for concept in value
43
+ ]
44
+
45
+ counts = Counter(concept_ids)
46
+ duplicates = {concept for concept, count in counts.items() if count > 1}
47
+
48
+ if duplicates:
49
+ raise ValueError(f"Duplicate concepts found: {humanize_collection(duplicates)}")
50
+
51
+ return value
@@ -78,11 +78,12 @@ class Property(ResourceMetadata):
78
78
  return value
79
79
 
80
80
  max_count = info.data.get("max_count")
81
+ min_count = info.data.get("min_count")
81
82
 
82
- if max_count is None or max_count > 1:
83
+ if max_count is None or max_count > 1 or (min_count and min_count > 1):
83
84
  raise ValueError(
84
85
  "Setting default value is only supported for single-valued properties."
85
- f" Property has max_count={max_count or 'Inf'}."
86
+ f" Property has min_count={info.data.get('min_count')} and max_count={info.data.get('max_count')}."
86
87
  )
87
88
  return value
88
89
 
cognite/neat/_version.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "0.123.41"
1
+ __version__ = "0.123.43"
2
2
  __engine__ = "^2.0.4"
@@ -274,3 +274,5 @@ DMS_RESERVED_PROPERTIES = frozenset(
274
274
  "endNode",
275
275
  }
276
276
  )
277
+
278
+ NAMED_GRAPH_NAMESPACE = Namespace("http://thisisneat.io/namedgraph/")
@@ -1,15 +1,19 @@
1
+ import re
1
2
  import warnings
2
3
  from typing import Any, Literal, cast
3
4
 
4
5
  from cognite.client.data_classes.data_modeling import DataModelId, DataModelIdentifier
5
6
  from cognite.client.utils.useful_types import SequenceNotStr
7
+ from rdflib import URIRef
6
8
 
7
9
  from cognite.neat.v0.core._client import NeatClient
8
10
  from cognite.neat.v0.core._constants import (
9
11
  CLASSIC_CDF_NAMESPACE,
12
+ NAMED_GRAPH_NAMESPACE,
10
13
  get_default_prefixes_and_namespaces,
11
14
  )
12
15
  from cognite.neat.v0.core._data_model import catalog, importers
16
+ from cognite.neat.v0.core._data_model._constants import SPACE_COMPLIANCE_REGEX
13
17
  from cognite.neat.v0.core._data_model.importers import BaseImporter
14
18
  from cognite.neat.v0.core._data_model.models.entities._single_value import ViewEntity
15
19
  from cognite.neat.v0.core._data_model.transformers import ClassicPrepareCore
@@ -826,13 +830,21 @@ class RDFReadAPI(BaseReadAPI):
826
830
  importer = importers.OWLImporter.from_file(reader.materialize_path(), source_name=f"file {reader!s}")
827
831
  return self._state.data_model_import(importer)
828
832
 
829
- def instances(self, io: Any) -> IssueList:
833
+ def instances(self, io: Any, named_graph: str | None = None) -> IssueList:
830
834
  self._state._raise_exception_if_condition_not_met(
831
835
  "Read RDF Instances",
832
836
  empty_data_model_store_required=True,
833
837
  )
834
838
  reader = NeatReader.create(io)
835
- self._state.instances.store.write(extractors.RdfFileExtractor(reader.materialize_path()))
839
+
840
+ # validate and convert named_graph to URI
841
+ named_graph_uri: URIRef | None = None
842
+ if named_graph:
843
+ if not re.match(SPACE_COMPLIANCE_REGEX, named_graph):
844
+ raise NeatValueError(f"Named graph '{named_graph}' does not comply with naming requirements. ")
845
+ named_graph_uri = NAMED_GRAPH_NAMESPACE[named_graph]
846
+
847
+ self._state.instances.store.write(extractors.RdfFileExtractor(reader.materialize_path()), named_graph_uri)
836
848
  return IssueList()
837
849
 
838
850
  def __call__(
@@ -840,6 +852,7 @@ class RDFReadAPI(BaseReadAPI):
840
852
  io: Any,
841
853
  type: NeatObjectType | None = None,
842
854
  source: RDFFileType | None = None,
855
+ named_graph: str | URIRef | None = None,
843
856
  ) -> IssueList:
844
857
  if type is None:
845
858
  type = object_wizard()
@@ -858,7 +871,7 @@ class RDFReadAPI(BaseReadAPI):
858
871
  raise ValueError(f"Expected ontology, imf types or instances, got {source}")
859
872
 
860
873
  elif type == "instances":
861
- return self.instances(io)
874
+ return self.instances(io, named_graph=named_graph)
862
875
 
863
876
  else:
864
877
  raise NeatSessionError(f"Expected data model or instances, got {type}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognite-neat
3
- Version: 0.123.41
3
+ Version: 0.123.43
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,6 +1,6 @@
1
1
  cognite/neat/__init__.py,sha256=Lo4DbjDOwnhCYUoAgPp5RG1fDdF7OlnomalTe7n1ydw,211
2
2
  cognite/neat/_issues.py,sha256=uv0fkkWwTKqNmTmHqyoBB3L6yMCh42EZpEkLGmIJYOY,812
3
- cognite/neat/_version.py,sha256=ufRXfLAZOiccgiTU2G1cLrNuGEalUnTHSuR_tpkSN2w,47
3
+ cognite/neat/_version.py,sha256=dEWoG_6PogUbhTlc8CLubWeLvGWXiuXTv6Q2rLO3bJs,47
4
4
  cognite/neat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  cognite/neat/_data_model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  cognite/neat/_data_model/_constants.py,sha256=NGGvWHlQqhkkSBP_AqoofGYjNph3SiZX6QPINlMsy04,107
@@ -11,8 +11,9 @@ cognite/neat/_data_model/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
11
11
  cognite/neat/_data_model/models/conceptual/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  cognite/neat/_data_model/models/conceptual/_base.py,sha256=SFkoBJDM51pqew_isHFJoB20OgfofpwVRnTrg-rKkNY,710
13
13
  cognite/neat/_data_model/models/conceptual/_concept.py,sha256=0Pk4W2TJ_Y0Z7oPHpzely1kPXrAkmkyqw6a0n3il6LY,2248
14
+ cognite/neat/_data_model/models/conceptual/_data_model.py,sha256=mSX0z8i29ufcRUhvC_NPeo2xGidlK3B1n89kngY_SqQ,1695
14
15
  cognite/neat/_data_model/models/conceptual/_properties.py,sha256=CpF37vJYBTLT4DH4ZOu2U-JyWtkb_27V8fw52qiaE_k,4007
15
- cognite/neat/_data_model/models/conceptual/_property.py,sha256=CpF37vJYBTLT4DH4ZOu2U-JyWtkb_27V8fw52qiaE_k,4007
16
+ cognite/neat/_data_model/models/conceptual/_property.py,sha256=blSZQxX52zaILAtjUkldPzPeysz7wnG-UGSNU5tacI8,4138
16
17
  cognite/neat/_data_model/models/dms/__init__.py,sha256=I_yw2GoEjUdLk8VOiLSlU4BWgE3u_GgCHJayeEa1w1w,3583
17
18
  cognite/neat/_data_model/models/dms/_base.py,sha256=R8SP3Zi9daTBqewYKGjuNEkrWc-j91f-6t34CN-9YJ0,719
18
19
  cognite/neat/_data_model/models/dms/_constants.py,sha256=wBkLjAPwufPc2naxOfPA1XC0CM2RbDbo6Dpiv9dPrew,1344
@@ -45,7 +46,7 @@ cognite/neat/_utils/http_client/_tracker.py,sha256=EBBnd-JZ7nc_jYNFJokCHN2UZ9sx0
45
46
  cognite/neat/v0/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
47
  cognite/neat/v0/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
48
  cognite/neat/v0/core/_config.py,sha256=WT1BS8uADcFvGoUYOOfwFOVq_VBl472TisdoA3wLick,280
48
- cognite/neat/v0/core/_constants.py,sha256=J0avfxWcipJup-pv9MvFIaO8NC0heDaNAsmSPMFEP3U,9063
49
+ cognite/neat/v0/core/_constants.py,sha256=mNNHu-QAD54DEA9A1yHd9Fk19SbqZAE6DoCfYxDRvbM,9134
49
50
  cognite/neat/v0/core/_shared.py,sha256=Ov59SWYboRRsncB_5V1ZC_BAoACfNLjo80vqE5Ru6wo,2325
50
51
  cognite/neat/v0/core/_client/__init__.py,sha256=RQ7MwL8mwGqGHokRzsPqO3XStDzmI4-c12_gz1UPJ74,177
51
52
  cognite/neat/v0/core/_client/_api_client.py,sha256=ZIipNVjd0kVts5Gh-PcV96DhA-RyT0v5EwZHa77hdXg,863
@@ -217,7 +218,7 @@ cognite/neat/v0/session/_inspect.py,sha256=6xC-tLJfP7sbSQpIlpPmCQWklGxK_rEXBE41j
217
218
  cognite/neat/v0/session/_mapping.py,sha256=9lQFnB0wpizo4ySIEDMWh183qpHh8TlVL7uOgAtJUxE,2904
218
219
  cognite/neat/v0/session/_plugin.py,sha256=TqEeUYDiZmOyl33h44J5OlqkH7VzgGi63nJFidpBV4M,2235
219
220
  cognite/neat/v0/session/_prepare.py,sha256=HFdDmBnYRpaCm90s_A0byHLJIZwKrt2ve6i3EyN0V6w,12802
220
- cognite/neat/v0/session/_read.py,sha256=2pdlWa-OHQ4j2gRKNTeBzWBOipDPnznnqyys-yzUq2s,34658
221
+ cognite/neat/v0/session/_read.py,sha256=jMviC69NLxaGqHFBcqHLNA_XPmIl2vOTTAchTOxR5nw,35288
221
222
  cognite/neat/v0/session/_set.py,sha256=qFi3YrYBd09MfHVJ2Ak0PCGigTAhGttfnA2iWSYwUt4,4617
222
223
  cognite/neat/v0/session/_show.py,sha256=O6Vcp5BNWfp2hpWuyqsdFhN0WAl29ot-QrC5iKBGe5Y,10758
223
224
  cognite/neat/v0/session/_state.py,sha256=2t1DBybamq67CuNZo_a1AQfDfYWnKS-MATFFuJf_h4M,7454
@@ -231,7 +232,7 @@ cognite/neat/v0/session/engine/__init__.py,sha256=D3MxUorEs6-NtgoICqtZ8PISQrjrr4
231
232
  cognite/neat/v0/session/engine/_import.py,sha256=1QxA2_EK613lXYAHKQbZyw2yjo5P9XuiX4Z6_6-WMNQ,169
232
233
  cognite/neat/v0/session/engine/_interface.py,sha256=3W-cYr493c_mW3P5O6MKN1xEQg3cA7NHR_ev3zdF9Vk,533
233
234
  cognite/neat/v0/session/engine/_load.py,sha256=u0x7vuQCRoNcPt25KJBJRn8sJabonYK4vtSZpiTdP4k,5201
234
- cognite_neat-0.123.41.dist-info/METADATA,sha256=x1il3bStkdRMLwIwGMK5UABcb2tkCyc3Zr63dkY27Vw,9148
235
- cognite_neat-0.123.41.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
236
- cognite_neat-0.123.41.dist-info/licenses/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
237
- cognite_neat-0.123.41.dist-info/RECORD,,
235
+ cognite_neat-0.123.43.dist-info/METADATA,sha256=R09xC2ziQsAEfmEMQ9tnUDA57fIpJstPhY7GUVqrFWc,9148
236
+ cognite_neat-0.123.43.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
237
+ cognite_neat-0.123.43.dist-info/licenses/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
238
+ cognite_neat-0.123.43.dist-info/RECORD,,