cognite-neat 0.87.4__py3-none-any.whl → 0.88.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.

Files changed (132) hide show
  1. cognite/neat/_version.py +1 -1
  2. cognite/neat/app/api/data_classes/rest.py +0 -19
  3. cognite/neat/app/api/explorer.py +6 -4
  4. cognite/neat/app/api/routers/crud.py +11 -21
  5. cognite/neat/app/api/routers/workflows.py +24 -94
  6. cognite/neat/graph/extractors/_classic_cdf/_assets.py +8 -2
  7. cognite/neat/graph/extractors/_mock_graph_generator.py +2 -2
  8. cognite/neat/graph/loaders/_base.py +17 -12
  9. cognite/neat/graph/loaders/_rdf2asset.py +223 -58
  10. cognite/neat/graph/loaders/_rdf2dms.py +1 -1
  11. cognite/neat/graph/stores/_base.py +5 -0
  12. cognite/neat/rules/analysis/_asset.py +31 -1
  13. cognite/neat/rules/importers/_inference2rules.py +31 -35
  14. cognite/neat/rules/models/information/_rules.py +1 -1
  15. cognite/neat/workflows/steps/data_contracts.py +17 -43
  16. cognite/neat/workflows/steps/lib/current/graph_extractor.py +28 -24
  17. cognite/neat/workflows/steps/lib/current/graph_loader.py +4 -21
  18. cognite/neat/workflows/steps/lib/current/graph_store.py +18 -134
  19. cognite/neat/workflows/steps_registry.py +5 -7
  20. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/METADATA +1 -1
  21. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/RECORD +24 -132
  22. cognite/neat/app/api/routers/core.py +0 -91
  23. cognite/neat/app/api/routers/data_exploration.py +0 -336
  24. cognite/neat/app/api/routers/rules.py +0 -203
  25. cognite/neat/legacy/__init__.py +0 -0
  26. cognite/neat/legacy/graph/__init__.py +0 -3
  27. cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -20182
  28. cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44.xml +0 -20163
  29. cognite/neat/legacy/graph/examples/__init__.py +0 -10
  30. cognite/neat/legacy/graph/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
  31. cognite/neat/legacy/graph/exceptions.py +0 -90
  32. cognite/neat/legacy/graph/extractors/__init__.py +0 -6
  33. cognite/neat/legacy/graph/extractors/_base.py +0 -14
  34. cognite/neat/legacy/graph/extractors/_dexpi.py +0 -44
  35. cognite/neat/legacy/graph/extractors/_graph_capturing_sheet.py +0 -403
  36. cognite/neat/legacy/graph/extractors/_mock_graph_generator.py +0 -361
  37. cognite/neat/legacy/graph/loaders/__init__.py +0 -23
  38. cognite/neat/legacy/graph/loaders/_asset_loader.py +0 -511
  39. cognite/neat/legacy/graph/loaders/_base.py +0 -67
  40. cognite/neat/legacy/graph/loaders/_exceptions.py +0 -85
  41. cognite/neat/legacy/graph/loaders/core/__init__.py +0 -0
  42. cognite/neat/legacy/graph/loaders/core/labels.py +0 -58
  43. cognite/neat/legacy/graph/loaders/core/models.py +0 -136
  44. cognite/neat/legacy/graph/loaders/core/rdf_to_assets.py +0 -1046
  45. cognite/neat/legacy/graph/loaders/core/rdf_to_relationships.py +0 -559
  46. cognite/neat/legacy/graph/loaders/rdf_to_dms.py +0 -309
  47. cognite/neat/legacy/graph/loaders/validator.py +0 -87
  48. cognite/neat/legacy/graph/models.py +0 -6
  49. cognite/neat/legacy/graph/stores/__init__.py +0 -13
  50. cognite/neat/legacy/graph/stores/_base.py +0 -400
  51. cognite/neat/legacy/graph/stores/_graphdb_store.py +0 -52
  52. cognite/neat/legacy/graph/stores/_memory_store.py +0 -43
  53. cognite/neat/legacy/graph/stores/_oxigraph_store.py +0 -151
  54. cognite/neat/legacy/graph/stores/_oxrdflib.py +0 -247
  55. cognite/neat/legacy/graph/stores/_rdf_to_graph.py +0 -42
  56. cognite/neat/legacy/graph/transformations/__init__.py +0 -0
  57. cognite/neat/legacy/graph/transformations/entity_matcher.py +0 -101
  58. cognite/neat/legacy/graph/transformations/query_generator/__init__.py +0 -3
  59. cognite/neat/legacy/graph/transformations/query_generator/sparql.py +0 -575
  60. cognite/neat/legacy/graph/transformations/transformer.py +0 -322
  61. cognite/neat/legacy/rules/__init__.py +0 -0
  62. cognite/neat/legacy/rules/analysis.py +0 -231
  63. cognite/neat/legacy/rules/examples/Rules-Nordic44-to-graphql.xlsx +0 -0
  64. cognite/neat/legacy/rules/examples/Rules-Nordic44.xlsx +0 -0
  65. cognite/neat/legacy/rules/examples/__init__.py +0 -18
  66. cognite/neat/legacy/rules/examples/power-grid-containers.yaml +0 -124
  67. cognite/neat/legacy/rules/examples/power-grid-example.xlsx +0 -0
  68. cognite/neat/legacy/rules/examples/power-grid-model.yaml +0 -224
  69. cognite/neat/legacy/rules/examples/rules-template.xlsx +0 -0
  70. cognite/neat/legacy/rules/examples/sheet2cdf-transformation-rules.xlsx +0 -0
  71. cognite/neat/legacy/rules/examples/skos-rules.xlsx +0 -0
  72. cognite/neat/legacy/rules/examples/source-to-solution-mapping-rules.xlsx +0 -0
  73. cognite/neat/legacy/rules/examples/wind-energy.owl +0 -1511
  74. cognite/neat/legacy/rules/exceptions.py +0 -2972
  75. cognite/neat/legacy/rules/exporters/__init__.py +0 -20
  76. cognite/neat/legacy/rules/exporters/_base.py +0 -45
  77. cognite/neat/legacy/rules/exporters/_core/__init__.py +0 -5
  78. cognite/neat/legacy/rules/exporters/_core/rules2labels.py +0 -24
  79. cognite/neat/legacy/rules/exporters/_rules2dms.py +0 -885
  80. cognite/neat/legacy/rules/exporters/_rules2excel.py +0 -213
  81. cognite/neat/legacy/rules/exporters/_rules2graphql.py +0 -183
  82. cognite/neat/legacy/rules/exporters/_rules2ontology.py +0 -524
  83. cognite/neat/legacy/rules/exporters/_rules2pydantic_models.py +0 -748
  84. cognite/neat/legacy/rules/exporters/_rules2rules.py +0 -105
  85. cognite/neat/legacy/rules/exporters/_rules2triples.py +0 -38
  86. cognite/neat/legacy/rules/exporters/_validation.py +0 -146
  87. cognite/neat/legacy/rules/importers/__init__.py +0 -22
  88. cognite/neat/legacy/rules/importers/_base.py +0 -66
  89. cognite/neat/legacy/rules/importers/_dict2rules.py +0 -158
  90. cognite/neat/legacy/rules/importers/_dms2rules.py +0 -194
  91. cognite/neat/legacy/rules/importers/_graph2rules.py +0 -308
  92. cognite/neat/legacy/rules/importers/_json2rules.py +0 -39
  93. cognite/neat/legacy/rules/importers/_owl2rules/__init__.py +0 -3
  94. cognite/neat/legacy/rules/importers/_owl2rules/_owl2classes.py +0 -239
  95. cognite/neat/legacy/rules/importers/_owl2rules/_owl2metadata.py +0 -260
  96. cognite/neat/legacy/rules/importers/_owl2rules/_owl2properties.py +0 -217
  97. cognite/neat/legacy/rules/importers/_owl2rules/_owl2rules.py +0 -290
  98. cognite/neat/legacy/rules/importers/_spreadsheet2rules.py +0 -45
  99. cognite/neat/legacy/rules/importers/_xsd2rules.py +0 -20
  100. cognite/neat/legacy/rules/importers/_yaml2rules.py +0 -39
  101. cognite/neat/legacy/rules/models/__init__.py +0 -5
  102. cognite/neat/legacy/rules/models/_base.py +0 -151
  103. cognite/neat/legacy/rules/models/raw_rules.py +0 -316
  104. cognite/neat/legacy/rules/models/rdfpath.py +0 -237
  105. cognite/neat/legacy/rules/models/rules.py +0 -1289
  106. cognite/neat/legacy/rules/models/tables.py +0 -9
  107. cognite/neat/legacy/rules/models/value_types.py +0 -118
  108. cognite/neat/legacy/workflows/examples/Export_DMS/workflow.yaml +0 -89
  109. cognite/neat/legacy/workflows/examples/Export_Rules_to_Ontology/workflow.yaml +0 -152
  110. cognite/neat/legacy/workflows/examples/Extract_DEXPI_Graph_and_Export_Rules/workflow.yaml +0 -139
  111. cognite/neat/legacy/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -270
  112. cognite/neat/legacy/workflows/examples/Import_DMS/workflow.yaml +0 -65
  113. cognite/neat/legacy/workflows/examples/Ontology_to_Data_Model/workflow.yaml +0 -116
  114. cognite/neat/legacy/workflows/examples/Validate_Rules/workflow.yaml +0 -67
  115. cognite/neat/legacy/workflows/examples/Validate_Solution_Model/workflow.yaml +0 -64
  116. cognite/neat/legacy/workflows/examples/Visualize_Data_Model_Using_Mock_Graph/workflow.yaml +0 -95
  117. cognite/neat/legacy/workflows/examples/Visualize_Semantic_Data_Model/workflow.yaml +0 -111
  118. cognite/neat/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -270
  119. cognite/neat/workflows/migration/__init__.py +0 -0
  120. cognite/neat/workflows/migration/steps.py +0 -91
  121. cognite/neat/workflows/migration/wf_manifests.py +0 -33
  122. cognite/neat/workflows/steps/lib/legacy/__init__.py +0 -7
  123. cognite/neat/workflows/steps/lib/legacy/graph_contextualization.py +0 -82
  124. cognite/neat/workflows/steps/lib/legacy/graph_extractor.py +0 -746
  125. cognite/neat/workflows/steps/lib/legacy/graph_loader.py +0 -606
  126. cognite/neat/workflows/steps/lib/legacy/graph_store.py +0 -307
  127. cognite/neat/workflows/steps/lib/legacy/graph_transformer.py +0 -58
  128. cognite/neat/workflows/steps/lib/legacy/rules_exporter.py +0 -511
  129. cognite/neat/workflows/steps/lib/legacy/rules_importer.py +0 -612
  130. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/LICENSE +0 -0
  131. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/WHEEL +0 -0
  132. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/entry_points.txt +0 -0
