cognite-neat 0.85.10__py3-none-any.whl → 0.85.11__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.
cognite/neat/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.85.10"
1
+ __version__ = "0.85.11"
@@ -2,6 +2,7 @@ import math
2
2
  import re
3
3
  import sys
4
4
  import warnings
5
+ from collections import defaultdict
5
6
  from datetime import datetime
6
7
  from typing import TYPE_CHECKING, Any, ClassVar, Literal
7
8
 
@@ -390,3 +391,72 @@ class DMSRules(BaseRules):
390
391
  from ._converter import _DMSRulesConverter
391
392
 
392
393
  return _DMSRulesConverter(self).as_domain_rules()
394
+
395
+ def create_reference(
396
+ self, reference: "DMSRules", view_extension_mapping: dict[str, str], default_extension: str | None = None
397
+ ) -> None:
398
+ """Takes this data models and makes it into an extension of the reference data model.
399
+
400
+ The argument view_extension_mapping is a dictionary where the keys are views of this data model,
401
+ and each value is the view of the reference data model that the view should extend. For example:
402
+
403
+ ```python
404
+ view_extension_mapping = {"Pump": "Asset"}
405
+ ```
406
+
407
+ This would make the view "Pump" in this data model extend the view "Asset" in the reference data model.
408
+ Note that all the keys in the dictionary must be external ids of views in this data model,
409
+ and all the values must be external ids of views in the reference data model.
410
+
411
+ Args:
412
+ reference: The reference data model
413
+ view_extension_mapping: A dictionary mapping views in this data model to views in the reference data model
414
+ default_extension: The default view in the reference data model that views in this
415
+ data model should extend if no mapping is provided.
416
+
417
+ """
418
+ if self.reference is not None:
419
+ raise ValueError("Reference already exists")
420
+ self.reference = reference
421
+ view_by_external_id = {view.view.external_id: view for view in self.views}
422
+ ref_view_by_external_id = {view.view.external_id: view for view in reference.views}
423
+
424
+ if invalid_views := set(view_extension_mapping.keys()) - set(view_by_external_id.keys()):
425
+ raise ValueError(f"Views are not in this dat model {invalid_views}")
426
+ if invalid_views := set(view_extension_mapping.values()) - set(ref_view_by_external_id.keys()):
427
+ raise ValueError(f"Views are not in the reference data model {invalid_views}")
428
+ if default_extension and default_extension not in ref_view_by_external_id:
429
+ raise ValueError(f"Default extension view not in the reference data model {default_extension}")
430
+
431
+ properties_by_view_external_id: dict[str, dict[str, DMSProperty]] = defaultdict(dict)
432
+ for prop in self.properties:
433
+ properties_by_view_external_id[prop.view.external_id][prop.view_property] = prop
434
+
435
+ ref_properties_by_view_external_id: dict[str, dict[str, DMSProperty]] = defaultdict(dict)
436
+ for prop in reference.properties:
437
+ ref_properties_by_view_external_id[prop.view.external_id][prop.view_property] = prop
438
+
439
+ for view_external_id, view in view_by_external_id.items():
440
+ if view_external_id in view_extension_mapping:
441
+ ref_external_id = view_extension_mapping[view_external_id]
442
+ elif default_extension:
443
+ ref_external_id = default_extension
444
+ else:
445
+ continue
446
+
447
+ ref_view = ref_view_by_external_id[ref_external_id]
448
+ shared_properties = set(properties_by_view_external_id[view_external_id].keys()) & set(
449
+ ref_properties_by_view_external_id[ref_external_id].keys()
450
+ )
451
+ if shared_properties:
452
+ if view.implements is None:
453
+ view.implements = [ref_view.view]
454
+ elif isinstance(view.implements, list) and ref_view.view not in view.implements:
455
+ view.implements.append(ref_view.view)
456
+ for prop_name in shared_properties:
457
+ prop = properties_by_view_external_id[view_external_id][prop_name]
458
+ ref_prop = ref_properties_by_view_external_id[ref_external_id][prop_name]
459
+ if ref_prop.container and ref_prop.container_property:
460
+ prop.container = ref_prop.container
461
+ prop.container_property = ref_prop.container_property
462
+ prop.reference = ReferenceEntity.from_entity(ref_prop.view, ref_prop.view_property)
@@ -146,7 +146,9 @@ class DMSPropertyInput:
146
146
  "Value Type": value_type,
147
147
  "Property (linage)": self.property_ or self.view_property,
148
148
  "Class (linage)": (
149
- ClassEntity.load(self.class_, prefix=default_space, version=default_version) if self.class_ else None
149
+ ClassEntity.load(self.class_ or self.view, prefix=default_space, version=default_version)
150
+ if self.class_ or self.view
151
+ else None
150
152
  ),
151
153
  "Name": self.name,
152
154
  "Description": self.description,
@@ -499,6 +499,13 @@ class ReferenceEntity(ClassEntity):
499
499
  prefix: str
500
500
  property_: str | None = Field(None, alias="property")
501
501
 
502
+ @classmethod
503
+ def from_entity(cls, entity: Entity, property_: str) -> "ReferenceEntity":
504
+ if isinstance(entity, ClassEntity):
505
+ return cls(prefix=str(entity.prefix), suffix=entity.suffix, version=entity.version, property=property_)
506
+ else:
507
+ return cls(prefix=str(entity.prefix), suffix=entity.suffix, property=property_)
508
+
502
509
  def as_view_id(self) -> ViewId:
503
510
  if isinstance(self.prefix, _UndefinedType) or isinstance(self.suffix, _UnknownType):
504
511
  raise ValueError("Prefix is not defined or suffix is unknown")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cognite-neat
3
- Version: 0.85.10
3
+ Version: 0.85.11
4
4
  Summary: Knowledge graph transformation
