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,152 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Literal, cast
|
|
4
|
+
|
|
5
|
+
from openpyxl import Workbook
|
|
6
|
+
from openpyxl.cell import Cell
|
|
7
|
+
from openpyxl.styles import Alignment, Border, Font, NamedStyle, PatternFill, Side
|
|
8
|
+
from openpyxl.utils import get_column_letter
|
|
9
|
+
from openpyxl.worksheet.datavalidation import DataValidation
|
|
10
|
+
|
|
11
|
+
from cognite.neat._rules._constants import EntityTypes
|
|
12
|
+
from cognite.neat._rules.analysis import InformationAnalysis
|
|
13
|
+
from cognite.neat._rules.models.entities._single_value import ClassEntity
|
|
14
|
+
from cognite.neat._rules.models.information._rules import InformationRules
|
|
15
|
+
|
|
16
|
+
from ._base import BaseExporter
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class InstanceTemplateExporter(BaseExporter[InformationRules, Workbook]):
|
|
20
|
+
"""
|
|
21
|
+
Converts Information Rules to a templated spreadsheet meant for capturing
|
|
22
|
+
instances based on class definitions in the rules.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
no_rows: number of rows for processing, by default 1000
|
|
26
|
+
auto_identifier_type: type of automatic identifier, by default "index" based, alternative is "uuid" based
|
|
27
|
+
add_drop_down_list: Add drop down selection for columns that contain linking properties, by default True
|
|
28
|
+
|
|
29
|
+
!!! note "no_rows parameter"
|
|
30
|
+
no_rows should be set to the maximum expected number of instances of any of the classes.
|
|
31
|
+
By default, it is set to 1000, increase it accordingly if you have more instances.
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
no_rows: int = 1000,
|
|
38
|
+
auto_identifier_type: Literal["index", "uuid"] = "index",
|
|
39
|
+
add_drop_down_list: bool = True,
|
|
40
|
+
):
|
|
41
|
+
self.no_rows = no_rows
|
|
42
|
+
self.auto_identifier_type = auto_identifier_type
|
|
43
|
+
self.add_drop_down_list = add_drop_down_list
|
|
44
|
+
|
|
45
|
+
def export(
|
|
46
|
+
self,
|
|
47
|
+
rules: InformationRules,
|
|
48
|
+
):
|
|
49
|
+
workbook = Workbook()
|
|
50
|
+
|
|
51
|
+
# Remove default sheet named "Sheet"
|
|
52
|
+
workbook.remove(workbook["Sheet"])
|
|
53
|
+
|
|
54
|
+
for class_, properties in InformationAnalysis(rules).class_property_pairs().items():
|
|
55
|
+
workbook.create_sheet(title=class_.suffix)
|
|
56
|
+
|
|
57
|
+
# Add header rows
|
|
58
|
+
workbook[class_.suffix].append(["identifier", *list(properties.keys())])
|
|
59
|
+
|
|
60
|
+
if self.auto_identifier_type == "uuid":
|
|
61
|
+
_add_uuid_identifiers(workbook, class_.suffix, self.no_rows)
|
|
62
|
+
else:
|
|
63
|
+
# Default to index-based identifier
|
|
64
|
+
_add_index_identifiers(workbook, class_.suffix, self.no_rows)
|
|
65
|
+
|
|
66
|
+
for i, property_ in enumerate(properties.values()):
|
|
67
|
+
if property_.type_ == EntityTypes.object_property and self.add_drop_down_list:
|
|
68
|
+
_add_drop_down_list(
|
|
69
|
+
workbook,
|
|
70
|
+
class_.suffix,
|
|
71
|
+
get_column_letter(i + 2),
|
|
72
|
+
self.no_rows,
|
|
73
|
+
cast(ClassEntity, property_.value_type).suffix,
|
|
74
|
+
"A",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
_adjust_column_width(workbook)
|
|
78
|
+
_set_header_style(workbook)
|
|
79
|
+
|
|
80
|
+
return workbook
|
|
81
|
+
|
|
82
|
+
def export_to_file(self, rules: InformationRules, filepath: Path) -> None:
|
|
83
|
+
"""Exports graph capturing sheet to excel file."""
|
|
84
|
+
data = self.export(rules)
|
|
85
|
+
try:
|
|
86
|
+
data.save(filepath)
|
|
87
|
+
finally:
|
|
88
|
+
data.close()
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _add_index_identifiers(workbook: Workbook, sheet: str, no_rows: int):
|
|
93
|
+
"""Adds index-based auto identifier to a sheet identifier column"""
|
|
94
|
+
for i in range(no_rows):
|
|
95
|
+
workbook[sheet][f"A{i+2}"] = f'=IF(ISBLANK(B{i+2}), "","{sheet}-{i+1}")'
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _add_uuid_identifiers(workbook: Workbook, sheet: str, no_rows: int):
|
|
99
|
+
"""Adds UUID-based auto identifier to a sheet identifier column"""
|
|
100
|
+
for i in range(no_rows):
|
|
101
|
+
workbook[sheet][f"A{i+2}"] = f'=IF(ISBLANK(B{i+2}), "","{sheet}-{uuid.uuid4()}")'
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _add_drop_down_list(
|
|
105
|
+
workbook: Workbook,
|
|
106
|
+
sheet: str,
|
|
107
|
+
column: str,
|
|
108
|
+
no_rows: int,
|
|
109
|
+
value_sheet: str,
|
|
110
|
+
value_column: str,
|
|
111
|
+
):
|
|
112
|
+
"""Adds a drop down list to a column"""
|
|
113
|
+
drop_down_list = DataValidation(
|
|
114
|
+
type="list",
|
|
115
|
+
formula1=f"={value_sheet}!{value_column}$2:{value_column}${no_rows}",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
workbook[sheet].add_data_validation(drop_down_list)
|
|
119
|
+
|
|
120
|
+
for i in range(no_rows):
|
|
121
|
+
drop_down_list.add(workbook[sheet][f"{column}{i+2}"])
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _adjust_column_width(workbook: Workbook):
|
|
125
|
+
"""Adjusts the column width based on the content"""
|
|
126
|
+
for sheet in workbook.sheetnames:
|
|
127
|
+
for cell_tuple in workbook[sheet].columns:
|
|
128
|
+
# Wrong type annotation in openpyxl
|
|
129
|
+
cell = cast(Cell, cell_tuple[0]) # type: ignore[index]
|
|
130
|
+
if cell.value:
|
|
131
|
+
adjusted_width = (len(str(cell.value)) + 5) * 1.2
|
|
132
|
+
workbook[sheet].column_dimensions[cell.column_letter].width = adjusted_width
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _set_header_style(workbook: Workbook):
|
|
136
|
+
"""Sets the header style for all sheets in the workbook"""
|
|
137
|
+
style = NamedStyle(name="header style")
|
|
138
|
+
style.font = Font(bold=True, size=16)
|
|
139
|
+
side = Side(style="thin", color="000000")
|
|
140
|
+
style.border = Border(left=side, right=side, top=side, bottom=side)
|
|
141
|
+
workbook.add_named_style(style)
|
|
142
|
+
|
|
143
|
+
for sheet in workbook.sheetnames:
|
|
144
|
+
for cell_tuple in workbook[sheet].columns:
|
|
145
|
+
# Wrong type annotation in openpyxl
|
|
146
|
+
cell = cast(Cell, cell_tuple[0]) # type: ignore[index]
|
|
147
|
+
workbook[sheet][f"{cell.column_letter}1"].style = style
|
|
148
|
+
if f"{cell.column_letter}1" == "A1":
|
|
149
|
+
workbook[sheet][f"{cell.column_letter}1"].fill = PatternFill("solid", start_color="2FB5F2")
|
|
150
|
+
else:
|
|
151
|
+
workbook[sheet][f"{cell.column_letter}1"].fill = PatternFill("solid", start_color="FFB202")
|
|
152
|
+
workbook[sheet][f"{cell.column_letter}1"].alignment = Alignment(horizontal="center", vertical="center")
|
|
@@ -8,22 +8,23 @@ from pydantic import BaseModel, ConfigDict, ValidationInfo, field_validator
|
|
|
8
8
|
from rdflib import DCTERMS, OWL, RDF, RDFS, XSD, BNode, Graph, Literal, Namespace, URIRef
|
|
9
9
|
from rdflib.collection import Collection as GraphCollection
|
|
10
10
|
|
|
11
|
-
from cognite.neat.
|
|
12
|
-
from cognite.neat.
|
|
13
|
-
from cognite.neat.
|
|
11
|
+
from cognite.neat._constants import DEFAULT_NAMESPACE as NEAT_NAMESPACE
|
|
12
|
+
from cognite.neat._issues import MultiValueError
|
|
13
|
+
from cognite.neat._issues.errors import (
|
|
14
14
|
PropertyDefinitionDuplicatedError,
|
|
15
15
|
)
|
|
16
|
-
from cognite.neat.
|
|
17
|
-
from cognite.neat.
|
|
18
|
-
from cognite.neat.
|
|
19
|
-
from cognite.neat.
|
|
20
|
-
from cognite.neat.
|
|
16
|
+
from cognite.neat._issues.warnings import PropertyDefinitionDuplicatedWarning
|
|
17
|
+
from cognite.neat._rules._constants import EntityTypes
|
|
18
|
+
from cognite.neat._rules.analysis import InformationAnalysis
|
|
19
|
+
from cognite.neat._rules.models.data_types import DataType
|
|
20
|
+
from cognite.neat._rules.models.entities import ClassEntity
|
|
21
|
+
from cognite.neat._rules.models.information import (
|
|
21
22
|
InformationClass,
|
|
22
23
|
InformationMetadata,
|
|
23
24
|
InformationProperty,
|
|
24
25
|
InformationRules,
|
|
25
26
|
)
|
|
26
|
-
from cognite.neat.
|
|
27
|
+
from cognite.neat._utils.rdf_ import remove_namespace_from_uri
|
|
27
28
|
|
|
28
29
|
from ._base import BaseExporter
|
|
29
30
|
from ._validation import duplicated_properties
|
|
@@ -5,7 +5,7 @@ from typing import Literal, get_args
|
|
|
5
5
|
|
|
6
6
|
import yaml
|
|
7
7
|
|
|
8
|
-
from cognite.neat.
|
|
8
|
+
from cognite.neat._rules._shared import VerifiedRules
|
|
9
9
|
|
|
10
10
|
from ._base import BaseExporter
|
|
11
11
|
|
|
@@ -16,8 +16,6 @@ class YAMLExporter(BaseExporter[VerifiedRules, str]):
|
|
|
16
16
|
Args:
|
|
17
17
|
files: The number of files to output. Defaults to "single".
|
|
18
18
|
output: The format to output the rules. Defaults to "yaml".
|
|
19
|
-
output_role: The role to output the rules for. Defaults to None, which means that the role
|
|
20
|
-
of the input rules will be used.
|
|
21
19
|
|
|
22
20
|
The following formats are available:
|
|
23
21
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from collections import defaultdict
|
|
2
2
|
from collections.abc import Iterable
|
|
3
3
|
|
|
4
|
-
from cognite.neat.
|
|
5
|
-
from cognite.neat.
|
|
4
|
+
from cognite.neat._rules.models.entities import ClassEntity
|
|
5
|
+
from cognite.neat._rules.models.information import InformationProperty
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def duplicated_properties(
|
|
@@ -8,9 +8,9 @@ from typing import Any, Generic, Literal
|
|
|
8
8
|
from pydantic import ValidationError
|
|
9
9
|
from rdflib import Namespace
|
|
10
10
|
|
|
11
|
-
from cognite.neat.
|
|
12
|
-
from cognite.neat.
|
|
13
|
-
from cognite.neat.
|
|
11
|
+
from cognite.neat._issues import IssueList, NeatError, NeatWarning
|
|
12
|
+
from cognite.neat._rules._shared import ReadRules, T_InputRules
|
|
13
|
+
from cognite.neat._utils.auxiliary import class_html_doc
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class BaseImporter(ABC, Generic[T_InputRules]):
|
|
@@ -19,24 +19,24 @@ from cognite.client.data_classes.data_modeling.views import (
|
|
|
19
19
|
)
|
|
20
20
|
from cognite.client.utils import ms_to_datetime
|
|
21
21
|
|
|
22
|
-
from cognite.neat.
|
|
23
|
-
from cognite.neat.
|
|
24
|
-
from cognite.neat.
|
|
22
|
+
from cognite.neat._issues import IssueList, NeatIssue
|
|
23
|
+
from cognite.neat._issues.errors import FileTypeUnexpectedError, ResourceMissingIdentifierError, ResourceRetrievalError
|
|
24
|
+
from cognite.neat._issues.warnings import (
|
|
25
25
|
PropertyNotFoundWarning,
|
|
26
26
|
PropertyTypeNotSupportedWarning,
|
|
27
27
|
ResourceNotFoundWarning,
|
|
28
28
|
ResourcesDuplicatedWarning,
|
|
29
29
|
)
|
|
30
|
-
from cognite.neat.
|
|
31
|
-
from cognite.neat.
|
|
32
|
-
from cognite.neat.
|
|
30
|
+
from cognite.neat._rules._shared import ReadRules
|
|
31
|
+
from cognite.neat._rules.importers._base import BaseImporter, _handle_issues
|
|
32
|
+
from cognite.neat._rules.models import (
|
|
33
33
|
DataModelType,
|
|
34
34
|
DMSInputRules,
|
|
35
35
|
DMSSchema,
|
|
36
36
|
SchemaCompleteness,
|
|
37
37
|
)
|
|
38
|
-
from cognite.neat.
|
|
39
|
-
from cognite.neat.
|
|
38
|
+
from cognite.neat._rules.models.data_types import DataType, Enum
|
|
39
|
+
from cognite.neat._rules.models.dms import (
|
|
40
40
|
DMSInputContainer,
|
|
41
41
|
DMSInputEnum,
|
|
42
42
|
DMSInputMetadata,
|
|
@@ -44,7 +44,7 @@ from cognite.neat.rules.models.dms import (
|
|
|
44
44
|
DMSInputProperty,
|
|
45
45
|
DMSInputView,
|
|
46
46
|
)
|
|
47
|
-
from cognite.neat.
|
|
47
|
+
from cognite.neat._rules.models.entities import (
|
|
48
48
|
ClassEntity,
|
|
49
49
|
ContainerEntity,
|
|
50
50
|
DMSNodeEntity,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
from collections import Counter
|
|
2
2
|
from collections.abc import Callable, Sequence
|
|
3
3
|
|
|
4
|
-
from cognite.neat.
|
|
5
|
-
from cognite.neat.
|
|
4
|
+
from cognite.neat._issues import IssueList
|
|
5
|
+
from cognite.neat._issues.errors import (
|
|
6
6
|
PropertyTypeNotSupportedError,
|
|
7
7
|
ResourceMissingIdentifierError,
|
|
8
8
|
ResourceNotFoundError,
|
|
9
9
|
)
|
|
10
|
-
from cognite.neat.
|
|
11
|
-
from cognite.neat.
|
|
10
|
+
from cognite.neat._issues.warnings import PropertyTypeNotSupportedWarning, ResourceTypeNotSupportedWarning
|
|
11
|
+
from cognite.neat._rules.importers._dtdl2rules.spec import (
|
|
12
12
|
DTMI,
|
|
13
13
|
Command,
|
|
14
14
|
CommandV2,
|
|
@@ -25,9 +25,9 @@ from cognite.neat.rules.importers._dtdl2rules.spec import (
|
|
|
25
25
|
Telemetry,
|
|
26
26
|
TelemetryV2,
|
|
27
27
|
)
|
|
28
|
-
from cognite.neat.
|
|
29
|
-
from cognite.neat.
|
|
30
|
-
from cognite.neat.
|
|
28
|
+
from cognite.neat._rules.models.data_types import _DATA_TYPE_BY_NAME, DataType, Json, String
|
|
29
|
+
from cognite.neat._rules.models.entities import ClassEntity
|
|
30
|
+
from cognite.neat._rules.models.information import (
|
|
31
31
|
InformationInputClass,
|
|
32
32
|
InformationInputProperty,
|
|
33
33
|
)
|
|
@@ -5,21 +5,21 @@ from pathlib import Path
|
|
|
5
5
|
|
|
6
6
|
from pydantic import ValidationError
|
|
7
7
|
|
|
8
|
-
from cognite.neat.
|
|
9
|
-
from cognite.neat.
|
|
8
|
+
from cognite.neat._issues import IssueList, NeatIssue
|
|
9
|
+
from cognite.neat._issues.warnings import (
|
|
10
10
|
FileItemNotSupportedWarning,
|
|
11
11
|
FileMissingRequiredFieldWarning,
|
|
12
12
|
FileReadWarning,
|
|
13
13
|
FileTypeUnexpectedWarning,
|
|
14
14
|
NeatValueWarning,
|
|
15
15
|
)
|
|
16
|
-
from cognite.neat.
|
|
17
|
-
from cognite.neat.
|
|
18
|
-
from cognite.neat.
|
|
19
|
-
from cognite.neat.
|
|
20
|
-
from cognite.neat.
|
|
21
|
-
from cognite.neat.
|
|
22
|
-
from cognite.neat.
|
|
16
|
+
from cognite.neat._rules._shared import ReadRules
|
|
17
|
+
from cognite.neat._rules.importers._base import BaseImporter
|
|
18
|
+
from cognite.neat._rules.importers._dtdl2rules.dtdl_converter import _DTDLConverter
|
|
19
|
+
from cognite.neat._rules.importers._dtdl2rules.spec import DTDL_CLS_BY_TYPE_BY_SPEC, DTDLBase, Interface
|
|
20
|
+
from cognite.neat._rules.models import InformationInputRules, SchemaCompleteness
|
|
21
|
+
from cognite.neat._rules.models.information import InformationInputMetadata
|
|
22
|
+
from cognite.neat._utils.text import humanize_collection, to_pascal
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class DTDLImporter(BaseImporter[InformationInputRules]):
|
|
@@ -15,7 +15,7 @@ from typing import TYPE_CHECKING, Any, ClassVar, Literal, TypeAlias
|
|
|
15
15
|
from pydantic import BaseModel, Field, field_validator, model_serializer, model_validator
|
|
16
16
|
from pydantic.fields import FieldInfo
|
|
17
17
|
|
|
18
|
-
from cognite.neat.
|
|
18
|
+
from cognite.neat._rules.models.entities import ClassEntity
|
|
19
19
|
|
|
20
20
|
if TYPE_CHECKING:
|
|
21
21
|
from pydantic.type_adapter import IncEx
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from rdflib import DC, DCTERMS, OWL, RDF, RDFS, SH, SKOS, XSD, Graph, Namespace, URIRef
|
|
4
|
+
|
|
5
|
+
from cognite.neat._issues import IssueList
|
|
6
|
+
from cognite.neat._issues.errors import FileReadError
|
|
7
|
+
from cognite.neat._rules._shared import ReadRules
|
|
8
|
+
from cognite.neat._rules.importers._base import BaseImporter
|
|
9
|
+
from cognite.neat._rules.models.data_types import AnyURI
|
|
10
|
+
from cognite.neat._rules.models.entities import UnknownEntity
|
|
11
|
+
from cognite.neat._rules.models.information import (
|
|
12
|
+
InformationInputRules,
|
|
13
|
+
)
|
|
14
|
+
from cognite.neat._store import NeatGraphStore
|
|
15
|
+
from cognite.neat._utils.rdf_ import get_namespace, uri_to_short_form
|
|
16
|
+
|
|
17
|
+
DEFAULT_NON_EXISTING_NODE_TYPE = AnyURI()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class BaseRDFImporter(BaseImporter[InformationInputRules]):
|
|
21
|
+
"""Baser RDF importers used for all rules importers that are using RDF as input.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
issue_list: Issue list to store issues
|
|
25
|
+
graph: Knowledge graph
|
|
26
|
+
prefix: Prefix to be used for the imported rules
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
issue_list: IssueList,
|
|
32
|
+
graph: Graph,
|
|
33
|
+
prefix: str,
|
|
34
|
+
max_number_of_instance: int,
|
|
35
|
+
non_existing_node_type: UnknownEntity | AnyURI,
|
|
36
|
+
) -> None:
|
|
37
|
+
self.issue_list = issue_list
|
|
38
|
+
self.graph = graph
|
|
39
|
+
self.prefix = prefix
|
|
40
|
+
self.max_number_of_instance = max_number_of_instance
|
|
41
|
+
self.non_existing_node_type = non_existing_node_type
|
|
42
|
+
|
|
43
|
+
@classmethod
|
|
44
|
+
def from_graph_store(
|
|
45
|
+
cls,
|
|
46
|
+
store: NeatGraphStore,
|
|
47
|
+
prefix: str = "neat",
|
|
48
|
+
max_number_of_instance: int = -1,
|
|
49
|
+
non_existing_node_type: UnknownEntity | AnyURI = DEFAULT_NON_EXISTING_NODE_TYPE,
|
|
50
|
+
):
|
|
51
|
+
return cls(
|
|
52
|
+
IssueList(title=f"{cls.__name__} issues"),
|
|
53
|
+
store.graph,
|
|
54
|
+
prefix=prefix,
|
|
55
|
+
max_number_of_instance=max_number_of_instance,
|
|
56
|
+
non_existing_node_type=non_existing_node_type,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def from_file(
|
|
61
|
+
cls,
|
|
62
|
+
filepath: Path,
|
|
63
|
+
prefix: str = "neat",
|
|
64
|
+
max_number_of_instance: int = -1,
|
|
65
|
+
non_existing_node_type: UnknownEntity | AnyURI = DEFAULT_NON_EXISTING_NODE_TYPE,
|
|
66
|
+
):
|
|
67
|
+
issue_list = IssueList(title=f"{cls.__name__} issues")
|
|
68
|
+
|
|
69
|
+
graph = Graph()
|
|
70
|
+
try:
|
|
71
|
+
graph.parse(filepath)
|
|
72
|
+
except Exception as e:
|
|
73
|
+
issue_list.append(FileReadError(filepath, str(e)))
|
|
74
|
+
|
|
75
|
+
# bind key namespaces
|
|
76
|
+
graph.bind("owl", OWL)
|
|
77
|
+
graph.bind("rdf", RDF)
|
|
78
|
+
graph.bind("rdfs", RDFS)
|
|
79
|
+
graph.bind("dcterms", DCTERMS)
|
|
80
|
+
graph.bind("dc", DC)
|
|
81
|
+
graph.bind("skos", SKOS)
|
|
82
|
+
graph.bind("sh", SH)
|
|
83
|
+
graph.bind("xsd", XSD)
|
|
84
|
+
graph.bind("imf", "http://ns.imfid.org/imf#")
|
|
85
|
+
|
|
86
|
+
return cls(
|
|
87
|
+
issue_list,
|
|
88
|
+
graph,
|
|
89
|
+
prefix=prefix,
|
|
90
|
+
max_number_of_instance=max_number_of_instance,
|
|
91
|
+
non_existing_node_type=non_existing_node_type,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def to_rules(
|
|
95
|
+
self,
|
|
96
|
+
) -> ReadRules[InformationInputRules]:
|
|
97
|
+
"""
|
|
98
|
+
Creates `Rules` object from the data for target role.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
if self.issue_list.has_errors:
|
|
102
|
+
# In case there were errors during the import, the to_rules method will return None
|
|
103
|
+
return ReadRules(None, self.issue_list, {})
|
|
104
|
+
|
|
105
|
+
rules_dict = self._to_rules_components()
|
|
106
|
+
|
|
107
|
+
rules = InformationInputRules.load(rules_dict)
|
|
108
|
+
|
|
109
|
+
self._add_transformation(rules)
|
|
110
|
+
|
|
111
|
+
return ReadRules(rules, self.issue_list, {})
|
|
112
|
+
|
|
113
|
+
def _to_rules_components(self) -> dict:
|
|
114
|
+
raise NotImplementedError()
|
|
115
|
+
|
|
116
|
+
@classmethod
|
|
117
|
+
def _add_transformation(cls, rules: InformationInputRules) -> None:
|
|
118
|
+
rules.prefixes = {}
|
|
119
|
+
|
|
120
|
+
rules.prefixes[rules.metadata.prefix] = Namespace(rules.metadata.namespace)
|
|
121
|
+
|
|
122
|
+
class_ref_dict = {}
|
|
123
|
+
for class_ in rules.classes:
|
|
124
|
+
if class_.reference:
|
|
125
|
+
cls._add_uri_namespace_to_prefixes(URIRef(class_.reference), rules.prefixes)
|
|
126
|
+
class_ref_dict[class_.class_] = f"{uri_to_short_form(URIRef(class_.reference), rules.prefixes)}"
|
|
127
|
+
|
|
128
|
+
for property_ in rules.properties:
|
|
129
|
+
if property_.reference:
|
|
130
|
+
cls._add_uri_namespace_to_prefixes(URIRef(property_.reference), rules.prefixes)
|
|
131
|
+
if class_id := class_ref_dict.get(property_.class_, None):
|
|
132
|
+
property_id = f"{uri_to_short_form(URIRef(property_.reference), rules.prefixes)}"
|
|
133
|
+
property_.transformation = f"{class_id}({property_id})"
|
|
134
|
+
|
|
135
|
+
@classmethod
|
|
136
|
+
def _add_uri_namespace_to_prefixes(cls, URI: URIRef, prefixes: dict[str, Namespace]):
|
|
137
|
+
"""Add URI to prefixes dict if not already present
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
URI: URI from which namespace is being extracted
|
|
141
|
+
prefixes: Dict of prefixes and namespaces
|
|
142
|
+
"""
|
|
143
|
+
if Namespace(get_namespace(URI)) not in prefixes.values():
|
|
144
|
+
prefixes[f"prefix-{len(prefixes)+1}"] = Namespace(get_namespace(URI))
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from rdflib import Namespace
|
|
2
2
|
|
|
3
|
-
from cognite.neat.
|
|
4
|
-
from cognite.neat.
|
|
3
|
+
from cognite.neat._rules.importers._rdf._shared import make_metadata_compliant
|
|
4
|
+
from cognite.neat._rules.models import RoleTypes, SchemaCompleteness
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def parse_imf_metadata() -> dict:
|
|
7
|
+
def parse_imf_metadata(prefix: str = "pcaimf") -> dict:
|
|
8
8
|
"""Provide hardcoded IMF metadata to dict.
|
|
9
9
|
|
|
10
10
|
Returns:
|
|
@@ -19,7 +19,7 @@ def parse_imf_metadata() -> dict:
|
|
|
19
19
|
raw_metadata = {
|
|
20
20
|
"role": RoleTypes.information,
|
|
21
21
|
"schema": SchemaCompleteness.partial,
|
|
22
|
-
"prefix":
|
|
22
|
+
"prefix": prefix,
|
|
23
23
|
"namespace": Namespace("https://posccaesar.org/imf/"),
|
|
24
24
|
"version": None,
|
|
25
25
|
"created": None,
|
|
@@ -2,7 +2,7 @@ from typing import cast
|
|
|
2
2
|
|
|
3
3
|
from rdflib import Graph
|
|
4
4
|
|
|
5
|
-
from cognite.neat.
|
|
5
|
+
from cognite.neat._rules.importers._rdf._shared import (
|
|
6
6
|
clean_up_properties,
|
|
7
7
|
make_properties_compliant,
|
|
8
8
|
parse_raw_properties_dataframe,
|
|
@@ -76,6 +76,7 @@ def parse_imf_to_properties(graph: Graph, language: str = "en") -> list[dict]:
|
|
|
76
76
|
BIND(REPLACE(?tempClassSegment, "-", "_") AS ?classSegment)
|
|
77
77
|
BIND(IF(CONTAINS(?classString, "imf/"), CONCAT("IMF_", ?classSegment) , ?classSegment) AS ?class)
|
|
78
78
|
|
|
79
|
+
|
|
79
80
|
# Finding the last segment of the property IRI
|
|
80
81
|
BIND(STR(?imfProperty) AS ?propertyString)
|
|
81
82
|
BIND(REPLACE(?propertyString, "^.*[/#]([^/#]*)$", "$1") AS ?tempPropertySegment)
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
"""This module performs importing of various formats to one of serializations for which
|
|
2
2
|
there are loaders to TransformationRules pydantic class."""
|
|
3
3
|
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
from rdflib import DC, DCTERMS, OWL, RDF, RDFS, SH, SKOS, Graph
|
|
7
|
-
|
|
8
|
-
from cognite.neat.issues import IssueList
|
|
9
|
-
from cognite.neat.issues.errors import FileReadError
|
|
10
|
-
from cognite.neat.rules._shared import ReadRules
|
|
11
|
-
from cognite.neat.rules.importers._base import BaseImporter
|
|
12
|
-
from cognite.neat.rules.models import InformationInputRules
|
|
13
|
-
from cognite.neat.rules.models.data_types import _XSD_TYPES
|
|
4
|
+
from cognite.neat._rules.importers._rdf._base import BaseRDFImporter
|
|
5
|
+
from cognite.neat._rules.models.data_types import _XSD_TYPES
|
|
14
6
|
|
|
15
7
|
from ._imf2classes import parse_imf_to_classes
|
|
16
8
|
from ._imf2metadata import parse_imf_metadata
|
|
17
9
|
from ._imf2properties import parse_imf_to_properties
|
|
18
10
|
|
|
19
11
|
|
|
20
|
-
class IMFImporter(
|
|
12
|
+
class IMFImporter(BaseRDFImporter):
|
|
21
13
|
"""Convert SHACL shapes to tables/ transformation rules / Excel file.
|
|
22
14
|
|
|
23
15
|
Args:
|
|
@@ -36,39 +28,16 @@ class IMFImporter(BaseImporter[InformationInputRules]):
|
|
|
36
28
|
|
|
37
29
|
"""
|
|
38
30
|
|
|
39
|
-
def
|
|
40
|
-
self.filepath = filepath
|
|
41
|
-
|
|
42
|
-
def to_rules(
|
|
31
|
+
def _to_rules_components(
|
|
43
32
|
self,
|
|
44
|
-
) ->
|
|
45
|
-
graph = Graph()
|
|
46
|
-
try:
|
|
47
|
-
graph.parse(self.filepath)
|
|
48
|
-
except Exception as e:
|
|
49
|
-
return ReadRules(None, IssueList([FileReadError(self.filepath, f"Could not parse owl file: {e}")]), {})
|
|
50
|
-
|
|
51
|
-
# bind key namespaces
|
|
52
|
-
graph.bind("owl", OWL)
|
|
53
|
-
graph.bind("rdf", RDF)
|
|
54
|
-
graph.bind("rdfs", RDFS)
|
|
55
|
-
graph.bind("dcterms", DCTERMS)
|
|
56
|
-
graph.bind("dc", DC)
|
|
57
|
-
graph.bind("skos", SKOS)
|
|
58
|
-
graph.bind("sh", SH)
|
|
59
|
-
graph.bind("xsd", _XSD_TYPES)
|
|
60
|
-
graph.bind("imf", "http://ns.imfid.org/imf#")
|
|
61
|
-
|
|
33
|
+
) -> dict:
|
|
62
34
|
components = {
|
|
63
35
|
"Metadata": parse_imf_metadata(),
|
|
64
|
-
"Classes": parse_imf_to_classes(graph),
|
|
65
|
-
"Properties": parse_imf_to_properties(graph),
|
|
36
|
+
"Classes": parse_imf_to_classes(self.graph),
|
|
37
|
+
"Properties": parse_imf_to_properties(self.graph),
|
|
66
38
|
}
|
|
67
39
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
rules = InformationInputRules.load(components)
|
|
71
|
-
return ReadRules(rules, IssueList(), {})
|
|
40
|
+
return make_components_compliant(components)
|
|
72
41
|
|
|
73
42
|
|
|
74
43
|
def make_components_compliant(components: dict) -> dict:
|