cognite-neat 0.77.10__py3-none-any.whl → 0.78.0__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 +1 @@
1
- __version__ = "0.77.10"
1
+ __version__ = "0.78.0"
@@ -11,11 +11,12 @@ from cognite.neat.rules.importers._base import BaseImporter, Rules, _handle_issu
11
11
  from cognite.neat.rules.issues import IssueList
12
12
  from cognite.neat.rules.models import InformationRules, RoleTypes
13
13
  from cognite.neat.rules.models._base import MatchType
14
+ from cognite.neat.rules.models.entities import ClassEntity
14
15
  from cognite.neat.rules.models.information import (
15
16
  InformationMetadata,
16
17
  InformationRulesInput,
17
18
  )
18
- from cognite.neat.utils.utils import get_namespace, remove_namespace
19
+ from cognite.neat.utils.utils import get_namespace, remove_namespace, replace_non_alphanumeric_with_underscore
19
20
 
20
21
  ORDERED_CLASSES_QUERY = """SELECT ?class (count(?s) as ?instances )
21
22
  WHERE { ?s a ?class . }
@@ -106,7 +107,7 @@ class InferenceImporter(BaseImporter):
106
107
  return self._return_or_raise(self.issue_list, errors)
107
108
 
108
109
  if self.make_compliant and rules:
109
- rules = self._make_dms_compliant_rules(rules)
110
+ self._make_dms_compliant_rules(rules)
110
111
 
111
112
  return self._to_output(
112
113
  rules,
@@ -172,7 +173,7 @@ class InferenceImporter(BaseImporter):
172
173
  definition = {
173
174
  "class_": class_id,
174
175
  "property_": property_id,
175
- "max_occurrence": cast(RdfLiteral, occurrence).value,
176
+ "max_count": cast(RdfLiteral, occurrence).value,
176
177
  "value_type": value_type_id,
177
178
  "reference": property_uri,
178
179
  }
@@ -180,7 +181,6 @@ class InferenceImporter(BaseImporter):
180
181
  # USE CASE 1: If property is not present in properties
181
182
  if id_ not in properties:
182
183
  properties[id_] = definition
183
-
184
184
  # USE CASE 2: If property is present in properties but with different max count
185
185
  elif id_ in properties and not (properties[id_]["max_count"] == definition["max_count"]):
186
186
  properties[id_]["max_count"] = max(properties[id_]["max_count"], definition["max_count"])
@@ -217,5 +217,36 @@ class InferenceImporter(BaseImporter):
217
217
  )
218
218
 
219
219
  @classmethod
220
- def _make_dms_compliant_rules(cls, rules: InformationRules) -> InformationRules:
221
- raise NotImplementedError("Compliance with DMS is not supported yet.")
220
+ def _make_dms_compliant_rules(cls, rules: InformationRules) -> None:
221
+ cls._fix_property_redefinition(rules)
222
+ cls._fix_naming_of_entities(rules)
223
+
224
+ @classmethod
225
+ def _fix_property_redefinition(cls, rules: InformationRules) -> None:
226
+ seen = set()
227
+ for i, property_ in enumerate(rules.properties.data):
228
+ prop_id = f"{property_.class_}.{property_.property_}"
229
+ if prop_id in seen:
230
+ property_.property_ = f"{property_.property_}_{i+1}"
231
+ seen.add(f"{property_.class_}.{property_.property_}")
232
+ else:
233
+ seen.add(prop_id)
234
+
235
+ @classmethod
236
+ def _fix_naming_of_entities(cls, rules: InformationRules) -> None:
237
+ # Fixing class ids
238
+ for class_ in rules.classes:
239
+ class_.class_ = class_.class_.as_dms_compliant_entity()
240
+ class_.parent = [parent.as_dms_compliant_entity() for parent in class_.parent] if class_.parent else None
241
+
242
+ # Fixing property definitions
243
+ for property_ in rules.properties:
244
+ # fix class id
245
+ property_.class_ = property_.class_.as_dms_compliant_entity()
246
+
247
+ # fix property id
248
+ property_.property_ = replace_non_alphanumeric_with_underscore(property_.property_)
249
+
250
+ # fix value type
251
+ if isinstance(property_.value_type, ClassEntity):
252
+ property_.value_type = property_.value_type.as_dms_compliant_entity()
@@ -7,6 +7,8 @@ from typing import Annotated, Any, ClassVar, Generic, TypeVar, cast
7
7
  from cognite.client.data_classes.data_modeling.ids import ContainerId, DataModelId, NodeId, PropertyId, ViewId
8
8
  from pydantic import AnyHttpUrl, BaseModel, BeforeValidator, Field, PlainSerializer, model_serializer, model_validator
9
9
 
10
+ from cognite.neat.utils.utils import replace_non_alphanumeric_with_underscore
11
+
10
12
  if sys.version_info >= (3, 11):
11
13
  from enum import StrEnum
12
14
  from typing import Self
@@ -231,6 +233,11 @@ class ClassEntity(Entity):
231
233
  space = default_space if isinstance(self.prefix, _UndefinedType) else self.prefix
232
234
  return ContainerEntity(space=space, externalId=str(self.suffix))
233
235
 
236
+ def as_dms_compliant_entity(self) -> "Self":
237
+ new_entity = self.model_copy(deep=True)
238
+ new_entity.suffix = replace_non_alphanumeric_with_underscore(new_entity.suffix)
239
+ return new_entity
240
+
234
241
 
235
242
  class ParentClassEntity(ClassEntity):
236
243
  type_: ClassVar[EntityTypes] = EntityTypes.parent_class
@@ -1,5 +1,6 @@
1
1
  import hashlib
2
2
  import logging
3
+ import re
3
4
  import sys
4
5
  import time
5
6
  from collections import OrderedDict
@@ -350,3 +351,7 @@ def get_inheritance_path(child: Any, child_parent: dict[Any, list[Any]]) -> list
350
351
  for parent in child_parent[child]:
351
352
  path.extend(get_inheritance_path(parent, child_parent))
352
353
  return path
354
+
355
+
356
+ def replace_non_alphanumeric_with_underscore(text):
357
+ return re.sub(r"\W+", "_", text)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cognite-neat
3
- Version: 0.77.10
3
+ Version: 0.78.0
4
4
  Summary: Knowledge graph transformation
5
5
  Home-page: https://cognite-neat.readthedocs-hosted.com/
6
6
  License: Apache-2.0
@@ -1,5 +1,5 @@
1
1
  cognite/neat/__init__.py,sha256=v-rRiDOgZ3sQSMQKq0vgUQZvpeOkoHFXissAx6Ktg84,61
2
- cognite/neat/_version.py,sha256=-swOEBp1OmcqYEuvtO9gV117lIY0GkQSzACgRA9L1AE,24
2
+ cognite/neat/_version.py,sha256=c66Ro55TMfP42f5YzH82UTnUBBvi0RwfY4nXmvb0W50,23
3
3
  cognite/neat/app/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  cognite/neat/app/api/asgi/metrics.py,sha256=nxFy7L5cChTI0a-zkCiJ59Aq8yLuIJp5c9Dg0wRXtV0,152
5
5
  cognite/neat/app/api/configuration.py,sha256=2U5M6M252swvQPQyooA1EBzFUZNtcTmuSaywfJDgckM,4232
@@ -178,7 +178,7 @@ cognite/neat/rules/importers/_dtdl2rules/_unit_lookup.py,sha256=wW4saKva61Q_i17g
178
178
  cognite/neat/rules/importers/_dtdl2rules/dtdl_converter.py,sha256=ysmWUxZ0npwrTB0uiH5jA0v37sfCwowGaYk17IyxPUU,12663
179
179
  cognite/neat/rules/importers/_dtdl2rules/dtdl_importer.py,sha256=QDyGt5YBaxzF4v_oCFSgKRSpwVdVruDU3-VW0DEiHbY,6718
180
180
  cognite/neat/rules/importers/_dtdl2rules/spec.py,sha256=tim_MfN1J0F3Oeqk3BMgIA82d_MZvhRuRMsLK3B4PYc,11897
181
- cognite/neat/rules/importers/_inference2rules.py,sha256=VYs4SCYQk3OMJnCkpJ-fTsK73OfK8cOyYXBAdYI3_WU,9389
181
+ cognite/neat/rules/importers/_inference2rules.py,sha256=Jkq058al1NNGvVxrYZsv5y2-hFXt3CtGq9S1V5Vqbj8,10765
182
182
  cognite/neat/rules/importers/_owl2rules/__init__.py,sha256=tdGcrgtozdQyST-pTlxIa4cLBNTLvtk1nNYR4vOdFSw,63
183
183
  cognite/neat/rules/importers/_owl2rules/_owl2classes.py,sha256=LInFeBq-NbBIuMEAwgWch2a4DbBUt4_OMqPkwehW-sw,7591
184
184
  cognite/neat/rules/importers/_owl2rules/_owl2metadata.py,sha256=NdPN0dBB0NYkAcfC0yrYdIrGfdPbl5gfeGnSV3EtUPM,7786
@@ -210,7 +210,7 @@ cognite/neat/rules/models/dms/_schema.py,sha256=A4z8CINmLQgWzHoScxejRPMRo40ngKly
210
210
  cognite/neat/rules/models/dms/_serializer.py,sha256=iqp2zyyf8jEcU-R3PERuN8nu248xIqyxiWj4owAn92g,6406
211
211
  cognite/neat/rules/models/dms/_validation.py,sha256=nPSyfM1vGZ7d9Uv_2vF2HvMetygtehXW7eNtPD6eW8E,13937
212
212
  cognite/neat/rules/models/domain.py,sha256=tkKcHvDXnZ5IkOr1wHiuNBtE1h8OCFmf6GZSqzHzxjI,2814
213
- cognite/neat/rules/models/entities.py,sha256=iBG84Jr1qQ7PvkMJUJzJ1oWApeONb1IACixdJSztUhk,16395
213
+ cognite/neat/rules/models/entities.py,sha256=SuVPDVZdf18Mx7h5BgrF8HVojWq_X3cFyCDoTA_sOIU,16686
214
214
  cognite/neat/rules/models/information/__init__.py,sha256=HR6g8xgyU53U7Ck8pPdbT70817Q4NC1r1pCRq5SA8iw,291
215
215
  cognite/neat/rules/models/information/_converter.py,sha256=JN63_G5bygdL5WCz-q0_ygiU0NHkzUxm5mZ3WD8yUes,11029
216
216
  cognite/neat/rules/models/information/_rules.py,sha256=tdCjvAtqnFzEo2zcx-BZHmvjSs28gVun2wz8UaT-AOA,13268
@@ -230,7 +230,7 @@ cognite/neat/utils/cdf_loaders/data_classes.py,sha256=0apspfwVlFltYOZfmk_PNknS3Z
230
230
  cognite/neat/utils/exceptions.py,sha256=-w4cAcvcoWLf-_ZwAl7QV_NysfqtQzIOd1Ti-mpxJgM,981
231
231
  cognite/neat/utils/spreadsheet.py,sha256=LI0c7dlW0zXHkHw0NvB-gg6Df6cDcE3FbiaHBYLXdzQ,2714
232
232
  cognite/neat/utils/text.py,sha256=4bg1_Q0lg7KsoxaDOvXrVyeY78BJN8i-27BlyDzUCls,3082
233
- cognite/neat/utils/utils.py,sha256=VlMRlnpncvf7B4ccQzY91nLkErgYg_mAetS6zu2Yj3o,12818
233
+ cognite/neat/utils/utils.py,sha256=gcbBbuUSm7xJhgU7ZRzeNc4eJtDVCS2CdNhbGP9gLq4,12919
234
234
  cognite/neat/utils/xml.py,sha256=ppLT3lQKVp8wOP-m8-tFY8uB2P4R76l7R_-kUtsABng,992
235
235
  cognite/neat/workflows/__init__.py,sha256=oiKub_U9f5cA0I1nKl5dFkR4BD8_6Be9eMzQ_50PwP0,396
236
236
  cognite/neat/workflows/_exceptions.py,sha256=ugI_X1XNpikAiL8zIggBjcx6q7WvOpRIgvxHrj2Rhr4,1348
@@ -276,8 +276,8 @@ cognite/neat/workflows/steps_registry.py,sha256=fkTX14ZA7_gkUYfWIlx7A1XbCidvqR23
276
276
  cognite/neat/workflows/tasks.py,sha256=dqlJwKAb0jlkl7abbY8RRz3m7MT4SK8-7cntMWkOYjw,788
277
277
  cognite/neat/workflows/triggers.py,sha256=_BLNplzoz0iic367u1mhHMHiUrCwP-SLK6_CZzfODX0,7071
278
278
  cognite/neat/workflows/utils.py,sha256=gKdy3RLG7ctRhbCRwaDIWpL9Mi98zm56-d4jfHDqP1E,453
279
- cognite_neat-0.77.10.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
280
- cognite_neat-0.77.10.dist-info/METADATA,sha256=ioQ2hIZ3OVqhuHAAeHK1WePxy_c5Hu_n231b-m8E2R4,9307
281
- cognite_neat-0.77.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
282
- cognite_neat-0.77.10.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
283
- cognite_neat-0.77.10.dist-info/RECORD,,
279
+ cognite_neat-0.78.0.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
280
+ cognite_neat-0.78.0.dist-info/METADATA,sha256=I1IHVLVE_UkRsT2HM3vP3OtoE2AmEe_XaAi8wxFl1sY,9306
281
+ cognite_neat-0.78.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
282
+ cognite_neat-0.78.0.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
283
+ cognite_neat-0.78.0.dist-info/RECORD,,