cognite-neat 0.92.2__py3-none-any.whl → 0.93.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/__init__.py +3 -2
- cognite/neat/{app → _app}/api/configuration.py +9 -7
- cognite/neat/_app/api/context_manager/__init__.py +3 -0
- cognite/neat/{app → _app}/api/context_manager/manager.py +1 -1
- cognite/neat/{app → _app}/api/explorer.py +5 -5
- cognite/neat/{app → _app}/api/routers/configuration.py +2 -2
- cognite/neat/{app → _app}/api/routers/crud.py +4 -4
- cognite/neat/{app → _app}/api/routers/workflows.py +7 -7
- cognite/neat/{app → _app}/main.py +1 -1
- cognite/neat/_app/ui/neat-app/package-lock.json +18306 -0
- cognite/neat/_app/ui/neat-app/package.json +62 -0
- cognite/neat/_app/ui/neat-app/public/favicon.ico +0 -0
- cognite/neat/_app/ui/neat-app/public/img/architect-icon.svg +116 -0
- cognite/neat/_app/ui/neat-app/public/img/developer-icon.svg +112 -0
- cognite/neat/_app/ui/neat-app/public/img/sme-icon.svg +34 -0
- cognite/neat/_app/ui/neat-app/public/index.html +43 -0
- cognite/neat/_app/ui/neat-app/public/logo192.png +0 -0
- cognite/neat/_app/ui/neat-app/public/manifest.json +25 -0
- cognite/neat/_app/ui/neat-app/public/robots.txt +3 -0
- cognite/neat/_app/ui/neat-app/src/App.css +38 -0
- cognite/neat/_app/ui/neat-app/src/App.js +17 -0
- cognite/neat/_app/ui/neat-app/src/App.test.js +8 -0
- cognite/neat/_app/ui/neat-app/src/MainContainer.tsx +70 -0
- cognite/neat/_app/ui/neat-app/src/components/JsonViewer.tsx +43 -0
- cognite/neat/_app/ui/neat-app/src/components/LocalUploader.tsx +124 -0
- cognite/neat/_app/ui/neat-app/src/components/OverviewComponentEditorDialog.tsx +63 -0
- cognite/neat/_app/ui/neat-app/src/components/StepEditorDialog.tsx +511 -0
- cognite/neat/_app/ui/neat-app/src/components/TabPanel.tsx +36 -0
- cognite/neat/_app/ui/neat-app/src/components/Utils.tsx +56 -0
- cognite/neat/_app/ui/neat-app/src/components/WorkflowDeleteDialog.tsx +60 -0
- cognite/neat/_app/ui/neat-app/src/components/WorkflowExecutionReport.tsx +112 -0
- cognite/neat/_app/ui/neat-app/src/components/WorkflowImportExportDialog.tsx +67 -0
- cognite/neat/_app/ui/neat-app/src/components/WorkflowMetadataDialog.tsx +79 -0
- cognite/neat/_app/ui/neat-app/src/index.css +13 -0
- cognite/neat/_app/ui/neat-app/src/index.js +13 -0
- cognite/neat/_app/ui/neat-app/src/logo.svg +1 -0
- cognite/neat/_app/ui/neat-app/src/reportWebVitals.js +13 -0
- cognite/neat/_app/ui/neat-app/src/setupTests.js +5 -0
- cognite/neat/_app/ui/neat-app/src/types/WorkflowTypes.ts +388 -0
- cognite/neat/_app/ui/neat-app/src/views/AboutView.tsx +61 -0
- cognite/neat/_app/ui/neat-app/src/views/ConfigView.tsx +184 -0
- cognite/neat/_app/ui/neat-app/src/views/GlobalConfigView.tsx +180 -0
- cognite/neat/_app/ui/neat-app/src/views/WorkflowView.tsx +570 -0
- cognite/neat/_app/ui/neat-app/tsconfig.json +27 -0
- cognite/neat/{config.py → _config.py} +3 -3
- cognite/neat/{constants.py → _constants.py} +13 -5
- cognite/neat/_graph/_shared.py +34 -0
- cognite/neat/{graph → _graph}/_tracking/base.py +1 -1
- cognite/neat/{graph → _graph}/_tracking/log.py +1 -1
- cognite/neat/{graph → _graph}/extractors/__init__.py +5 -0
- cognite/neat/{graph → _graph}/extractors/_base.py +2 -2
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_assets.py +1 -1
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_base.py +4 -4
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_classic.py +5 -5
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_data_sets.py +1 -1
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_events.py +1 -1
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_files.py +1 -1
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_labels.py +1 -1
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_relationships.py +2 -2
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_sequences.py +1 -1
- cognite/neat/{graph → _graph}/extractors/_classic_cdf/_timeseries.py +1 -1
- cognite/neat/{graph → _graph}/extractors/_dexpi.py +5 -5
- cognite/neat/{graph → _graph}/extractors/_dms.py +3 -3
- cognite/neat/_graph/extractors/_iodd.py +402 -0
- cognite/neat/{graph → _graph}/extractors/_mock_graph_generator.py +9 -8
- cognite/neat/_graph/extractors/_rdf_file.py +49 -0
- cognite/neat/{graph → _graph}/loaders/_base.py +5 -5
- cognite/neat/{graph → _graph}/loaders/_rdf2asset.py +11 -10
- cognite/neat/{graph → _graph}/loaders/_rdf2dms.py +10 -10
- cognite/neat/{graph → _graph}/queries/_base.py +91 -19
- cognite/neat/{graph → _graph}/queries/_construct.py +5 -5
- cognite/neat/{graph → _graph}/queries/_shared.py +3 -3
- cognite/neat/{graph → _graph}/transformers/__init__.py +6 -0
- cognite/neat/{graph → _graph}/transformers/_classic_cdf.py +135 -3
- cognite/neat/_graph/transformers/_iodd.py +25 -0
- cognite/neat/_graph/transformers/_prune_graph.py +126 -0
- cognite/neat/{graph → _graph}/transformers/_rdfpath.py +3 -3
- cognite/neat/_graph/transformers/_value_type.py +66 -0
- cognite/neat/{issues → _issues}/_base.py +32 -17
- cognite/neat/{issues → _issues}/errors/__init__.py +1 -1
- cognite/neat/{issues → _issues}/errors/_external.py +8 -8
- cognite/neat/{issues → _issues}/errors/_general.py +5 -5
- cognite/neat/{issues → _issues}/errors/_properties.py +7 -7
- cognite/neat/{issues → _issues}/errors/_resources.py +11 -11
- cognite/neat/{issues → _issues}/errors/_workflow.py +5 -5
- cognite/neat/{issues → _issues}/warnings/__init__.py +1 -1
- cognite/neat/{issues → _issues}/warnings/_external.py +5 -5
- cognite/neat/{issues → _issues}/warnings/_general.py +4 -4
- cognite/neat/{issues → _issues}/warnings/_models.py +10 -10
- cognite/neat/{issues → _issues}/warnings/_properties.py +6 -6
- cognite/neat/{issues → _issues}/warnings/_resources.py +5 -5
- cognite/neat/{issues → _issues}/warnings/user_modeling.py +9 -9
- cognite/neat/_rules/_constants.py +190 -0
- cognite/neat/{rules → _rules}/_shared.py +5 -5
- cognite/neat/_rules/analysis/__init__.py +5 -0
- cognite/neat/{rules → _rules}/analysis/_asset.py +5 -5
- cognite/neat/{rules → _rules}/analysis/_base.py +5 -5
- cognite/neat/_rules/analysis/_dms.py +43 -0
- cognite/neat/{rules → _rules}/analysis/_information.py +12 -6
- cognite/neat/_rules/catalog/__init__.py +6 -0
- cognite/neat/_rules/catalog/info-rules-imf.xlsx +0 -0
- cognite/neat/{rules → _rules}/exporters/__init__.py +2 -0
- cognite/neat/{rules → _rules}/exporters/_base.py +3 -3
- cognite/neat/{rules → _rules}/exporters/_rules2dms.py +5 -5
- cognite/neat/{rules → _rules}/exporters/_rules2excel.py +26 -7
- cognite/neat/_rules/exporters/_rules2instance_template.py +152 -0
- cognite/neat/{rules → _rules}/exporters/_rules2ontology.py +10 -9
- cognite/neat/{rules → _rules}/exporters/_rules2yaml.py +1 -3
- cognite/neat/{rules → _rules}/exporters/_validation.py +2 -2
- cognite/neat/{rules → _rules}/importers/_base.py +3 -3
- cognite/neat/{rules → _rules}/importers/_dms2rules.py +9 -9
- cognite/neat/{rules → _rules}/importers/_dtdl2rules/dtdl_converter.py +7 -7
- cognite/neat/{rules → _rules}/importers/_dtdl2rules/dtdl_importer.py +9 -9
- cognite/neat/{rules → _rules}/importers/_dtdl2rules/spec.py +1 -1
- cognite/neat/_rules/importers/_rdf/_base.py +144 -0
- cognite/neat/{rules → _rules}/importers/_rdf/_imf2rules/_imf2classes.py +1 -1
- cognite/neat/{rules → _rules}/importers/_rdf/_imf2rules/_imf2metadata.py +4 -4
- cognite/neat/{rules → _rules}/importers/_rdf/_imf2rules/_imf2properties.py +2 -1
- cognite/neat/{rules → _rules}/importers/_rdf/_imf2rules/_imf2rules.py +8 -39
- cognite/neat/{rules → _rules}/importers/_rdf/_inference2rules.py +33 -106
- cognite/neat/{rules → _rules}/importers/_rdf/_owl2rules/_owl2classes.py +1 -1
- cognite/neat/{rules → _rules}/importers/_rdf/_owl2rules/_owl2metadata.py +5 -5
- cognite/neat/{rules → _rules}/importers/_rdf/_owl2rules/_owl2properties.py +1 -1
- cognite/neat/_rules/importers/_rdf/_owl2rules/_owl2rules.py +39 -0
- cognite/neat/{rules → _rules}/importers/_rdf/_shared.py +4 -4
- cognite/neat/{rules → _rules}/importers/_spreadsheet2rules.py +40 -6
- cognite/neat/{rules → _rules}/importers/_yaml2rules.py +5 -5
- cognite/neat/{rules → _rules}/models/__init__.py +5 -5
- cognite/neat/{rules → _rules}/models/_base_input.py +30 -11
- cognite/neat/{rules → _rules}/models/_base_rules.py +22 -8
- cognite/neat/{rules → _rules}/models/_rdfpath.py +1 -1
- cognite/neat/_rules/models/_types.py +151 -0
- cognite/neat/{rules → _rules}/models/asset/_rules.py +4 -4
- cognite/neat/{rules → _rules}/models/asset/_rules_input.py +4 -4
- cognite/neat/{rules → _rules}/models/asset/_validation.py +7 -7
- cognite/neat/{rules → _rules}/models/data_types.py +15 -12
- cognite/neat/{rules → _rules}/models/dms/_exporter.py +60 -12
- cognite/neat/{rules → _rules}/models/dms/_rules.py +29 -26
- cognite/neat/{rules → _rules}/models/dms/_rules_input.py +4 -4
- cognite/neat/{rules → _rules}/models/dms/_schema.py +15 -14
- cognite/neat/{rules → _rules}/models/dms/_validation.py +8 -8
- cognite/neat/{rules → _rules}/models/domain.py +6 -6
- cognite/neat/{rules → _rules}/models/entities/__init__.py +1 -2
- cognite/neat/_rules/models/entities/_constants.py +15 -0
- cognite/neat/{rules → _rules}/models/entities/_loaders.py +2 -2
- cognite/neat/{rules → _rules}/models/entities/_multi_value.py +15 -2
- cognite/neat/{rules → _rules}/models/entities/_single_value.py +16 -4
- cognite/neat/{rules → _rules}/models/information/_rules.py +37 -25
- cognite/neat/{rules → _rules}/models/information/_rules_input.py +3 -3
- cognite/neat/{rules → _rules}/models/information/_validation.py +6 -5
- cognite/neat/_rules/models/mapping/__init__.py +4 -0
- cognite/neat/_rules/models/mapping/_base.py +131 -0
- cognite/neat/_rules/models/mapping/_classic2core.py +150 -0
- cognite/neat/{rules → _rules}/transformers/__init__.py +15 -2
- cognite/neat/{rules → _rules}/transformers/_base.py +3 -3
- cognite/neat/{rules → _rules}/transformers/_converters.py +289 -20
- cognite/neat/{rules/transformers/_map_onto.py → _rules/transformers/_mapping.py} +46 -4
- cognite/neat/{rules → _rules}/transformers/_pipelines.py +4 -4
- cognite/neat/{rules → _rules}/transformers/_verification.py +10 -4
- cognite/neat/_session/__init__.py +3 -0
- cognite/neat/_session/_base.py +86 -0
- cognite/neat/_session/_prepare.py +61 -0
- cognite/neat/_session/_read.py +118 -0
- cognite/neat/_session/_show.py +96 -0
- cognite/neat/_session/_state.py +69 -0
- cognite/neat/_session/_to.py +70 -0
- cognite/neat/_session/_wizard.py +39 -0
- cognite/neat/_session/exceptions.py +42 -0
- cognite/neat/{store → _store}/_base.py +63 -32
- cognite/neat/{store → _store}/_provenance.py +11 -1
- cognite/neat/{utils → _utils}/auth.py +14 -3
- cognite/neat/{utils → _utils}/auxiliary.py +1 -1
- cognite/neat/{utils → _utils}/cdf/loaders/_data_modeling.py +8 -2
- cognite/neat/{utils → _utils}/cdf/loaders/_ingestion.py +1 -1
- cognite/neat/{utils → _utils}/upload.py +1 -1
- cognite/neat/_version.py +1 -1
- cognite/neat/_workflows/__init__.py +17 -0
- cognite/neat/{workflows → _workflows}/base.py +10 -10
- cognite/neat/{workflows → _workflows}/cdf_store.py +3 -3
- cognite/neat/{workflows → _workflows}/examples/Export_DMS/workflow.yaml +89 -89
- cognite/neat/{workflows → _workflows}/manager.py +6 -6
- cognite/neat/{workflows → _workflows}/steps/data_contracts.py +3 -3
- cognite/neat/{workflows → _workflows}/steps/lib/current/graph_extractor.py +8 -31
- cognite/neat/{workflows → _workflows}/steps/lib/current/graph_loader.py +4 -4
- cognite/neat/{workflows → _workflows}/steps/lib/current/graph_store.py +4 -4
- cognite/neat/{workflows → _workflows}/steps/lib/current/rules_exporter.py +8 -8
- cognite/neat/{workflows → _workflows}/steps/lib/current/rules_importer.py +13 -13
- cognite/neat/{workflows → _workflows}/steps/lib/current/rules_validator.py +8 -8
- cognite/neat/{workflows → _workflows}/steps/lib/io/io_steps.py +3 -3
- cognite/neat/{workflows → _workflows}/steps/step_model.py +3 -3
- cognite/neat/{workflows → _workflows}/steps_registry.py +9 -9
- cognite/neat/{workflows → _workflows}/tasks.py +1 -1
- cognite/neat/{workflows → _workflows}/triggers.py +2 -2
- {cognite_neat-0.92.2.dist-info → cognite_neat-0.93.0.dist-info}/METADATA +6 -2
- cognite_neat-0.93.0.dist-info/RECORD +276 -0
- {cognite_neat-0.92.2.dist-info → cognite_neat-0.93.0.dist-info}/WHEEL +1 -1
- cognite_neat-0.93.0.dist-info/entry_points.txt +3 -0
- cognite/neat/app/api/context_manager/__init__.py +0 -3
- cognite/neat/graph/_shared.py +0 -5
- cognite/neat/graph/extractors/_iodd.py +0 -160
- cognite/neat/graph/extractors/_rdf_file.py +0 -26
- cognite/neat/rules/analysis/__init__.py +0 -6
- cognite/neat/rules/examples/__init__.py +0 -10
- cognite/neat/rules/examples/info-rules-imf.xlsx +0 -0
- cognite/neat/rules/examples/wind-energy.owl +0 -1511
- cognite/neat/rules/importers/_rdf/_owl2rules/_owl2rules.py +0 -65
- cognite/neat/rules/models/_types.py +0 -96
- cognite/neat/rules/models/entities/_constants.py +0 -73
- cognite/neat/utils/regex_patterns.py +0 -58
- cognite/neat/workflows/__init__.py +0 -12
- cognite_neat-0.92.2.dist-info/RECORD +0 -224
- cognite_neat-0.92.2.dist-info/entry_points.txt +0 -3
- /cognite/neat/{app → _app}/api/__init__.py +0 -0
- /cognite/neat/{app → _app}/api/asgi/metrics.py +0 -0
- /cognite/neat/{app → _app}/api/data_classes/__init__.py +0 -0
- /cognite/neat/{app → _app}/api/data_classes/rest.py +0 -0
- /cognite/neat/{app → _app}/api/routers/metrics.py +0 -0
- /cognite/neat/{app → _app}/api/utils/__init__.py +0 -0
- /cognite/neat/{app → _app}/api/utils/data_mapping.py +0 -0
- /cognite/neat/{app → _app}/api/utils/logging.py +0 -0
- /cognite/neat/{app → _app}/api/utils/query_templates.py +0 -0
- /cognite/neat/{app → _app}/monitoring/__init__.py +0 -0
- /cognite/neat/{app → _app}/monitoring/metrics.py +0 -0
- /cognite/neat/{app → _app}/ui/index.html +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/.gitignore +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/README.md +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/asset-manifest.json +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/favicon.ico +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/img/architect-icon.svg +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/img/developer-icon.svg +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/img/sme-icon.svg +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/index.html +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/logo192.png +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/manifest.json +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/robots.txt +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/static/css/main.72e3d92e.css +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/static/css/main.72e3d92e.css.map +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/static/js/main.5a52cf09.js +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/static/js/main.5a52cf09.js.LICENSE.txt +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/static/js/main.5a52cf09.js.map +0 -0
- /cognite/neat/{app → _app}/ui/neat-app/build/static/media/logo.8093b84df9ed36a174c629d6fe0b730d.svg +0 -0
- /cognite/neat/{graph → _graph}/__init__.py +0 -0
- /cognite/neat/{graph → _graph}/_tracking/__init__.py +0 -0
- /cognite/neat/{graph → _graph}/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -0
- /cognite/neat/{graph → _graph}/examples/Knowledge-Graph-Nordic44.xml +0 -0
- /cognite/neat/{graph → _graph}/examples/__init__.py +0 -0
- /cognite/neat/{graph → _graph}/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
- /cognite/neat/{graph → _graph}/extractors/_classic_cdf/__init__.py +0 -0
- /cognite/neat/{graph → _graph}/loaders/__init__.py +0 -0
- /cognite/neat/{graph → _graph}/models.py +0 -0
- /cognite/neat/{graph → _graph}/queries/__init__.py +0 -0
- /cognite/neat/{graph → _graph}/transformers/_base.py +0 -0
- /cognite/neat/{issues → _issues}/__init__.py +0 -0
- /cognite/neat/{issues → _issues}/formatters.py +0 -0
- /cognite/neat/{rules → _rules}/__init__.py +0 -0
- /cognite/neat/{rules → _rules}/importers/__init__.py +0 -0
- /cognite/neat/{rules → _rules}/importers/_dtdl2rules/__init__.py +0 -0
- /cognite/neat/{rules → _rules}/importers/_dtdl2rules/_unit_lookup.py +0 -0
- /cognite/neat/{rules → _rules}/importers/_rdf/__init__.py +0 -0
- /cognite/neat/{rules → _rules}/importers/_rdf/_imf2rules/__init__.py +0 -0
- /cognite/neat/{rules → _rules}/importers/_rdf/_owl2rules/__init__.py +0 -0
- /cognite/neat/{rules → _rules}/models/asset/__init__.py +0 -0
- /cognite/neat/{rules → _rules}/models/dms/__init__.py +0 -0
- /cognite/neat/{rules → _rules}/models/entities/_types.py +0 -0
- /cognite/neat/{rules → _rules}/models/entities/_wrapped.py +0 -0
- /cognite/neat/{rules → _rules}/models/information/__init__.py +0 -0
- /cognite/neat/{store → _store}/__init__.py +0 -0
- /cognite/neat/{utils → _utils}/__init__.py +0 -0
- /cognite/neat/{utils → _utils}/cdf/__init__.py +0 -0
- /cognite/neat/{utils → _utils}/cdf/data_classes.py +0 -0
- /cognite/neat/{utils → _utils}/cdf/loaders/__init__.py +0 -0
- /cognite/neat/{utils → _utils}/cdf/loaders/_base.py +0 -0
- /cognite/neat/{utils → _utils}/collection_.py +0 -0
- /cognite/neat/{utils → _utils}/rdf_.py +0 -0
- /cognite/neat/{utils → _utils}/spreadsheet.py +0 -0
- /cognite/neat/{utils → _utils}/text.py +0 -0
- /cognite/neat/{utils → _utils}/time_.py +0 -0
- /cognite/neat/{utils → _utils}/xml_.py +0 -0
- /cognite/neat/{workflows → _workflows}/examples/Export_Semantic_Data_Model/workflow.yaml +0 -0
- /cognite/neat/{workflows → _workflows}/examples/Import_DMS/workflow.yaml +0 -0
- /cognite/neat/{workflows → _workflows}/examples/Validate_Rules/workflow.yaml +0 -0
- /cognite/neat/{workflows → _workflows}/examples/Validate_Solution_Model/workflow.yaml +0 -0
- /cognite/neat/{workflows → _workflows}/model.py +0 -0
- /cognite/neat/{workflows → _workflows}/steps/__init__.py +0 -0
- /cognite/neat/{workflows → _workflows}/steps/lib/__init__.py +0 -0
- /cognite/neat/{workflows → _workflows}/steps/lib/current/__init__.py +0 -0
- /cognite/neat/{workflows → _workflows}/steps/lib/io/__init__.py +0 -0
- /cognite/neat/{workflows → _workflows}/utils.py +0 -0
- {cognite_neat-0.92.2.dist-info → cognite_neat-0.93.0.dist-info}/LICENSE +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
from ._base import RuleMapping
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def create_classic_to_core_mapping() -> RuleMapping:
|
|
5
|
+
return RuleMapping.model_validate(_CLASSIC_TO_CORE)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_CLASSIC_TO_CORE = {
|
|
9
|
+
"classes": [
|
|
10
|
+
{"destination": {"Class": "cdf_cdm:CogniteAsset"}, "source": {"Class": "classic:Asset"}},
|
|
11
|
+
{"destination": {"Class": "cdf_cdm:DataProduct"}, "source": {"Class": "classic:DataSet"}},
|
|
12
|
+
{"destination": {"Class": "cdf_cdm:CogniteActivity"}, "source": {"Class": "classic:Event"}},
|
|
13
|
+
{"destination": {"Class": "cdf_cdm:CogniteFile"}, "source": {"Class": "classic:File"}},
|
|
14
|
+
{"destination": {"Class": "cdf_cdm:CogniteTimeSeries"}, "source": {"Class": "classic:TimeSeries"}},
|
|
15
|
+
],
|
|
16
|
+
"properties": [
|
|
17
|
+
{
|
|
18
|
+
"destination": {"Class": "cdf_cdm:CogniteAsset", "Property": "externalId"},
|
|
19
|
+
"source": {"Class": "classic:Asset", "Property": "externalId"},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"destination": {"Class": "cdf_cdm:CogniteAsset", "Property": "name"},
|
|
23
|
+
"source": {"Class": "classic:Asset", "Property": "name"},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"destination": {"Class": "cdf_cdm:CogniteAsset", "Property": "parent"},
|
|
27
|
+
"source": {"Class": "classic:Asset", "Property": "parentId"},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"destination": {"Class": "cdf_cdm:CogniteAsset", "Property": "description"},
|
|
31
|
+
"source": {"Class": "classic:Asset", "Property": "description"},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"destination": {"Class": "cdf_cdm:CogniteSourceSystem", "Property": "name"},
|
|
35
|
+
"source": {"Class": "classic:Asset", "Property": "source"},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"destination": {"Class": "cdf_cdm:CogniteAsset", "Property": "tag"},
|
|
39
|
+
"source": {"Class": "classic:Asset", "Property": "labels"},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "externalId"},
|
|
43
|
+
"source": {"Class": "classic:DataSet", "Property": "externalId"},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "name"},
|
|
47
|
+
"source": {"Class": "classic:DataSet", "Property": "name"},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "description"},
|
|
51
|
+
"source": {"Class": "classic:DataSet", "Property": "description"},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "metadata"},
|
|
55
|
+
"source": {"Class": "classic:DataSet", "Property": "metadata"},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"destination": {"Class": "cdf_cdm:DataProduct", "Property": "writeProtected"},
|
|
59
|
+
"source": {"Class": "classic:DataSet", "Property": "writeProtected"},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"destination": {"Class": "cdf_cdm:CogniteActivity", "Property": "externalId"},
|
|
63
|
+
"source": {"Class": "classic:Event", "Property": "externalId"},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"destination": {"Class": "cdf_cdm:CogniteSchedulable", "Property": "startTime"},
|
|
67
|
+
"source": {"Class": "classic:Event", "Property": "startTime"},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"destination": {"Class": "cdf_cdm:CogniteSchedulable", "Property": "endTime"},
|
|
71
|
+
"source": {"Class": "classic:Event", "Property": "endTime"},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"destination": {"Class": "cdf_cdm:CogniteActivity", "Property": "description"},
|
|
75
|
+
"source": {"Class": "classic:Event", "Property": "description"},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"destination": {"Class": "cdf_cdm:CogniteActivity", "Property": "assets"},
|
|
79
|
+
"source": {"Class": "classic:Event", "Property": "assetIds"},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"destination": {"Class": "cdf_cdm:CogniteSourceSystem", "Property": "name"},
|
|
83
|
+
"source": {"Class": "classic:Event", "Property": "source"},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "externalId"},
|
|
87
|
+
"source": {"Class": "classic:File", "Property": "externalId"},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "name"},
|
|
91
|
+
"source": {"Class": "classic:File", "Property": "name"},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "directory"},
|
|
95
|
+
"source": {"Class": "classic:File", "Property": "directory"},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"destination": {"Class": "cdf_cdm:CogniteSourceSystem", "Property": "name"},
|
|
99
|
+
"source": {"Class": "classic:File", "Property": "source"},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "mimeType"},
|
|
103
|
+
"source": {"Class": "classic:File", "Property": "mimeType"},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "assets"},
|
|
107
|
+
"source": {"Class": "classic:File", "Property": "assetIds"},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "sourceCreatedTime"},
|
|
111
|
+
"source": {"Class": "classic:File", "Property": "sourceCreatedTime"},
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"destination": {"Class": "cdf_cdm:CogniteFile", "Property": "sourceUpdatedTime"},
|
|
115
|
+
"source": {"Class": "classic:File", "Property": "sourceModifiedTime"},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "externalId"},
|
|
119
|
+
"source": {"Class": "classic:TimeSeries", "Property": "externalId"},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "name"},
|
|
123
|
+
"source": {"Class": "classic:TimeSeries", "Property": "name"},
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "type"},
|
|
127
|
+
"source": {"Class": "classic:TimeSeries", "Property": "isString"},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "sourceUnit"},
|
|
131
|
+
"source": {"Class": "classic:TimeSeries", "Property": "unit"},
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "unit"},
|
|
135
|
+
"source": {"Class": "classic:TimeSeries", "Property": "unitExternalId"},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "assets"},
|
|
139
|
+
"source": {"Class": "classic:TimeSeries", "Property": "assetId"},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "isStep"},
|
|
143
|
+
"source": {"Class": "classic:TimeSeries", "Property": "isStep"},
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"destination": {"Class": "cdf_cdm:CogniteTimeSeries", "Property": "description"},
|
|
147
|
+
"source": {"Class": "classic:TimeSeries", "Property": "description"},
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
from ._base import RulesPipeline, RulesTransformer
|
|
2
|
-
from ._converters import
|
|
3
|
-
|
|
2
|
+
from ._converters import (
|
|
3
|
+
AssetToInformation,
|
|
4
|
+
ConvertToRules,
|
|
5
|
+
DMSToInformation,
|
|
6
|
+
InformationToAsset,
|
|
7
|
+
InformationToDMS,
|
|
8
|
+
ReduceCogniteModel,
|
|
9
|
+
ToCompliantEntities,
|
|
10
|
+
ToExtension,
|
|
11
|
+
)
|
|
12
|
+
from ._mapping import MapOneToOne, RuleMapper
|
|
4
13
|
from ._pipelines import ImporterPipeline
|
|
5
14
|
from ._verification import VerifyAnyRules, VerifyAssetRules, VerifyDMSRules, VerifyInformationRules
|
|
6
15
|
|
|
@@ -18,4 +27,8 @@ __all__ = [
|
|
|
18
27
|
"VerifyInformationRules",
|
|
19
28
|
"VerifyAnyRules",
|
|
20
29
|
"MapOneToOne",
|
|
30
|
+
"ToCompliantEntities",
|
|
31
|
+
"RuleMapper",
|
|
32
|
+
"ToExtension",
|
|
33
|
+
"ReduceCogniteModel",
|
|
21
34
|
]
|
|
@@ -2,9 +2,9 @@ from abc import ABC, abstractmethod
|
|
|
2
2
|
from collections.abc import MutableSequence
|
|
3
3
|
from typing import Generic, TypeVar
|
|
4
4
|
|
|
5
|
-
from cognite.neat.
|
|
6
|
-
from cognite.neat.
|
|
7
|
-
from cognite.neat.
|
|
5
|
+
from cognite.neat._issues import IssueList, NeatError
|
|
6
|
+
from cognite.neat._issues.errors import NeatTypeError, NeatValueError
|
|
7
|
+
from cognite.neat._rules._shared import (
|
|
8
8
|
InputRules,
|
|
9
9
|
JustRules,
|
|
10
10
|
MaybeRules,
|
|
@@ -2,18 +2,23 @@ import re
|
|
|
2
2
|
import warnings
|
|
3
3
|
from abc import ABC, abstractmethod
|
|
4
4
|
from collections import Counter, defaultdict
|
|
5
|
-
from collections.abc import Collection
|
|
5
|
+
from collections.abc import Collection, Mapping
|
|
6
6
|
from datetime import date, datetime
|
|
7
7
|
from typing import Literal, TypeVar, cast
|
|
8
8
|
|
|
9
9
|
from cognite.client.data_classes import data_modeling as dms
|
|
10
|
+
from cognite.client.data_classes.data_modeling import DataModelId, DataModelIdentifier, ViewId
|
|
10
11
|
from rdflib import Namespace
|
|
11
12
|
|
|
12
|
-
from cognite.neat.
|
|
13
|
-
from cognite.neat.
|
|
14
|
-
from cognite.neat.
|
|
15
|
-
from cognite.neat.
|
|
13
|
+
from cognite.neat._constants import COGNITE_MODELS, DMS_CONTAINER_PROPERTY_SIZE_LIMIT
|
|
14
|
+
from cognite.neat._issues.errors import NeatValueError
|
|
15
|
+
from cognite.neat._issues.warnings.user_modeling import ParentInDifferentSpaceWarning
|
|
16
|
+
from cognite.neat._rules._constants import EntityTypes
|
|
17
|
+
from cognite.neat._rules._shared import InputRules, JustRules, OutRules, VerifiedRules
|
|
18
|
+
from cognite.neat._rules.analysis import DMSAnalysis
|
|
19
|
+
from cognite.neat._rules.models import (
|
|
16
20
|
AssetRules,
|
|
21
|
+
DMSInputRules,
|
|
17
22
|
DMSRules,
|
|
18
23
|
DomainRules,
|
|
19
24
|
ExtensionCategory,
|
|
@@ -22,16 +27,15 @@ from cognite.neat.rules.models import (
|
|
|
22
27
|
SheetList,
|
|
23
28
|
data_types,
|
|
24
29
|
)
|
|
25
|
-
from cognite.neat.
|
|
26
|
-
from cognite.neat.
|
|
27
|
-
from cognite.neat.
|
|
30
|
+
from cognite.neat._rules.models.data_types import DataType, String
|
|
31
|
+
from cognite.neat._rules.models.dms import DMSMetadata, DMSProperty, DMSView
|
|
32
|
+
from cognite.neat._rules.models.entities import (
|
|
28
33
|
AssetEntity,
|
|
29
34
|
AssetFields,
|
|
30
35
|
ClassEntity,
|
|
31
36
|
ContainerEntity,
|
|
32
37
|
DMSUnknownEntity,
|
|
33
38
|
EdgeEntity,
|
|
34
|
-
EntityTypes,
|
|
35
39
|
MultiValueTypeInfo,
|
|
36
40
|
ReferenceEntity,
|
|
37
41
|
RelationshipEntity,
|
|
@@ -39,12 +43,19 @@ from cognite.neat.rules.models.entities import (
|
|
|
39
43
|
UnknownEntity,
|
|
40
44
|
ViewEntity,
|
|
41
45
|
)
|
|
42
|
-
from cognite.neat.
|
|
46
|
+
from cognite.neat._rules.models.information import InformationClass, InformationMetadata, InformationProperty
|
|
47
|
+
from cognite.neat._rules.models.information._rules_input import (
|
|
48
|
+
InformationInputClass,
|
|
49
|
+
InformationInputProperty,
|
|
50
|
+
InformationInputRules,
|
|
51
|
+
)
|
|
43
52
|
|
|
44
53
|
from ._base import RulesTransformer
|
|
45
54
|
|
|
46
55
|
T_VerifiedInRules = TypeVar("T_VerifiedInRules", bound=VerifiedRules)
|
|
47
56
|
T_VerifiedOutRules = TypeVar("T_VerifiedOutRules", bound=VerifiedRules)
|
|
57
|
+
T_InputInRules = TypeVar("T_InputInRules", bound=InputRules)
|
|
58
|
+
T_InputOutRules = TypeVar("T_InputOutRules", bound=InputRules)
|
|
48
59
|
|
|
49
60
|
|
|
50
61
|
class ConversionTransformer(RulesTransformer[T_VerifiedInRules, T_VerifiedOutRules], ABC):
|
|
@@ -59,6 +70,105 @@ class ConversionTransformer(RulesTransformer[T_VerifiedInRules, T_VerifiedOutRul
|
|
|
59
70
|
raise NotImplementedError()
|
|
60
71
|
|
|
61
72
|
|
|
73
|
+
class ToCompliantEntities(RulesTransformer[InformationInputRules, InformationInputRules]): # type: ignore[misc]
|
|
74
|
+
"""Converts input rules to rules with compliant entity IDs that match regex patters used
|
|
75
|
+
by DMS schema components."""
|
|
76
|
+
|
|
77
|
+
def transform(
|
|
78
|
+
self, rules: InformationInputRules | OutRules[InformationInputRules]
|
|
79
|
+
) -> OutRules[InformationInputRules]:
|
|
80
|
+
return JustRules(self._transform(self._to_rules(rules)))
|
|
81
|
+
|
|
82
|
+
def _transform(self, rules: InformationInputRules) -> InformationInputRules:
|
|
83
|
+
rules.metadata.prefix = self._fix_entity(rules.metadata.prefix)
|
|
84
|
+
rules.classes = self._fix_classes(rules.classes)
|
|
85
|
+
rules.properties = self._fix_properties(rules.properties)
|
|
86
|
+
return rules
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def _fix_entity(cls, entity: str) -> str:
|
|
90
|
+
entity = re.sub(r"[^_a-zA-Z0-9]+", "_", entity)
|
|
91
|
+
|
|
92
|
+
# entity id must start with a letter
|
|
93
|
+
if not entity[0].isalpha():
|
|
94
|
+
entity = "prefix_" + entity
|
|
95
|
+
# and end with a letter or number
|
|
96
|
+
if not entity[-1].isalnum():
|
|
97
|
+
entity = entity + "_suffix"
|
|
98
|
+
|
|
99
|
+
# removing any double underscores that could occur
|
|
100
|
+
return re.sub(r"[^a-zA-Z0-9]+", "_", entity)
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def _fix_class(cls, class_: str | ClassEntity) -> str | ClassEntity:
|
|
104
|
+
if isinstance(class_, str):
|
|
105
|
+
if len(class_.split(":")) == 2:
|
|
106
|
+
prefix, suffix = class_.split(":")
|
|
107
|
+
class_ = f"{cls._fix_entity(prefix)}:{cls._fix_entity(suffix)}"
|
|
108
|
+
|
|
109
|
+
else:
|
|
110
|
+
class_ = cls._fix_entity(class_)
|
|
111
|
+
|
|
112
|
+
elif isinstance(class_, ClassEntity) and type(class_.prefix) is str:
|
|
113
|
+
class_ = ClassEntity(
|
|
114
|
+
prefix=cls._fix_entity(class_.prefix),
|
|
115
|
+
suffix=cls._fix_entity(class_.suffix),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return class_
|
|
119
|
+
|
|
120
|
+
@classmethod
|
|
121
|
+
def _fix_value_type(
|
|
122
|
+
cls, value_type: str | DataType | ClassEntity | MultiValueTypeInfo
|
|
123
|
+
) -> str | DataType | ClassEntity | MultiValueTypeInfo:
|
|
124
|
+
fixed_value_type: str | DataType | ClassEntity | MultiValueTypeInfo
|
|
125
|
+
|
|
126
|
+
if isinstance(value_type, str):
|
|
127
|
+
# this is a multi value type but as string
|
|
128
|
+
if " | " in value_type:
|
|
129
|
+
value_types = value_type.split(" | ")
|
|
130
|
+
fixed_value_type = " | ".join([cast(str, cls._fix_value_type(v)) for v in value_types])
|
|
131
|
+
# this is value type specified with prefix:suffix string
|
|
132
|
+
elif ":" in value_type:
|
|
133
|
+
fixed_value_type = cls._fix_class(value_type)
|
|
134
|
+
|
|
135
|
+
# this is value type specified as suffix only
|
|
136
|
+
else:
|
|
137
|
+
fixed_value_type = cls._fix_entity(value_type)
|
|
138
|
+
|
|
139
|
+
# value type specified as instances of DataType, ClassEntity or MultiValueTypeInfo
|
|
140
|
+
elif isinstance(value_type, MultiValueTypeInfo):
|
|
141
|
+
fixed_value_type = MultiValueTypeInfo(
|
|
142
|
+
types=[cast(DataType | ClassEntity, cls._fix_value_type(type_)) for type_ in value_type.types],
|
|
143
|
+
)
|
|
144
|
+
elif isinstance(value_type, ClassEntity):
|
|
145
|
+
fixed_value_type = cls._fix_class(value_type)
|
|
146
|
+
|
|
147
|
+
# this is a DataType instance but also we should default to original value
|
|
148
|
+
else:
|
|
149
|
+
fixed_value_type = value_type
|
|
150
|
+
|
|
151
|
+
return fixed_value_type
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def _fix_classes(cls, definitions: list[InformationInputClass]) -> list[InformationInputClass]:
|
|
155
|
+
fixed_definitions = []
|
|
156
|
+
for definition in definitions:
|
|
157
|
+
definition.class_ = cls._fix_class(definition.class_)
|
|
158
|
+
fixed_definitions.append(definition)
|
|
159
|
+
return fixed_definitions
|
|
160
|
+
|
|
161
|
+
@classmethod
|
|
162
|
+
def _fix_properties(cls, definitions: list[InformationInputProperty]) -> list[InformationInputProperty]:
|
|
163
|
+
fixed_definitions = []
|
|
164
|
+
for definition in definitions:
|
|
165
|
+
definition.class_ = cls._fix_class(definition.class_)
|
|
166
|
+
definition.property_ = cls._fix_entity(definition.property_)
|
|
167
|
+
definition.value_type = cls._fix_value_type(definition.value_type)
|
|
168
|
+
fixed_definitions.append(definition)
|
|
169
|
+
return fixed_definitions
|
|
170
|
+
|
|
171
|
+
|
|
62
172
|
class InformationToDMS(ConversionTransformer[InformationRules, DMSRules]):
|
|
63
173
|
"""Converts InformationRules to DMSRules."""
|
|
64
174
|
|
|
@@ -114,6 +224,146 @@ class ConvertToRules(ConversionTransformer[VerifiedRules, VerifiedRules]):
|
|
|
114
224
|
raise ValueError(f"Unsupported conversion from {type(rules)} to {self._out_cls}")
|
|
115
225
|
|
|
116
226
|
|
|
227
|
+
_T_Entity = TypeVar("_T_Entity", bound=ClassEntity | ViewEntity)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class ToExtension(RulesTransformer[DMSRules, DMSRules]):
|
|
231
|
+
def __init__(
|
|
232
|
+
self,
|
|
233
|
+
new_model_id: DataModelIdentifier,
|
|
234
|
+
org_name: str | None = None,
|
|
235
|
+
mode: Literal["composition"] = "composition",
|
|
236
|
+
):
|
|
237
|
+
self.new_model_id = DataModelId.load(new_model_id)
|
|
238
|
+
self.org_name = org_name
|
|
239
|
+
self.mode = mode
|
|
240
|
+
|
|
241
|
+
def transform(self, rules: DMSRules | OutRules[DMSRules]) -> JustRules[DMSRules]:
|
|
242
|
+
# Copy to ensure immutability
|
|
243
|
+
verified = self._to_rules(rules)
|
|
244
|
+
if self.org_name is None and verified.metadata.as_data_model_id() in COGNITE_MODELS:
|
|
245
|
+
raise NeatValueError(f"Prefix is required when extending {verified.metadata.as_data_model_id()}")
|
|
246
|
+
source_id = verified.metadata.as_data_model_id()
|
|
247
|
+
|
|
248
|
+
dump = verified.dump()
|
|
249
|
+
dump["metadata"]["schema_"] = SchemaCompleteness.partial.value
|
|
250
|
+
dump["metadata"]["space"] = self.new_model_id.space
|
|
251
|
+
dump["metadata"]["external_id"] = self.new_model_id.external_id
|
|
252
|
+
if self.new_model_id.version is not None:
|
|
253
|
+
dump["metadata"]["version"] = self.new_model_id.version
|
|
254
|
+
# Serialize and deserialize to set the new space and external_id
|
|
255
|
+
# as the default values for the new model.
|
|
256
|
+
new_model = DMSRules.model_validate(DMSInputRules.load(dump).dump())
|
|
257
|
+
|
|
258
|
+
# Write back the original space and external_id for the container of the new model.
|
|
259
|
+
for prop in new_model.properties:
|
|
260
|
+
if prop.container and prop.container.space == self.new_model_id.space:
|
|
261
|
+
prop.container = ContainerEntity(
|
|
262
|
+
space=source_id.space,
|
|
263
|
+
externalId=prop.container.suffix,
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
if self.mode == "composition":
|
|
267
|
+
new_model.containers = None
|
|
268
|
+
for view in new_model.views:
|
|
269
|
+
view.implements = None
|
|
270
|
+
|
|
271
|
+
if source_id in COGNITE_MODELS:
|
|
272
|
+
# Remove CognitePrefixes.
|
|
273
|
+
for prop in new_model.properties:
|
|
274
|
+
prop.view = self._remove_cognite_prefix(prop.view)
|
|
275
|
+
prop.class_ = self._remove_cognite_prefix(prop.class_)
|
|
276
|
+
if isinstance(prop.value_type, ViewEntity):
|
|
277
|
+
prop.value_type = self._remove_cognite_prefix(prop.value_type)
|
|
278
|
+
for view in new_model.views:
|
|
279
|
+
view.view = self._remove_cognite_prefix(view.view)
|
|
280
|
+
view.class_ = self._remove_cognite_prefix(view.class_)
|
|
281
|
+
|
|
282
|
+
return JustRules(new_model)
|
|
283
|
+
|
|
284
|
+
def _remove_cognite_prefix(self, entity: _T_Entity) -> _T_Entity:
|
|
285
|
+
new_suffix = entity.suffix.replace("Cognite", self.org_name or "")
|
|
286
|
+
if isinstance(entity, ViewEntity):
|
|
287
|
+
return ViewEntity(space=entity.space, externalId=new_suffix, version=entity.version) # type: ignore[return-value]
|
|
288
|
+
elif isinstance(entity, ClassEntity):
|
|
289
|
+
return ClassEntity(prefix=entity.prefix, suffix=new_suffix, version=entity.version) # type: ignore[return-value]
|
|
290
|
+
raise ValueError(f"Unsupported entity type: {type(entity)}")
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class ReduceCogniteModel(RulesTransformer[DMSRules, DMSRules]):
|
|
294
|
+
_ASSET_VIEW = ViewId("cdf_cdm", "CogniteAsset", "v1")
|
|
295
|
+
_VIEW_BY_COLLECTION: Mapping[Literal["3D", "Annotation", "BaseViews"], frozenset[ViewId]] = {
|
|
296
|
+
"3D": frozenset(
|
|
297
|
+
{
|
|
298
|
+
ViewId("cdf_cdm", "Cognite3DModel", "v1"),
|
|
299
|
+
ViewId("cdf_cdm", "Cognite3DObject", "v1"),
|
|
300
|
+
ViewId("cdf_cdm", "Cognite3DRevision", "v1"),
|
|
301
|
+
ViewId("cdf_cdm", "Cognite3DTransformation", "v1"),
|
|
302
|
+
ViewId("cdf_cdm", "Cognite360Image", "v1"),
|
|
303
|
+
ViewId("cdf_cdm", "Cognite360ImageAnnotation", "v1"),
|
|
304
|
+
ViewId("cdf_cdm", "Cognite360ImageCollection", "v1"),
|
|
305
|
+
ViewId("cdf_cdm", "Cognite360ImageModel", "v1"),
|
|
306
|
+
ViewId("cdf_cdm", "Cognite360ImageStation", "v1"),
|
|
307
|
+
ViewId("cdf_cdm", "CogniteCADModel", "v1"),
|
|
308
|
+
ViewId("cdf_cdm", "CogniteCADNode", "v1"),
|
|
309
|
+
ViewId("cdf_cdm", "CogniteCADRevision", "v1"),
|
|
310
|
+
ViewId("cdf_cdm", "CogniteCubeMap", "v1"),
|
|
311
|
+
ViewId("cdf_cdm", "CognitePointCloudModel", "v1"),
|
|
312
|
+
ViewId("cdf_cdm", "CognitePointCloudRevision", "v1"),
|
|
313
|
+
ViewId("cdf_cdm", "CognitePointCloudVolume", "v1"),
|
|
314
|
+
}
|
|
315
|
+
),
|
|
316
|
+
"Annotation": frozenset(
|
|
317
|
+
{
|
|
318
|
+
ViewId("cdf_cdm", "CogniteAnnotation", "v1"),
|
|
319
|
+
ViewId("cdf_cdm", "CogniteDiagramAnnotation", "v1"),
|
|
320
|
+
}
|
|
321
|
+
),
|
|
322
|
+
"BaseViews": frozenset(
|
|
323
|
+
{
|
|
324
|
+
ViewId("cdf_cdm", "CogniteDescribable", "v1"),
|
|
325
|
+
ViewId("cdf_cdm", "CogniteSchedulable", "v1"),
|
|
326
|
+
ViewId("cdf_cdm", "CogniteSourceable", "v1"),
|
|
327
|
+
ViewId("cdf_cdm", "CogniteVisualizable", "v1"),
|
|
328
|
+
}
|
|
329
|
+
),
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
def __init__(self, drop: Collection[Literal["3D", "Annotation", "BaseViews"]]):
|
|
333
|
+
self.drop = drop
|
|
334
|
+
|
|
335
|
+
def transform(self, rules: DMSRules | OutRules[DMSRules]) -> JustRules[DMSRules]:
|
|
336
|
+
verified = self._to_rules(rules)
|
|
337
|
+
if verified.metadata.as_data_model_id() not in COGNITE_MODELS:
|
|
338
|
+
raise NeatValueError(f"Can only reduce Cognite Data Models, not {verified.metadata.as_data_model_id()}")
|
|
339
|
+
if invalid := (set(self.drop) - set(self._VIEW_BY_COLLECTION.keys())):
|
|
340
|
+
raise NeatValueError(f"Invalid drop values: {invalid}. Expected {set(self._VIEW_BY_COLLECTION)}")
|
|
341
|
+
|
|
342
|
+
exclude_views = {view for collection in self.drop for view in self._VIEW_BY_COLLECTION[collection]}
|
|
343
|
+
new_model = verified.model_copy(deep=True)
|
|
344
|
+
|
|
345
|
+
properties_by_view = DMSAnalysis(new_model).classes_with_properties(consider_inheritance=True)
|
|
346
|
+
|
|
347
|
+
new_model.views = SheetList[DMSView](
|
|
348
|
+
[view for view in new_model.views if view.view.as_id() not in exclude_views]
|
|
349
|
+
)
|
|
350
|
+
new_properties = SheetList[DMSProperty]()
|
|
351
|
+
for view in new_model.views:
|
|
352
|
+
for prop in properties_by_view[view.view]:
|
|
353
|
+
if self._is_asset_3D_property(prop):
|
|
354
|
+
# We filter out the 3D property of asset
|
|
355
|
+
continue
|
|
356
|
+
new_properties.append(prop)
|
|
357
|
+
new_model.properties = new_properties
|
|
358
|
+
|
|
359
|
+
return JustRules(new_model)
|
|
360
|
+
|
|
361
|
+
def _is_asset_3D_property(self, prop: DMSProperty) -> bool:
|
|
362
|
+
if "3D" not in self.drop:
|
|
363
|
+
return False
|
|
364
|
+
return prop.view.as_id() == self._ASSET_VIEW and prop.property_ == "object3D"
|
|
365
|
+
|
|
366
|
+
|
|
117
367
|
class _InformationRulesConverter:
|
|
118
368
|
def __init__(self, information: InformationRules):
|
|
119
369
|
self.rules = information
|
|
@@ -135,7 +385,7 @@ class _InformationRulesConverter:
|
|
|
135
385
|
raise NotImplementedError("DomainRules not implemented yet")
|
|
136
386
|
|
|
137
387
|
def as_asset_architect_rules(self) -> "AssetRules":
|
|
138
|
-
from cognite.neat.
|
|
388
|
+
from cognite.neat._rules.models.asset._rules import AssetClass, AssetMetadata, AssetProperty, AssetRules
|
|
139
389
|
|
|
140
390
|
classes: SheetList[AssetClass] = SheetList[AssetClass](
|
|
141
391
|
[AssetClass(**class_.model_dump()) for class_ in self.rules.classes]
|
|
@@ -157,7 +407,7 @@ class _InformationRulesConverter:
|
|
|
157
407
|
)
|
|
158
408
|
|
|
159
409
|
def as_dms_rules(self, ignore_undefined_value_types: bool = False) -> "DMSRules":
|
|
160
|
-
from cognite.neat.
|
|
410
|
+
from cognite.neat._rules.models.dms._rules import (
|
|
161
411
|
DMSContainer,
|
|
162
412
|
DMSProperty,
|
|
163
413
|
DMSRules,
|
|
@@ -252,7 +502,7 @@ class _InformationRulesConverter:
|
|
|
252
502
|
|
|
253
503
|
@classmethod
|
|
254
504
|
def _convert_metadata_to_dms(cls, metadata: InformationMetadata) -> "DMSMetadata":
|
|
255
|
-
from cognite.neat.
|
|
505
|
+
from cognite.neat._rules.models.dms._rules import (
|
|
256
506
|
DMSMetadata,
|
|
257
507
|
)
|
|
258
508
|
|
|
@@ -273,18 +523,35 @@ class _InformationRulesConverter:
|
|
|
273
523
|
def _as_dms_property(self, prop: InformationProperty, default_space: str, default_version: str) -> "DMSProperty":
|
|
274
524
|
"""This creates the first"""
|
|
275
525
|
|
|
276
|
-
from cognite.neat.
|
|
526
|
+
from cognite.neat._rules.models.dms._rules import DMSProperty
|
|
277
527
|
|
|
278
528
|
# returns property type, which can be ObjectProperty or DatatypeProperty
|
|
279
529
|
value_type: DataType | ViewEntity | DMSUnknownEntity
|
|
280
530
|
if isinstance(prop.value_type, DataType):
|
|
281
531
|
value_type = prop.value_type
|
|
532
|
+
|
|
533
|
+
# UnknownEntity should resolve to DMSUnknownEntity
|
|
534
|
+
# meaning end node type is unknown
|
|
282
535
|
elif isinstance(prop.value_type, UnknownEntity):
|
|
283
536
|
value_type = DMSUnknownEntity()
|
|
537
|
+
|
|
284
538
|
elif isinstance(prop.value_type, ClassEntity):
|
|
285
539
|
value_type = prop.value_type.as_view_entity(default_space, default_version)
|
|
540
|
+
|
|
286
541
|
elif isinstance(prop.value_type, MultiValueTypeInfo):
|
|
287
|
-
|
|
542
|
+
# Multi Object type should resolve to DMSUnknownEntity
|
|
543
|
+
# meaning end node type is unknown
|
|
544
|
+
if prop.value_type.is_multi_object_type():
|
|
545
|
+
value_type = DMSUnknownEntity()
|
|
546
|
+
|
|
547
|
+
# Multi Data type should resolve to a single data type, or it should
|
|
548
|
+
elif prop.value_type.is_multi_data_type():
|
|
549
|
+
value_type = self.convert_multi_data_type(prop.value_type)
|
|
550
|
+
|
|
551
|
+
# Mixed types default to string
|
|
552
|
+
else:
|
|
553
|
+
value_type = String()
|
|
554
|
+
|
|
288
555
|
else:
|
|
289
556
|
raise ValueError(f"Unsupported value type: {prop.value_type.type_}")
|
|
290
557
|
|
|
@@ -391,13 +658,15 @@ class _InformationRulesConverter:
|
|
|
391
658
|
return f"{suffix}2"
|
|
392
659
|
|
|
393
660
|
@staticmethod
|
|
394
|
-
def
|
|
395
|
-
if not
|
|
661
|
+
def convert_multi_data_type(value_type: MultiValueTypeInfo) -> DataType:
|
|
662
|
+
if not value_type.is_multi_data_type():
|
|
396
663
|
raise ValueError("Only MultiValueType with DataType types is supported")
|
|
397
664
|
# We check above that there are no ClassEntity types in the MultiValueType
|
|
398
665
|
py_types = {type_.python for type_ in value_type.types} # type: ignore[union-attr]
|
|
666
|
+
|
|
667
|
+
# JSON mixed with other types should resolve to string that is safe choice
|
|
399
668
|
if dms.Json in py_types and len(py_types) > 1:
|
|
400
|
-
|
|
669
|
+
return data_types.String()
|
|
401
670
|
elif dms.Json in py_types:
|
|
402
671
|
return data_types.Json()
|
|
403
672
|
elif not (py_types - {bool}):
|
|
@@ -422,7 +691,7 @@ class _DMSRulesConverter:
|
|
|
422
691
|
def as_information_rules(
|
|
423
692
|
self,
|
|
424
693
|
) -> "InformationRules":
|
|
425
|
-
from cognite.neat.
|
|
694
|
+
from cognite.neat._rules.models.information._rules import (
|
|
426
695
|
InformationClass,
|
|
427
696
|
InformationProperty,
|
|
428
697
|
InformationRules,
|
|
@@ -487,7 +756,7 @@ class _DMSRulesConverter:
|
|
|
487
756
|
|
|
488
757
|
@classmethod
|
|
489
758
|
def _convert_metadata_to_info(cls, metadata: DMSMetadata) -> "InformationMetadata":
|
|
490
|
-
from cognite.neat.
|
|
759
|
+
from cognite.neat._rules.models.information._rules import InformationMetadata
|
|
491
760
|
|
|
492
761
|
prefix = metadata.space
|
|
493
762
|
return InformationMetadata(
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
from abc import ABC
|
|
2
2
|
from collections import defaultdict
|
|
3
3
|
|
|
4
|
-
from cognite.neat.
|
|
5
|
-
from cognite.neat.
|
|
6
|
-
from cognite.neat.
|
|
7
|
-
from cognite.neat.
|
|
4
|
+
from cognite.neat._rules._shared import JustRules, OutRules
|
|
5
|
+
from cognite.neat._rules.models import DMSRules, InformationRules
|
|
6
|
+
from cognite.neat._rules.models._base_rules import ClassRef
|
|
7
|
+
from cognite.neat._rules.models.dms import DMSProperty
|
|
8
|
+
from cognite.neat._rules.models.entities import ClassEntity, ReferenceEntity
|
|
9
|
+
from cognite.neat._rules.models.information import InformationClass
|
|
10
|
+
from cognite.neat._rules.models.mapping import RuleMapping
|
|
8
11
|
|
|
9
12
|
from ._base import RulesTransformer
|
|
10
13
|
|
|
@@ -95,3 +98,42 @@ class MapOneToOne(MapOntoTransformers):
|
|
|
95
98
|
prop.reference = ReferenceEntity.from_entity(ref_prop.view, ref_prop.view_property)
|
|
96
99
|
|
|
97
100
|
return JustRules(solution)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class RuleMapper(RulesTransformer[InformationRules, InformationRules]):
|
|
104
|
+
"""Maps properties and classes using the given mapping.
|
|
105
|
+
|
|
106
|
+
**Note**: This transformer mutates the input rules.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
mapping: The mapping to use.
|
|
110
|
+
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
def __init__(self, mapping: RuleMapping) -> None:
|
|
114
|
+
self.mapping = mapping
|
|
115
|
+
|
|
116
|
+
def transform(self, rules: InformationRules | OutRules[InformationRules]) -> JustRules[InformationRules]:
|
|
117
|
+
input_rules = self._to_rules(rules)
|
|
118
|
+
|
|
119
|
+
destination_by_source = self.mapping.properties.as_destination_by_source()
|
|
120
|
+
destination_cls_by_source = self.mapping.classes.as_destination_by_source()
|
|
121
|
+
used_destination_classes: set[ClassEntity] = set()
|
|
122
|
+
for prop in input_rules.properties:
|
|
123
|
+
if destination_prop := destination_by_source.get(prop.as_reference()):
|
|
124
|
+
prop.class_ = destination_prop.class_
|
|
125
|
+
prop.property_ = destination_prop.property_
|
|
126
|
+
used_destination_classes.add(destination_prop.class_)
|
|
127
|
+
elif destination_cls := destination_cls_by_source.get(ClassRef(Class=prop.class_)):
|
|
128
|
+
# If the property is not in the mapping, but the class is,
|
|
129
|
+
# then we should map the class to the destination
|
|
130
|
+
prop.class_ = destination_cls.class_
|
|
131
|
+
|
|
132
|
+
for cls_ in input_rules.classes:
|
|
133
|
+
if destination_cls := destination_cls_by_source.get(cls_.as_reference()):
|
|
134
|
+
cls_.class_ = destination_cls.class_
|
|
135
|
+
existing_classes = {cls_.class_ for cls_ in input_rules.classes}
|
|
136
|
+
for new_cls in used_destination_classes - existing_classes:
|
|
137
|
+
input_rules.classes.append(InformationClass(class_=new_cls))
|
|
138
|
+
|
|
139
|
+
return JustRules(input_rules)
|