cognite-neat 0.87.6__py3-none-any.whl → 0.88.1__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 (171) 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/configuration.py +1 -1
  5. cognite/neat/app/api/routers/crud.py +11 -21
  6. cognite/neat/app/api/routers/workflows.py +24 -94
  7. cognite/neat/app/ui/neat-app/build/asset-manifest.json +7 -7
  8. cognite/neat/app/ui/neat-app/build/index.html +1 -1
  9. cognite/neat/app/ui/neat-app/build/static/css/{main.38a62222.css → main.72e3d92e.css} +2 -2
  10. cognite/neat/app/ui/neat-app/build/static/css/main.72e3d92e.css.map +1 -0
  11. cognite/neat/app/ui/neat-app/build/static/js/main.5a52cf09.js +3 -0
  12. cognite/neat/app/ui/neat-app/build/static/js/{main.ec7f72e2.js.LICENSE.txt → main.5a52cf09.js.LICENSE.txt} +0 -9
  13. cognite/neat/app/ui/neat-app/build/static/js/main.5a52cf09.js.map +1 -0
  14. cognite/neat/config.py +44 -27
  15. cognite/neat/exceptions.py +6 -0
  16. cognite/neat/graph/extractors/_classic_cdf/_assets.py +21 -73
  17. cognite/neat/graph/extractors/_classic_cdf/_base.py +102 -0
  18. cognite/neat/graph/extractors/_classic_cdf/_events.py +46 -42
  19. cognite/neat/graph/extractors/_classic_cdf/_files.py +41 -45
  20. cognite/neat/graph/extractors/_classic_cdf/_labels.py +75 -52
  21. cognite/neat/graph/extractors/_classic_cdf/_relationships.py +49 -27
  22. cognite/neat/graph/extractors/_classic_cdf/_sequences.py +47 -50
  23. cognite/neat/graph/extractors/_classic_cdf/_timeseries.py +47 -49
  24. cognite/neat/graph/queries/_base.py +22 -29
  25. cognite/neat/graph/queries/_shared.py +1 -1
  26. cognite/neat/graph/stores/_base.py +24 -11
  27. cognite/neat/graph/transformers/_rdfpath.py +3 -2
  28. cognite/neat/issues.py +8 -0
  29. cognite/neat/rules/exporters/_rules2ontology.py +28 -20
  30. cognite/neat/rules/exporters/_validation.py +15 -21
  31. cognite/neat/rules/importers/_inference2rules.py +31 -35
  32. cognite/neat/rules/importers/_owl2rules/_owl2metadata.py +3 -7
  33. cognite/neat/rules/importers/_spreadsheet2rules.py +30 -27
  34. cognite/neat/rules/issues/dms.py +20 -0
  35. cognite/neat/rules/issues/importing.py +15 -0
  36. cognite/neat/rules/issues/ontology.py +298 -0
  37. cognite/neat/rules/issues/spreadsheet.py +48 -0
  38. cognite/neat/rules/issues/tables.py +72 -0
  39. cognite/neat/rules/models/_rdfpath.py +4 -4
  40. cognite/neat/rules/models/_types/_field.py +9 -19
  41. cognite/neat/rules/models/information/_rules.py +5 -4
  42. cognite/neat/utils/rdf_.py +17 -9
  43. cognite/neat/utils/regex_patterns.py +52 -0
  44. cognite/neat/workflows/steps/data_contracts.py +17 -43
  45. cognite/neat/workflows/steps/lib/current/graph_extractor.py +28 -24
  46. cognite/neat/workflows/steps/lib/current/graph_loader.py +4 -21
  47. cognite/neat/workflows/steps/lib/current/graph_store.py +18 -134
  48. cognite/neat/workflows/steps_registry.py +5 -7
  49. {cognite_neat-0.87.6.dist-info → cognite_neat-0.88.1.dist-info}/METADATA +2 -6
  50. cognite_neat-0.88.1.dist-info/RECORD +209 -0
  51. cognite/neat/app/api/routers/core.py +0 -91
  52. cognite/neat/app/api/routers/data_exploration.py +0 -336
  53. cognite/neat/app/api/routers/rules.py +0 -203
  54. cognite/neat/app/ui/neat-app/build/static/css/main.38a62222.css.map +0 -1
  55. cognite/neat/app/ui/neat-app/build/static/js/main.ec7f72e2.js +0 -3
  56. cognite/neat/app/ui/neat-app/build/static/js/main.ec7f72e2.js.map +0 -1
  57. cognite/neat/graph/stores/_oxrdflib.py +0 -247
  58. cognite/neat/legacy/__init__.py +0 -0
  59. cognite/neat/legacy/graph/__init__.py +0 -3
  60. cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -20182
  61. cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44.xml +0 -20163
  62. cognite/neat/legacy/graph/examples/__init__.py +0 -10
  63. cognite/neat/legacy/graph/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
  64. cognite/neat/legacy/graph/exceptions.py +0 -90
  65. cognite/neat/legacy/graph/extractors/__init__.py +0 -6
  66. cognite/neat/legacy/graph/extractors/_base.py +0 -14
  67. cognite/neat/legacy/graph/extractors/_dexpi.py +0 -44
  68. cognite/neat/legacy/graph/extractors/_graph_capturing_sheet.py +0 -403
  69. cognite/neat/legacy/graph/extractors/_mock_graph_generator.py +0 -361
  70. cognite/neat/legacy/graph/loaders/__init__.py +0 -23
  71. cognite/neat/legacy/graph/loaders/_asset_loader.py +0 -511
  72. cognite/neat/legacy/graph/loaders/_base.py +0 -67
  73. cognite/neat/legacy/graph/loaders/_exceptions.py +0 -85
  74. cognite/neat/legacy/graph/loaders/core/__init__.py +0 -0
  75. cognite/neat/legacy/graph/loaders/core/labels.py +0 -58
  76. cognite/neat/legacy/graph/loaders/core/models.py +0 -136
  77. cognite/neat/legacy/graph/loaders/core/rdf_to_assets.py +0 -1046
  78. cognite/neat/legacy/graph/loaders/core/rdf_to_relationships.py +0 -559
  79. cognite/neat/legacy/graph/loaders/rdf_to_dms.py +0 -309
  80. cognite/neat/legacy/graph/loaders/validator.py +0 -87
  81. cognite/neat/legacy/graph/models.py +0 -6
  82. cognite/neat/legacy/graph/stores/__init__.py +0 -13
  83. cognite/neat/legacy/graph/stores/_base.py +0 -400
  84. cognite/neat/legacy/graph/stores/_graphdb_store.py +0 -52
  85. cognite/neat/legacy/graph/stores/_memory_store.py +0 -43
  86. cognite/neat/legacy/graph/stores/_oxigraph_store.py +0 -151
  87. cognite/neat/legacy/graph/stores/_oxrdflib.py +0 -247
  88. cognite/neat/legacy/graph/stores/_rdf_to_graph.py +0 -42
  89. cognite/neat/legacy/graph/transformations/__init__.py +0 -0
  90. cognite/neat/legacy/graph/transformations/entity_matcher.py +0 -101
  91. cognite/neat/legacy/graph/transformations/query_generator/__init__.py +0 -3
  92. cognite/neat/legacy/graph/transformations/query_generator/sparql.py +0 -575
  93. cognite/neat/legacy/graph/transformations/transformer.py +0 -322
  94. cognite/neat/legacy/rules/__init__.py +0 -0
  95. cognite/neat/legacy/rules/analysis.py +0 -231
  96. cognite/neat/legacy/rules/examples/Rules-Nordic44-to-graphql.xlsx +0 -0
  97. cognite/neat/legacy/rules/examples/Rules-Nordic44.xlsx +0 -0
  98. cognite/neat/legacy/rules/examples/__init__.py +0 -18
  99. cognite/neat/legacy/rules/examples/power-grid-containers.yaml +0 -124
  100. cognite/neat/legacy/rules/examples/power-grid-example.xlsx +0 -0
  101. cognite/neat/legacy/rules/examples/power-grid-model.yaml +0 -224
  102. cognite/neat/legacy/rules/examples/rules-template.xlsx +0 -0
  103. cognite/neat/legacy/rules/examples/sheet2cdf-transformation-rules.xlsx +0 -0
  104. cognite/neat/legacy/rules/examples/skos-rules.xlsx +0 -0
  105. cognite/neat/legacy/rules/examples/source-to-solution-mapping-rules.xlsx +0 -0
  106. cognite/neat/legacy/rules/examples/wind-energy.owl +0 -1511
  107. cognite/neat/legacy/rules/exceptions.py +0 -2972
  108. cognite/neat/legacy/rules/exporters/__init__.py +0 -20
  109. cognite/neat/legacy/rules/exporters/_base.py +0 -45
  110. cognite/neat/legacy/rules/exporters/_core/__init__.py +0 -5
  111. cognite/neat/legacy/rules/exporters/_core/rules2labels.py +0 -24
  112. cognite/neat/legacy/rules/exporters/_rules2dms.py +0 -885
  113. cognite/neat/legacy/rules/exporters/_rules2excel.py +0 -213
  114. cognite/neat/legacy/rules/exporters/_rules2graphql.py +0 -183
  115. cognite/neat/legacy/rules/exporters/_rules2ontology.py +0 -524
  116. cognite/neat/legacy/rules/exporters/_rules2pydantic_models.py +0 -748
  117. cognite/neat/legacy/rules/exporters/_rules2rules.py +0 -105
  118. cognite/neat/legacy/rules/exporters/_rules2triples.py +0 -38
  119. cognite/neat/legacy/rules/exporters/_validation.py +0 -146
  120. cognite/neat/legacy/rules/importers/__init__.py +0 -22
  121. cognite/neat/legacy/rules/importers/_base.py +0 -66
  122. cognite/neat/legacy/rules/importers/_dict2rules.py +0 -158
  123. cognite/neat/legacy/rules/importers/_dms2rules.py +0 -194
  124. cognite/neat/legacy/rules/importers/_graph2rules.py +0 -308
  125. cognite/neat/legacy/rules/importers/_json2rules.py +0 -39
  126. cognite/neat/legacy/rules/importers/_owl2rules/__init__.py +0 -3
  127. cognite/neat/legacy/rules/importers/_owl2rules/_owl2classes.py +0 -239
  128. cognite/neat/legacy/rules/importers/_owl2rules/_owl2metadata.py +0 -260
  129. cognite/neat/legacy/rules/importers/_owl2rules/_owl2properties.py +0 -217
  130. cognite/neat/legacy/rules/importers/_owl2rules/_owl2rules.py +0 -290
  131. cognite/neat/legacy/rules/importers/_spreadsheet2rules.py +0 -45
  132. cognite/neat/legacy/rules/importers/_xsd2rules.py +0 -20
  133. cognite/neat/legacy/rules/importers/_yaml2rules.py +0 -39
  134. cognite/neat/legacy/rules/models/__init__.py +0 -5
  135. cognite/neat/legacy/rules/models/_base.py +0 -151
  136. cognite/neat/legacy/rules/models/raw_rules.py +0 -316
  137. cognite/neat/legacy/rules/models/rdfpath.py +0 -237
  138. cognite/neat/legacy/rules/models/rules.py +0 -1289
  139. cognite/neat/legacy/rules/models/tables.py +0 -9
  140. cognite/neat/legacy/rules/models/value_types.py +0 -118
  141. cognite/neat/legacy/workflows/examples/Export_DMS/workflow.yaml +0 -89
  142. cognite/neat/legacy/workflows/examples/Export_Rules_to_Ontology/workflow.yaml +0 -152
  143. cognite/neat/legacy/workflows/examples/Extract_DEXPI_Graph_and_Export_Rules/workflow.yaml +0 -139
  144. cognite/neat/legacy/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -270
  145. cognite/neat/legacy/workflows/examples/Import_DMS/workflow.yaml +0 -65
  146. cognite/neat/legacy/workflows/examples/Ontology_to_Data_Model/workflow.yaml +0 -116
  147. cognite/neat/legacy/workflows/examples/Validate_Rules/workflow.yaml +0 -67
  148. cognite/neat/legacy/workflows/examples/Validate_Solution_Model/workflow.yaml +0 -64
  149. cognite/neat/legacy/workflows/examples/Visualize_Data_Model_Using_Mock_Graph/workflow.yaml +0 -95
  150. cognite/neat/legacy/workflows/examples/Visualize_Semantic_Data_Model/workflow.yaml +0 -111
  151. cognite/neat/rules/exceptions.py +0 -2972
  152. cognite/neat/rules/models/_types/_base.py +0 -16
  153. cognite/neat/workflows/examples/Export_Rules_to_Ontology/workflow.yaml +0 -152
  154. cognite/neat/workflows/examples/Extract_DEXPI_Graph_and_Export_Rules/workflow.yaml +0 -139
  155. cognite/neat/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -270
  156. cognite/neat/workflows/examples/Ontology_to_Data_Model/workflow.yaml +0 -116
  157. cognite/neat/workflows/migration/__init__.py +0 -0
  158. cognite/neat/workflows/migration/steps.py +0 -91
  159. cognite/neat/workflows/migration/wf_manifests.py +0 -33
  160. cognite/neat/workflows/steps/lib/legacy/__init__.py +0 -7
  161. cognite/neat/workflows/steps/lib/legacy/graph_contextualization.py +0 -82
  162. cognite/neat/workflows/steps/lib/legacy/graph_extractor.py +0 -746
  163. cognite/neat/workflows/steps/lib/legacy/graph_loader.py +0 -606
  164. cognite/neat/workflows/steps/lib/legacy/graph_store.py +0 -307
  165. cognite/neat/workflows/steps/lib/legacy/graph_transformer.py +0 -58
  166. cognite/neat/workflows/steps/lib/legacy/rules_exporter.py +0 -511
  167. cognite/neat/workflows/steps/lib/legacy/rules_importer.py +0 -612
  168. cognite_neat-0.87.6.dist-info/RECORD +0 -319
  169. {cognite_neat-0.87.6.dist-info → cognite_neat-0.88.1.dist-info}/LICENSE +0 -0
  170. {cognite_neat-0.87.6.dist-info → cognite_neat-0.88.1.dist-info}/WHEEL +0 -0
  171. {cognite_neat-0.87.6.dist-info → cognite_neat-0.88.1.dist-info}/entry_points.txt +0 -0