@@ -1,58 +0,0 @@
1
- import logging
2
- import traceback
3
- from typing import cast
4
-
5
- from cognite.client import CogniteClient
6
- from cognite.client.data_classes import LabelDefinition, LabelDefinitionList
7
-
8
- from cognite.neat.legacy.rules.exporters._core import get_labels
9
- from cognite.neat.legacy.rules.models.rules import Rules
10
-
11
-
12
- def upload_labels(
13
- client: CogniteClient,
14
- rules: Rules,
15
- data_set_id: int,
16
- extra_labels: list | None = None,
17
- stop_on_exception: bool = False,
18
- ):
19
- """Generates labels from transformation rules and upload them to CDF
20
-
21
- Args:
22
- client : Instance of CogniteClient
23
- transformation_rules : Instance of TransformationRules which contains the labels to upload
24
- data_set_id : Id of the dataset to upload the labels to
25
- extra_labels : Any additional labels not defined in TransformationRules ,
26
- by default ["historic", "non-historic"]
27
- stop_on_exception : If this function fails to stop the process, by default False
28
- """
29
- if extra_labels is None:
30
- extra_labels = []
31
-
32
- try:
33
- logging.debug("Fetching existing labels from CDF")
34
- # This is to list all labels, not just the ones in the dataset since labels
35
- # must have unique external_ids, fixing issue that Daniel encountered
36
- if retrieved_labels := client.labels.list(limit=-1):
37
- existing_labels = set(retrieved_labels.to_pandas().external_id)
38
- else:
39
- existing_labels = set()
40
- logging.debug(f"Found {len(existing_labels)} existing labels in CDF")
41
- except Exception as e:
42
- logging.debug("Error fetching existing labels from CDF, no ")
43
- traceback.print_exc()
44
- if stop_on_exception:
45
- raise e
46
- existing_labels = set()
47
-
48
- non_existing_labels = set(list(get_labels(rules)) + extra_labels).difference(existing_labels)
49
-
50
- if non_existing_labels:
51
- logging.debug(f"Creating total of {len(existing_labels)} new labels in CDF")
52
- labels = [
53
- LabelDefinition(external_id=label, name=label, data_set_id=data_set_id) for label in non_existing_labels
54
- ]
55
- res = cast(LabelDefinitionList, client.labels.create(labels))
56
- logging.debug(f"Created total of {len(res)} new labels in CDF")
57
- else:
58
- logging.debug("No new labels created in CDF")
@@ -1,136 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import logging
4
- from typing import ClassVar
5
-
6
- from pydantic import BaseModel, ConfigDict, root_validator, validator
7
- from rdflib import Namespace
8
-
9
- from cognite.neat.legacy.rules.models.rules import METADATA_VALUE_MAX_LENGTH
10
-
11
-
12
- class AssetClassMapping(BaseModel):
13
- external_id: str
14
- name: str
15
- parent_external_id: str | None = None
16
- description: str | None = None
17
- metadata: dict | None = {}
18
-
19
- @root_validator(pre=True)
20
- def create_metadata(cls, values: dict):
21
- fields = values.keys()
22
-
23
- # adding metadata key in case if it is missing
24
- values["metadata"] = {} if "metadata" not in values else values["metadata"]
25
-
26
- for field in fields:
27
- if field not in ["external_id", "name", "parent_external_id", "data_set_id", "metadata", "description"]:
28
- values["metadata"][field] = ""
29
- return values
30
-
31
-
32
- class AssetTemplate(BaseModel):
33
- """This class is used to validate, repair and wrangle rdf asset dictionary according to the
34
- expected format of cognite sdk Asset dataclass."""
35
-
36
- external_id_prefix: str | None = None # convenience field to add prefix to external_ids
37
- external_id: str
38
- name: str | None = None
39
- parent_external_id: str | None = None
40
- metadata: dict | None = {}
41
- description: str | None = None
42
- data_set_id: int | None = None
43
-
44
- @root_validator(pre=True)
45
- def preprocess_fields(cls, values: dict):
46
- fields = values.keys()
47
-
48
- # Adding metadata key in case if it is missing
49
- values["metadata"] = {} if "metadata" not in values else values["metadata"]
50
-
51
- for field in fields:
52
- # Enrich: adding any field that is not in the list of expected fields to metadata
53
- if field not in [
54
- "external_id",
55
- "name",
56
- "parent_external_id",
57
- "data_set_id",
58
- "metadata",
59
- "description",
60
- "external_id_prefix",
61
- ]:
62
- values["metadata"][field] = values[field]
63
-
64
- # Repair: in case if name/description is list instead of single value list elements are joined
65
- elif field in ["name", "description"] and isinstance(values[field], list):
66
- msg = f"{values['type']} instance {values['identifier']} property {field} "
67
- msg += f"has multiple values {values[field]}, "
68
- msg += f"these values will be joined in a single string: {', '.join(values[field])}"
69
- logging.info(msg)
70
- values[field] = ", ".join(sorted(values[field]))[: METADATA_VALUE_MAX_LENGTH - 1]
71
-
72
- # Repair: in case if external_id or parent_external_id are lists, we take the first value
73
- elif field in ["external_id", "parent_external_id"] and isinstance(values[field], list):
74
- msg = f"{values['type']} instance {values['identifier']} property {field} "
75
- msg += f"has multiple values {values[field]}, "
76
- msg += f"only the first one will be used: {values[field][0]}"
77
- logging.info(msg)
78
- values[field] = values[field][0]
79
-
80
- # Setting asset to be by default active
81
- values["metadata"]["active"] = "true"
82
-
83
- # Handling case when the external_id is not provided by defaulting to the original identifier
84
- # The original identifier probably has its namespace removed
85
- if "external_id" not in fields and "identifier" in fields:
86
- values["external_id"] = values["identifier"]
87
-
88
- return values
89
-
90
- @validator("metadata")
91
- def to_list_if_comma(cls, value):
92
- for key, v in value.items():
93
- if isinstance(v, list):
94
- value[key] = ", ".join(sorted(v))[: METADATA_VALUE_MAX_LENGTH - 1]
95
- return value
96
-
97
- @validator("metadata")
98
- def to_str(cls, value):
99
- for key, v in value.items():
100
- value[key] = str(v)
101
- return value
102
-
103
- @validator("external_id", always=True)
104
- def add_prefix_to_external_id(cls, value, values):
105
- if values["external_id_prefix"]:
106
- return values["external_id_prefix"] + value
107
- else:
108
- return value
109
-
110
- @validator("parent_external_id")
111
- def add_prefix_to_parent_external_id(cls, value, values):
112
- if values["external_id_prefix"]:
113
- return values["external_id_prefix"] + value
114
- else:
115
- return value
116
-
117
-
118
- class RelationshipDefinition(BaseModel):
119
- source_class: str
120
- target_class: str
121
- property_: str
122
- labels: list[str] | None = None
123
- target_type: str = "Asset"
124
- source_type: str = "Asset"
125
- relationship_external_id_rule: str | None = None
126
-
127
-
128
- class RelationshipDefinitions(BaseModel):
129
- model_config: ClassVar[ConfigDict] = ConfigDict(
130
- populate_by_name=True, str_strip_whitespace=True, arbitrary_types_allowed=True, strict=False
131
- )
132
-
133
- data_set_id: int
134
- prefix: str
135
- namespace: Namespace
136
- relationships: dict[str, RelationshipDefinition]