5
5
  Home-page: https://cognite-neat.readthedocs-hosted.com/
6
6
  License: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  cognite/neat/__init__.py,sha256=AiexNcHdAHFbrrbo9c65gtil1dqx_SGraDH1PSsXjKE,126
2
2
  cognite/neat/_shared.py,sha256=RSaHm2eJceTlvb-hMMe4nHgoHdPYDfN3XcxDXo24k3A,1530
3
- cognite/neat/_version.py,sha256=r9a11H4Pc6Steq_whDR9D6B9Q8eBS2t0VVcst7vsaQA,24
3
+ cognite/neat/_version.py,sha256=bVP2BELxIGHP-amVHOwETotJ5zyQqFcbe7c26GvSm-c,24
4
4
  cognite/neat/app/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  cognite/neat/app/api/asgi/metrics.py,sha256=nxFy7L5cChTI0a-zkCiJ59Aq8yLuIJp5c9Dg0wRXtV0,152
6
6
  cognite/neat/app/api/configuration.py,sha256=2U5M6M252swvQPQyooA1EBzFUZNtcTmuSaywfJDgckM,4232
@@ -236,13 +236,13 @@ cognite/neat/rules/models/data_types.py,sha256=xAjm8UVEQlSylfkUJWiWP2NaK6dLYRDAB
236
236
  cognite/neat/rules/models/dms/__init__.py,sha256=Wzyqzz2ZIjpUbDg04CMuuIAw-f2A02DayNeqO9R-2Hw,491
237
237
  cognite/neat/rules/models/dms/_converter.py,sha256=QaJT0z0Yo4gkG9tHPZkU8idF8PK7c-tDahbyIT-WJQU,5959
238
238
  cognite/neat/rules/models/dms/_exporter.py,sha256=DRL5ahcBEdBltHLA2rzLyUfqG5SZkqINkqmYGDkQVg0,24785
239
- cognite/neat/rules/models/dms/_rules.py,sha256=XTIEWG49VjNs_bICGlgMd6uk4hseY1H6UVe2KMfHAWQ,16152
240
- cognite/neat/rules/models/dms/_rules_input.py,sha256=apDDTQll9UAyYL5gS2vDxHsujWrGBilTp7lK2kzJWO8,13467
239
+ cognite/neat/rules/models/dms/_rules.py,sha256=M7qv4uTZ-qpnIFQtoExEDppz0m0beNPm01djZxaj0yo,20118
240
+ cognite/neat/rules/models/dms/_rules_input.py,sha256=M5AqwW-p6z_qAum-1HE_lmONSmg-vF1ak7Y_AiM8vnU,13525
241
241
  cognite/neat/rules/models/dms/_schema.py,sha256=balykJXJy93HJzBZN-KBYrRJJvGsaEtQeX7-z0tbX7w,49566
242
242
  cognite/neat/rules/models/dms/_serializer.py,sha256=iqp2zyyf8jEcU-R3PERuN8nu248xIqyxiWj4owAn92g,6406
243
243
  cognite/neat/rules/models/dms/_validation.py,sha256=5mk9L99FSwC8Ok7weEjnFJ_OZnmqMWUc6XFMTfkqfDw,14549
244
244
  cognite/neat/rules/models/domain.py,sha256=wZ-DeIPFnacbNlxSrRuLzUpnhHdTpzNc22z0sDfisi4,2880
245
- cognite/neat/rules/models/entities.py,sha256=qZa_PJOjFk3yTu5NyTSbAjsrU0HUxVnme_7YruBJoRQ,20460
245
+ cognite/neat/rules/models/entities.py,sha256=u8jbE7n99FKKND6U9ogoUfhjtataDtATprAyRgBNwrw,20823
246
246
  cognite/neat/rules/models/information/__init__.py,sha256=HR6g8xgyU53U7Ck8pPdbT70817Q4NC1r1pCRq5SA8iw,291
247
247
  cognite/neat/rules/models/information/_converter.py,sha256=nsfOCe13c3gqbbF1mrQHofemzYKpvg_NKjJZDwSXo5E,13960
248
248
  cognite/neat/rules/models/information/_rules.py,sha256=v8ptTif8X55wYaNHvsx65jK7PP2ClSYWyFWUyI2rbyY,13487
@@ -310,8 +310,8 @@ cognite/neat/workflows/steps_registry.py,sha256=fkTX14ZA7_gkUYfWIlx7A1XbCidvqR23
310
310
  cognite/neat/workflows/tasks.py,sha256=dqlJwKAb0jlkl7abbY8RRz3m7MT4SK8-7cntMWkOYjw,788
311
311
  cognite/neat/workflows/triggers.py,sha256=_BLNplzoz0iic367u1mhHMHiUrCwP-SLK6_CZzfODX0,7071
312
312
  cognite/neat/workflows/utils.py,sha256=gKdy3RLG7ctRhbCRwaDIWpL9Mi98zm56-d4jfHDqP1E,453
313
- cognite_neat-0.85.10.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
314
- cognite_neat-0.85.10.dist-info/METADATA,sha256=8UOfc9V1ro6ldjvcGGTZek0bLiddHUjhdm4pbAfNoFw,9494
315
- cognite_neat-0.85.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
316
- cognite_neat-0.85.10.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
317
- cognite_neat-0.85.10.dist-info/RECORD,,
313
+ cognite_neat-0.85.11.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
314
+ cognite_neat-0.85.11.dist-info/METADATA,sha256=dofrglhVYBscSaExRgcBzxsXGN7a1cNkk1srGCk692w,9494
315
+ cognite_neat-0.85.11.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
316
+ cognite_neat-0.85.11.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
317
+ cognite_neat-0.85.11.dist-info/RECORD,,