@@ -1,511 +0,0 @@
1
- import logging
2
- import time
3
- import warnings
4
- from pathlib import Path
5
- from typing import ClassVar, Literal, cast
6
-
7
- from cognite.client import data_modeling as dm
8
-
9
- import cognite.neat.legacy.graph.extractors._graph_capturing_sheet
10
- from cognite.neat.exceptions import wrangle_warnings
11
- from cognite.neat.legacy.rules import exporters
12
- from cognite.neat.legacy.rules.exporters._rules2dms import DMSSchemaComponents
13
- from cognite.neat.legacy.rules.exporters._rules2graphql import GraphQLSchema
14
- from cognite.neat.legacy.rules.exporters._rules2ontology import Ontology
15
- from cognite.neat.utils.auxiliary import generate_exception_report
16
- from cognite.neat.workflows._exceptions import StepNotInitialized
17
- from cognite.neat.workflows.model import FlowMessage, StepExecutionStatus
18
- from cognite.neat.workflows.steps.data_contracts import CogniteClient, DMSSchemaComponentsData, RulesData
19
- from cognite.neat.workflows.steps.step_model import Configurable, Step
20
-
21
- __all__ = [
22
- "ExportDMSSchemaComponentsToYAML",
23
- "ExportDMSSchemaComponentsToCDF",
24
- "ExportRulesToGraphQLSchema",
25
- "ExportRulesToOntology",
26
- "ExportRulesToSHACL",
27
- "ExportRulesToGraphCapturingSheet",
28
- "ExportRulesToExcel",
29
- "GenerateDMSSchemaComponentsFromRules",
30
- "DeleteDMSSchemaComponents",
31
- ]
32
-
33
- CATEGORY = __name__.split(".")[-1].replace("_", " ").title() + " [LEGACY]"
34
-
35
-
36
- class GenerateDMSSchemaComponentsFromRules(Step):
37
- """
38
- This step generates DMS Schema components, such as data model, views, containers, etc. from Rules.
39
- """
40
-
41
- description = "This step generates DMS Schema components, such as data model, views, containers, etc. from Rules."
42
- version = "legacy"
43
- category = CATEGORY
44
-
45
- def run(self, rules: RulesData) -> (FlowMessage, DMSSchemaComponentsData): # type: ignore[override, syntax]
46
- data_model = DMSSchemaComponents.from_rules(rules.rules)
47
-
48
- output_text = (
49
- "DMS Schema Components Generated: "
50
- f"<li> - {len(data_model.spaces)} spaces</li>"
51
- f"<li> - {len(data_model.containers)} containers</li>"
52
- f"<li> - {len(data_model.views)} views</li>"
53
- f"</ul> which are referred in data model <b><code>{data_model.space}:{data_model.external_id}</code>"
54
- f"</b>/v=<b><code>{data_model.version}</code></b>"
55
- )
56
-
57
- # need to store the data model in the step so that it can be used by the next step
58
- # see GraphQL step
59
-
60
- return FlowMessage(output_text=output_text), DMSSchemaComponentsData(components=data_model)
61
-
62
-
63
- class ExportDMSSchemaComponentsToYAML(Step):
64
- """
65
- This step exports DMS schema components as YAML files
66
- """
67
-
68
- description = "This step exports DMS schema components as YAML files"
69
- version = "legacy"
70
- category = CATEGORY
71
- configurables: ClassVar[list[Configurable]] = [
72
- Configurable(
73
- name="format",
74
- value="yaml-dump",
75
- label="Format of the output files",
76
- options=["yaml-dump", "cognite-toolkit", "all"],
77
- ),
78
- ]
79
-
80
- def run(self, data_model_contract: DMSSchemaComponentsData) -> FlowMessage: # type: ignore[override, syntax]
81
- if self.configs is None or self.data_store_path is None:
82
- raise StepNotInitialized(type(self).__name__)
83
-
84
- format_ = self.configs["format"]
85
-
86
- staging_dir = self.config.staging_path
87
- staging_dir.mkdir(parents=True, exist_ok=True)
88
-
89
- if format_ in ["yaml-dump", "all"]:
90
- base_file_name = (
91
- f"{data_model_contract.components.space}-"
92
- f"{data_model_contract.components.external_id}-"
93
- f"v{data_model_contract.components.version.strip().replace('.', '_')}"
94
- )
95
-
96
- _container_file_name = f"{base_file_name}-containers.yaml"
97
- _data_model_file_name = f"{base_file_name}-data-model.yaml"
98
-
99
- container_full_path = staging_dir / _container_file_name
100
- data_model_full_path = staging_dir / _data_model_file_name
101
-
102
- data_model = dm.DataModelApply(
103
- space=data_model_contract.components.space,
104
- external_id=data_model_contract.components.external_id,
105
- version=data_model_contract.components.version,
106
- description=data_model_contract.components.description,
107
- name=data_model_contract.components.name,
108
- views=list(data_model_contract.components.views.values()),
109
- )
110
-
111
- containers = dm.ContainerApplyList(data_model_contract.components.containers.values())
112
-
113
- container_full_path.write_text(containers.dump_yaml())
114
- data_model_full_path.write_text(data_model.dump_yaml())
115
-
116
- output_text = (
117
- "<p></p>"
118
- "DMS Schema exported and can be downloaded here : "
119
- "<p></p>"
120
- f'- <a href="/data/{self.config.staging_path.name}/{_data_model_file_name}?{time.time()}" '
121
- f'target="_blank">{_data_model_file_name}</a>'
122
- "<p></p>"
123
- f'- <a href="/data/{self.config.staging_path.name}/{_container_file_name}?{time.time()}" '
124
- f'target="_blank">{_container_file_name}</a>'
125
- )
126
-
127
- return FlowMessage(output_text=output_text)
128
- else:
129
- return FlowMessage(
130
- error_text=f"Export format <b><code>{format_}</code></b> not implemented!",
131
- step_execution_status=StepExecutionStatus.ABORT_AND_FAIL,
132
- )
133
-
134
-
135
- class ExportDMSSchemaComponentsToCDF(Step):
136
- """
137
- This step exports generated DMS Schema components to CDF
138
- """
139
-
140
- description = "This step exports generated DMS Schema components to CDF."
141
- version = "legacy"
142
- category = CATEGORY
143
-
144
- configurables: ClassVar[list[Configurable]] = [
145
- Configurable(
146
- name="components",
147
- type="multi_select",
148
- value="",
149
- label="Select which DMS schema component(s) to export to CDF",
150
- options=["space", "container", "view", "data model"],
151
- ),
152
- Configurable(
153
- name="existing_component_handling",
154
- value="fail",
155
- label=(
156
- "How to handle situation when components being exported in CDF already exist."
157
- "Fail the step if any component already exists, "
158
- "Skip the component if it already exists, "
159
- " or Update the component try to update the component."
160
- ),
161
- options=["fail", "skip", "update"],
162
- ),
163
- Configurable(
164
- name="multi_space_components_create",
165
- value="False",
166
- label=(
167
- "Whether to create only components belonging to the data model space"
168
- " (i.e. space define under Metadata sheet of Rules), "
169
- "or also additionally components outside of the data model space."
170
- ),
171
- options=["True", "False"],
172
- ),
173
- ]
174
-
175
- def run(self, data_model: DMSSchemaComponentsData, cdf_client: CogniteClient) -> FlowMessage: # type: ignore[override, syntax]
176
- existing_component_handling: str = self.configs["existing_component_handling"]
177
- multi_space_components_create: bool = self.configs["multi_space_components_create"] == "True"
178
- components_to_create = {key for key, value in self.complex_configs["components"].items() if value}
179
-
180
- if not components_to_create:
181
- return FlowMessage(
182
- error_text="No DMS Schema components selected for upload! Please select minimum one!",
183
- step_execution_status=StepExecutionStatus.ABORT_AND_FAIL,
184
- )
185
-
186
- logs, errors = data_model.components.to_cdf(
187
- cdf_client,
188
- components_to_create=components_to_create,
189
- existing_component_handling=cast(Literal["skip"], existing_component_handling),
190
- multi_space_components_create=multi_space_components_create,
191
- return_report=True,
192
- )
193
-
194
- report = "# DMS Schema Components Export to CDF\n\n"
195
- for component, log in logs.items():
196
- if log:
197
- report += f"## {component.upper()}\n" + "\n".join(log) + "\n\n"
198
-
199
- report += "\n\n# ERRORS\n\n"
200
- for component, log in errors.items():
201
- if log:
202
- report += f"## {component.upper()}\n" + "\n".join(log) + "\n\n"
203
-
204
- # report
205
- report_file = "dms_component_creation_report.txt"
206
- report_dir = self.config.staging_path
207
- report_dir.mkdir(parents=True, exist_ok=True)
208
- report_full_path = report_dir / report_file
209
- report_full_path.write_text(report)
210
-
211
- output_text = (
212
- "<p></p>"
213
- "Download DMS Schema Components export "
214
- f'<a href="/data/staging/{report_file}?{time.time()}" '
215
- f'target="_blank">report</a>'
216
- )
217
-
218
- if any(value for value in errors.values()):
219
- return FlowMessage(error_text=output_text, step_execution_status=StepExecutionStatus.ABORT_AND_FAIL)
220
- else:
221
- return FlowMessage(output_text=output_text)
222
-
223
-
224
- class DeleteDMSSchemaComponents(Step):
225
- """
226
- This step deletes DMS Schema components
227
- """
228
-
229
- description = "This step deletes DMS Data model and all underlying containers and views."
230
- version = "legacy"
231
- category = CATEGORY
232
-
233
- configurables: ClassVar[list[Configurable]] = [
234
- Configurable(
235
- name="components",
236
- type="multi_select",
237
- value="",
238
- label="Select which DMS schema component(s) to delete",
239
- options=["space", "container", "view", "data model"],
240
- ),
241
- Configurable(
242
- name="multi_space_components_removal",
243
- value="False",
244
- label=(
245
- "False (default) = Only delete components inside the space referred"
246
- " in Metadata Sheet of Rules"
247
- r", True = Delete all components referred to in Rules<\p>"
248
- ),
249
- options=["True", "False"],
250
- ),
251
- ]
252
-
253
- def run(self, data_model: DMSSchemaComponentsData, cdf_client: CogniteClient) -> FlowMessage: # type: ignore[override, syntax]
254
- components_to_remove = {key for key, value in self.complex_configs["components"].items() if value}
255
- multi_space_components_removal: bool = self.configs["multi_space_components_removal"] == "True"
256
- if not components_to_remove:
257
- return FlowMessage(
258
- error_text="No DMS Schema components selected for deletion! Please select minimum one!",
259
- step_execution_status=StepExecutionStatus.ABORT_AND_FAIL,
260
- )
261
-
262
- logs, errors = data_model.components.remove(
263
- cdf_client,
264
- components_to_remove=components_to_remove,
265
- multi_space_components_removal=multi_space_components_removal,
266
- return_report=True,
267
- )
268
-
269
- report = "# DMS Schema Components Removal from CDF\n\n"
270
- for component, log in logs.items():
271
- if log:
272
- report += f"## {component.upper()}\n" + "\n".join(log) + "\n\n"
273
-
274
- report += "\n\n# ERRORS\n\n"
275
- for component, log in errors.items():
276
- if log:
277
- report += f"## {component.upper()}\n" + "\n".join(log) + "\n\n"
278
-
279
- # report
280
- report_file = "dms_component_removal_report.txt"
281
- report_dir = self.config.staging_path
282
- report_dir.mkdir(parents=True, exist_ok=True)
283
- report_full_path = report_dir / report_file
284
- report_full_path.write_text(report)
285
-
286
- output_text = (
287
- "<p></p>"
288
- "Download DMS Schema Components removal "
289
- f'<a href="/data/staging/{report_file}?{time.time()}" '
290
- f'target="_blank">report</a>'
291
- )
292
-
293
- if any(value for value in errors.values()):
294
- return FlowMessage(error_text=output_text, step_execution_status=StepExecutionStatus.ABORT_AND_FAIL)
295
- else:
296
- return FlowMessage(output_text=output_text)
297
-
298
-
299
- class ExportRulesToGraphQLSchema(Step):
300
- """
301
- This step generates GraphQL schema from data model defined in transformation rules
302
- """
303
-
304
- description = "This step generates GraphQL schema from data model defined in transformation rules."
305
- version = "legacy"
306
- category = CATEGORY
307
- configurables: ClassVar[list[Configurable]] = [
308
- Configurable(
309
- name="file_name",
310
- value="",
311
- label=(
312
- "Name of the GraphQL schema file it must have .graphql extension,"
313
- " if empty defaults to form `prefix-version.graphql`"
314
- ),
315
- ),
316
- Configurable(name="storage_dir", value="staging", label="Directory to store GraphQL schema file"),
317
- ]
318
-
319
- def run(self, transformation_rules: RulesData) -> FlowMessage: # type: ignore[override, syntax]
320
- if self.configs is None or self.data_store_path is None:
321
- raise StepNotInitialized(type(self).__name__)
322
- data_model_gql = GraphQLSchema.from_rules(transformation_rules.rules, verbose=True).schema
323
-
324
- default_name = (
325
- f"{transformation_rules.rules.metadata.prefix}-"
326
- f"v{transformation_rules.rules.metadata.version.strip().replace('.', '_')}"
327
- ".graphql"
328
- )
329
-
330
- schema_name = self.configs["file_name"] or default_name
331
-
332
- staging_dir_str = self.configs["storage_dir"]
333
- staging_dir = self.data_store_path / Path(staging_dir_str)
334
- staging_dir.mkdir(parents=True, exist_ok=True)
335
- fdm_model_full_path = staging_dir / schema_name
336
-
337
- fdm_model_full_path.write_text(data_model_gql)
338
-
339
- output_text = (
340
- "<p></p>"
341
- "GraphQL Schema generated and can be downloaded here : "
342
- f'<a href="/data/{staging_dir_str}/{schema_name}?{time.time()}" '
343
- f'target="_blank">{schema_name}</a>'
344
- )
345
-
346
- return FlowMessage(output_text=output_text)
347
-
348
-
349
- class ExportRulesToOntology(Step):
350
- """
351
- This step exports Rules to OWL ontology
352
- """
353
-
354
- description = "This step exports Rules to OWL ontology"
355
- version = "legacy"
356
- category = CATEGORY
357
- configurables: ClassVar[list[Configurable]] = [
358
- Configurable(
359
- name="ontology_file_path",
360
- value="staging/ontology.ttl",
361
- label=(
362
- "Relative path for the ontology file storage, "
363
- "must end with .ttl ! Will be auto-created if not provided !"
364
- ),
365
- )
366
- ]
367
-
368
- def run(self, rules: RulesData) -> FlowMessage: # type: ignore[override, syntax]
369
- if self.configs is None or self.data_store_path is None:
370
- raise StepNotInitialized(type(self).__name__)
371
-
372
- # ontology file
373
- default_path = self.data_store_path / Path(
374
- f"{rules.rules.metadata.prefix}-"
375
- f"v{rules.rules.metadata.version.strip().replace('.', '_')}"
376
- "-ontology.ttl"
377
- )
378
-
379
- if not self.configs["ontology_file_path"]:
380
- storage_path = default_path
381
- else:
382
- storage_path = self.data_store_path / Path(self.configs["ontology_file_path"])
383
-
384
- storage_path.parent.mkdir(parents=True, exist_ok=True)
385
- report_file_path = storage_path.parent / f"report_{storage_path.stem}.txt"
386
-
387
- with warnings.catch_warnings(record=True) as validation_warnings:
388
- ontology = Ontology.from_rules(rules=rules.rules)
389
-
390
- storage_path.write_text(ontology.ontology)
391
- report_file_path.write_text(generate_exception_report(wrangle_warnings(validation_warnings), "Warnings"))
392
-
393
- relative_ontology_file_path = str(storage_path).split("/data/")[1]
394
-
395
- output_text = (
396
- "<p></p>"
397
- "Rules exported to ontology can be downloaded here : "
398
- f'<a href="/data/{relative_ontology_file_path}?{time.time()}" '
399
- f'target="_blank">{storage_path.stem}.ttl</a>'
400
- )
401
-
402
- return FlowMessage(output_text=output_text)
403
-
404
-
405
- class ExportRulesToSHACL(Step):
406
- """
407
- This step exports Rules to SHACL
408
- """
409
-
410
- description = "This step exports Rules to SHACL"
411
- version = "legacy"
412
- category = CATEGORY
413
- configurables: ClassVar[list[Configurable]] = [
414
- Configurable(
415
- name="shacl_file_path",
416
- value="staging/shacl.ttl",
417
- label=(
418
- "Relative path for the SHACL file storage, "
419
- "must end with .ttl ! Will be auto-created if not provided !"
420
- ),
421
- )
422
- ]
423
-
424
- def run(self, rules: RulesData) -> FlowMessage: # type: ignore[override, syntax]
425
- if self.configs is None or self.data_store_path is None:
426
- raise StepNotInitialized(type(self).__name__)
427
-
428
- # ontology file
429
- default_path = self.data_store_path / Path(
430
- f"{rules.rules.metadata.prefix}-" f"v{rules.rules.metadata.version.strip().replace('.', '_')}" "-shacl.ttl"
431
- )
432
-
433
- if not self.configs["shacl_file_path"]:
434
- storage_path = default_path
435
- else:
436
- storage_path = self.data_store_path / Path(self.configs["shacl_file_path"])
437
- report_file_path = storage_path.parent / f"report_{storage_path.stem}.txt"
438
-
439
- with warnings.catch_warnings(record=True) as validation_warnings:
440
- ontology = Ontology.from_rules(rules=rules.rules)
441
-
442
- storage_path.parent.mkdir(parents=True, exist_ok=True)
443
- storage_path.write_text(ontology.constraints)
444
- report_file_path.write_text(generate_exception_report(wrangle_warnings(validation_warnings), "Warnings"))
445
-
446
- relative_shacl_file_path = str(storage_path).split("/data/")[1]
447
-
448
- output_text = (
449
- "<p></p>"
450
- "Rules exported to ontology can be downloaded here : "
451
- f'<a href="/data/{relative_shacl_file_path}?{time.time()}" '
452
- f'target="_blank">{storage_path.stem}.ttl</a>'
453
- )
454
-
455
- return FlowMessage(output_text=output_text)
456
-
457
-
458
- class ExportRulesToGraphCapturingSheet(Step):
459
- """
460
- This step generates graph capturing sheet
461
- """
462
-
463
- description = "This step generates graph capturing sheet"
464
- version = "legacy"
465
- category = CATEGORY
466
- configurables: ClassVar[list[Configurable]] = [
467
- Configurable(name="file_name", value="graph_capture_sheet.xlsx", label="File name of the data capture sheet"),
468
- Configurable(name="auto_identifier_type", value="index-based", label="Type of automatic identifier"),
469
- Configurable(name="storage_dir", value="staging", label="Directory to store data capture sheets"),
470
- ]
471
-
472
- def run(self, rules: RulesData) -> FlowMessage: # type: ignore[override, syntax]
473
- if self.configs is None or self.data_store_path is None:
474
- raise StepNotInitialized(type(self).__name__)
475
- logging.info("Generate graph capture sheet")
476
- sheet_name = self.configs["file_name"]
477
- auto_identifier_type = self.configs["auto_identifier_type"]
478
- staging_dir_str = self.configs["storage_dir"]
479
- logging.info(f"Auto identifier type {auto_identifier_type}")
480
- staging_dir = self.data_store_path / Path(staging_dir_str)
481
-
482
- staging_dir.mkdir(parents=True, exist_ok=True)
483
-
484
- data_capture_sheet_path = staging_dir / sheet_name
485
-
486
- cognite.neat.legacy.graph.extractors._graph_capturing_sheet.rules2graph_capturing_sheet(
487
- rules.rules, data_capture_sheet_path, auto_identifier_type=auto_identifier_type
488
- )
489
-
490
- output_text = (
491
- "Data capture sheet generated and can be downloaded here : "
492
- f'<a href="/data/{staging_dir_str}/{sheet_name}?{time.time()}" target="_blank">'
493
- f"{sheet_name}</a>"
494
- )
495
- return FlowMessage(output_text=output_text)
496
-
497
-
498
- class ExportRulesToExcel(Step):
499
- description = "This step export Rules to Excel representation"
500
- version = "legacy"
501
- category = CATEGORY
502
- configurables: ClassVar[list[Configurable]] = [
503
- Configurable(
504
- name="output_file_path", value="rules/custom-rules.xlsx", label="File path to the generated Excel file"
505
- )
506
- ]
507
-
508
- def run(self, rules_data: RulesData) -> FlowMessage: # type: ignore[override, syntax]
509
- full_path = Path(self.data_store_path) / Path(self.configs["output_file_path"])
510
- exporters.ExcelExporter.from_rules(rules=rules_data.rules).export_to_file(filepath=full_path)
511
- return FlowMessage(output_text="Generated Excel file from rules")