cognite-neat 0.123.2__py3-none-any.whl → 0.127.30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cognite/neat/__init__.py +2 -2
- cognite/neat/_client/__init__.py +4 -0
- cognite/neat/_client/api.py +8 -0
- cognite/neat/_client/client.py +21 -0
- cognite/neat/_client/config.py +40 -0
- cognite/neat/_client/containers_api.py +125 -0
- cognite/neat/_client/data_classes.py +44 -0
- cognite/neat/_client/data_model_api.py +115 -0
- cognite/neat/_client/spaces_api.py +115 -0
- cognite/neat/_client/statistics_api.py +24 -0
- cognite/neat/_client/views_api.py +129 -0
- cognite/neat/_config.py +185 -0
- cognite/neat/_data_model/_analysis.py +196 -0
- cognite/neat/_data_model/_constants.py +67 -0
- cognite/neat/_data_model/_identifiers.py +61 -0
- cognite/neat/_data_model/_shared.py +41 -0
- cognite/neat/_data_model/deployer/_differ.py +140 -0
- cognite/neat/_data_model/deployer/_differ_container.py +360 -0
- cognite/neat/_data_model/deployer/_differ_data_model.py +54 -0
- cognite/neat/_data_model/deployer/_differ_space.py +9 -0
- cognite/neat/_data_model/deployer/_differ_view.py +299 -0
- cognite/neat/_data_model/deployer/data_classes.py +529 -0
- cognite/neat/_data_model/deployer/deployer.py +401 -0
- cognite/neat/_data_model/exporters/__init__.py +15 -0
- cognite/neat/_data_model/exporters/_api_exporter.py +37 -0
- cognite/neat/_data_model/exporters/_base.py +24 -0
- cognite/neat/_data_model/exporters/_table_exporter/exporter.py +128 -0
- cognite/neat/_data_model/exporters/_table_exporter/workbook.py +409 -0
- cognite/neat/_data_model/exporters/_table_exporter/writer.py +421 -0
- cognite/neat/_data_model/importers/__init__.py +5 -0
- cognite/neat/_data_model/importers/_api_importer.py +166 -0
- cognite/neat/_data_model/importers/_base.py +16 -0
- cognite/neat/_data_model/importers/_table_importer/data_classes.py +295 -0
- cognite/neat/_data_model/importers/_table_importer/importer.py +192 -0
- cognite/neat/_data_model/importers/_table_importer/reader.py +1063 -0
- cognite/neat/_data_model/importers/_table_importer/source.py +94 -0
- cognite/neat/_data_model/models/conceptual/_base.py +18 -0
- cognite/neat/_data_model/models/conceptual/_concept.py +67 -0
- cognite/neat/_data_model/models/conceptual/_data_model.py +51 -0
- cognite/neat/_data_model/models/conceptual/_properties.py +104 -0
- cognite/neat/_data_model/models/conceptual/_property.py +105 -0
- cognite/neat/_data_model/models/dms/__init__.py +206 -0
- cognite/neat/_data_model/models/dms/_base.py +31 -0
- cognite/neat/_data_model/models/dms/_constants.py +48 -0
- cognite/neat/_data_model/models/dms/_constraints.py +42 -0
- cognite/neat/_data_model/models/dms/_container.py +159 -0
- cognite/neat/_data_model/models/dms/_data_model.py +95 -0
- cognite/neat/_data_model/models/dms/_data_types.py +195 -0
- cognite/neat/_data_model/models/dms/_http.py +28 -0
- cognite/neat/_data_model/models/dms/_indexes.py +30 -0
- cognite/neat/_data_model/models/dms/_limits.py +96 -0
- cognite/neat/_data_model/models/dms/_references.py +135 -0
- cognite/neat/_data_model/models/dms/_schema.py +18 -0
- cognite/neat/_data_model/models/dms/_space.py +48 -0
- cognite/neat/_data_model/models/dms/_types.py +17 -0
- cognite/neat/_data_model/models/dms/_view_filter.py +282 -0
- cognite/neat/_data_model/models/dms/_view_property.py +235 -0
- cognite/neat/_data_model/models/dms/_views.py +210 -0
- cognite/neat/_data_model/models/entities/__init__.py +50 -0
- cognite/neat/_data_model/models/entities/_base.py +101 -0
- cognite/neat/_data_model/models/entities/_constants.py +22 -0
- cognite/neat/_data_model/models/entities/_data_types.py +144 -0
- cognite/neat/_data_model/models/entities/_identifiers.py +61 -0
- cognite/neat/_data_model/models/entities/_parser.py +226 -0
- cognite/neat/_data_model/validation/dms/__init__.py +75 -0
- cognite/neat/_data_model/validation/dms/_ai_readiness.py +364 -0
- cognite/neat/_data_model/validation/dms/_base.py +307 -0
- cognite/neat/_data_model/validation/dms/_connections.py +638 -0
- cognite/neat/_data_model/validation/dms/_consistency.py +57 -0
- cognite/neat/_data_model/validation/dms/_containers.py +174 -0
- cognite/neat/_data_model/validation/dms/_limits.py +420 -0
- cognite/neat/_data_model/validation/dms/_orchestrator.py +222 -0
- cognite/neat/_data_model/validation/dms/_views.py +103 -0
- cognite/neat/_exceptions.py +56 -0
- cognite/neat/_issues.py +68 -0
- cognite/neat/_session/__init__.py +3 -0
- cognite/neat/_session/_html/_render.py +30 -0
- cognite/neat/_session/_html/static/__init__.py +8 -0
- cognite/neat/_session/_html/static/deployment.css +303 -0
- cognite/neat/_session/_html/static/deployment.js +150 -0
- cognite/neat/_session/_html/static/issues.css +211 -0
- cognite/neat/_session/_html/static/issues.js +168 -0
- cognite/neat/_session/_html/static/shared.css +186 -0
- cognite/neat/_session/_html/templates/__init__.py +4 -0
- cognite/neat/_session/_html/templates/deployment.html +75 -0
- cognite/neat/_session/_html/templates/issues.html +45 -0
- cognite/neat/_session/_issues.py +81 -0
- cognite/neat/_session/_opt.py +35 -0
- cognite/neat/_session/_physical.py +261 -0
- cognite/neat/_session/_result.py +236 -0
- cognite/neat/_session/_session.py +88 -0
- cognite/neat/_session/_usage_analytics/__init__.py +0 -0
- cognite/neat/_session/_usage_analytics/_collector.py +131 -0
- cognite/neat/_session/_usage_analytics/_constants.py +23 -0
- cognite/neat/_session/_usage_analytics/_storage.py +240 -0
- cognite/neat/_session/_wrappers.py +82 -0
- cognite/neat/_state_machine/__init__.py +10 -0
- cognite/neat/_state_machine/_base.py +37 -0
- cognite/neat/_state_machine/_states.py +52 -0
- cognite/neat/_store/__init__.py +3 -0
- cognite/neat/_store/_provenance.py +81 -0
- cognite/neat/_store/_store.py +156 -0
- cognite/neat/_utils/__init__.py +0 -0
- cognite/neat/_utils/_reader.py +194 -0
- cognite/neat/_utils/auxiliary.py +39 -0
- cognite/neat/_utils/collection.py +11 -0
- cognite/neat/_utils/http_client/__init__.py +39 -0
- cognite/neat/_utils/http_client/_client.py +245 -0
- cognite/neat/_utils/http_client/_config.py +19 -0
- cognite/neat/_utils/http_client/_data_classes.py +294 -0
- cognite/neat/_utils/http_client/_tracker.py +31 -0
- cognite/neat/_utils/text.py +71 -0
- cognite/neat/_utils/useful_types.py +37 -0
- cognite/neat/_utils/validation.py +154 -0
- cognite/neat/_version.py +1 -1
- cognite/neat/v0/__init__.py +0 -0
- cognite/neat/v0/core/__init__.py +0 -0
- cognite/neat/v0/core/_client/_api/__init__.py +0 -0
- cognite/neat/{core → v0/core}/_client/_api/data_modeling_loaders.py +86 -7
- cognite/neat/{core → v0/core}/_client/_api/neat_instances.py +5 -5
- cognite/neat/{core → v0/core}/_client/_api/schema.py +5 -5
- cognite/neat/{core → v0/core}/_client/_api/statistics.py +3 -3
- cognite/neat/{core → v0/core}/_client/_api_client.py +1 -1
- cognite/neat/v0/core/_client/data_classes/__init__.py +0 -0
- cognite/neat/{core → v0/core}/_client/data_classes/schema.py +4 -4
- cognite/neat/{core → v0/core}/_client/testing.py +1 -1
- cognite/neat/{core → v0/core}/_constants.py +10 -3
- cognite/neat/v0/core/_data_model/__init__.py +0 -0
- cognite/neat/{core → v0/core}/_data_model/_constants.py +9 -6
- cognite/neat/{core → v0/core}/_data_model/_shared.py +5 -5
- cognite/neat/{core → v0/core}/_data_model/analysis/_base.py +12 -8
- cognite/neat/{core → v0/core}/_data_model/exporters/__init__.py +1 -2
- cognite/neat/{core → v0/core}/_data_model/exporters/_base.py +7 -7
- cognite/neat/{core → v0/core}/_data_model/exporters/_data_model2dms.py +9 -9
- cognite/neat/{core → v0/core}/_data_model/exporters/_data_model2excel.py +13 -13
- cognite/neat/{core → v0/core}/_data_model/exporters/_data_model2instance_template.py +4 -4
- cognite/neat/{core/_data_model/exporters/_data_model2ontology.py → v0/core/_data_model/exporters/_data_model2semantic_model.py} +126 -133
- cognite/neat/{core → v0/core}/_data_model/exporters/_data_model2yaml.py +1 -1
- cognite/neat/{core → v0/core}/_data_model/importers/__init__.py +4 -6
- cognite/neat/{core → v0/core}/_data_model/importers/_base.py +5 -5
- cognite/neat/{core → v0/core}/_data_model/importers/_base_file_reader.py +2 -2
- cognite/neat/{core → v0/core}/_data_model/importers/_dict2data_model.py +6 -6
- cognite/neat/{core → v0/core}/_data_model/importers/_dms2data_model.py +19 -16
- cognite/neat/v0/core/_data_model/importers/_graph2data_model.py +299 -0
- cognite/neat/v0/core/_data_model/importers/_rdf/__init__.py +4 -0
- cognite/neat/{core → v0/core}/_data_model/importers/_rdf/_base.py +13 -13
- cognite/neat/{core → v0/core}/_data_model/importers/_rdf/_inference2rdata_model.py +14 -14
- cognite/neat/v0/core/_data_model/importers/_rdf/_owl2data_model.py +144 -0
- cognite/neat/v0/core/_data_model/importers/_rdf/_shared.py +255 -0
- cognite/neat/{core → v0/core}/_data_model/importers/_spreadsheet2data_model.py +94 -13
- cognite/neat/{core → v0/core}/_data_model/models/__init__.py +3 -3
- cognite/neat/{core → v0/core}/_data_model/models/_base_verified.py +5 -5
- cognite/neat/v0/core/_data_model/models/_import_contexts.py +82 -0
- cognite/neat/{core → v0/core}/_data_model/models/_types.py +5 -5
- cognite/neat/{core → v0/core}/_data_model/models/conceptual/_unverified.py +18 -12
- cognite/neat/v0/core/_data_model/models/conceptual/_validation.py +308 -0
- cognite/neat/{core → v0/core}/_data_model/models/conceptual/_verified.py +13 -11
- cognite/neat/{core → v0/core}/_data_model/models/data_types.py +14 -4
- cognite/neat/{core → v0/core}/_data_model/models/entities/__init__.py +6 -0
- cognite/neat/v0/core/_data_model/models/entities/_loaders.py +155 -0
- cognite/neat/{core → v0/core}/_data_model/models/entities/_multi_value.py +2 -2
- cognite/neat/v0/core/_data_model/models/entities/_restrictions.py +230 -0
- cognite/neat/{core → v0/core}/_data_model/models/entities/_single_value.py +121 -16
- cognite/neat/{core → v0/core}/_data_model/models/entities/_types.py +10 -0
- cognite/neat/{core → v0/core}/_data_model/models/mapping/_classic2core.py +5 -5
- cognite/neat/{core → v0/core}/_data_model/models/physical/__init__.py +1 -1
- cognite/neat/{core → v0/core}/_data_model/models/physical/_exporter.py +28 -21
- cognite/neat/{core → v0/core}/_data_model/models/physical/_unverified.py +141 -38
- cognite/neat/{core → v0/core}/_data_model/models/physical/_validation.py +190 -24
- cognite/neat/{core → v0/core}/_data_model/models/physical/_verified.py +135 -15
- cognite/neat/{core → v0/core}/_data_model/transformers/__init__.py +2 -0
- cognite/neat/{core → v0/core}/_data_model/transformers/_base.py +4 -4
- cognite/neat/{core → v0/core}/_data_model/transformers/_converters.py +39 -32
- cognite/neat/{core → v0/core}/_data_model/transformers/_mapping.py +7 -7
- cognite/neat/v0/core/_data_model/transformers/_union_conceptual.py +208 -0
- cognite/neat/{core → v0/core}/_data_model/transformers/_verification.py +7 -7
- cognite/neat/v0/core/_instances/__init__.py +0 -0
- cognite/neat/{core → v0/core}/_instances/_tracking/base.py +1 -1
- cognite/neat/{core → v0/core}/_instances/_tracking/log.py +1 -1
- cognite/neat/{core → v0/core}/_instances/extractors/__init__.py +1 -1
- cognite/neat/{core → v0/core}/_instances/extractors/_base.py +6 -6
- cognite/neat/v0/core/_instances/extractors/_classic_cdf/__init__.py +0 -0
- cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_base.py +7 -7
- cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_classic.py +12 -12
- cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_relationships.py +3 -3
- cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_sequences.py +2 -2
- cognite/neat/{core → v0/core}/_instances/extractors/_dict.py +6 -3
- cognite/neat/{core → v0/core}/_instances/extractors/_dms.py +6 -6
- cognite/neat/{core → v0/core}/_instances/extractors/_dms_graph.py +11 -11
- cognite/neat/{core → v0/core}/_instances/extractors/_mock_graph_generator.py +10 -10
- cognite/neat/{core → v0/core}/_instances/extractors/_raw.py +3 -3
- cognite/neat/{core → v0/core}/_instances/extractors/_rdf_file.py +7 -7
- cognite/neat/{core → v0/core}/_instances/loaders/_base.py +5 -5
- cognite/neat/{core → v0/core}/_instances/loaders/_rdf2dms.py +17 -17
- cognite/neat/{core → v0/core}/_instances/loaders/_rdf_to_instance_space.py +11 -11
- cognite/neat/{core → v0/core}/_instances/queries/_select.py +29 -3
- cognite/neat/{core → v0/core}/_instances/queries/_update.py +1 -1
- cognite/neat/{core → v0/core}/_instances/transformers/_base.py +4 -4
- cognite/neat/{core → v0/core}/_instances/transformers/_classic_cdf.py +6 -6
- cognite/neat/{core → v0/core}/_instances/transformers/_prune_graph.py +4 -4
- cognite/neat/{core → v0/core}/_instances/transformers/_rdfpath.py +1 -1
- cognite/neat/{core → v0/core}/_instances/transformers/_value_type.py +4 -4
- cognite/neat/{core → v0/core}/_issues/_base.py +11 -6
- cognite/neat/{core → v0/core}/_issues/_contextmanagers.py +8 -6
- cognite/neat/{core → v0/core}/_issues/_factory.py +11 -8
- cognite/neat/{core → v0/core}/_issues/errors/__init__.py +3 -1
- cognite/neat/{core → v0/core}/_issues/errors/_external.py +1 -1
- cognite/neat/{core → v0/core}/_issues/errors/_general.py +1 -1
- cognite/neat/{core → v0/core}/_issues/errors/_properties.py +12 -1
- cognite/neat/{core → v0/core}/_issues/errors/_resources.py +2 -2
- cognite/neat/{core → v0/core}/_issues/errors/_wrapper.py +7 -3
- cognite/neat/{core → v0/core}/_issues/warnings/__init__.py +5 -1
- cognite/neat/{core → v0/core}/_issues/warnings/_external.py +1 -1
- cognite/neat/{core → v0/core}/_issues/warnings/_general.py +1 -1
- cognite/neat/{core → v0/core}/_issues/warnings/_models.py +39 -4
- cognite/neat/{core → v0/core}/_issues/warnings/_properties.py +13 -2
- cognite/neat/{core → v0/core}/_issues/warnings/_resources.py +1 -1
- cognite/neat/{core → v0/core}/_issues/warnings/user_modeling.py +1 -1
- cognite/neat/{core → v0/core}/_store/_data_model.py +13 -12
- cognite/neat/{core → v0/core}/_store/_instance.py +45 -12
- cognite/neat/{core → v0/core}/_store/_provenance.py +3 -3
- cognite/neat/{core → v0/core}/_store/exceptions.py +4 -4
- cognite/neat/v0/core/_utils/__init__.py +0 -0
- cognite/neat/{core → v0/core}/_utils/auth.py +1 -1
- cognite/neat/{core → v0/core}/_utils/auxiliary.py +7 -1
- cognite/neat/{core → v0/core}/_utils/collection_.py +2 -2
- cognite/neat/{core → v0/core}/_utils/graph_transformations_report.py +1 -1
- cognite/neat/{core → v0/core}/_utils/rdf_.py +38 -14
- cognite/neat/{core → v0/core}/_utils/reader/_base.py +1 -1
- cognite/neat/{core → v0/core}/_utils/spreadsheet.py +22 -4
- cognite/neat/v0/core/_utils/tarjan.py +44 -0
- cognite/neat/{core → v0/core}/_utils/text.py +1 -1
- cognite/neat/{core → v0/core}/_utils/upload.py +3 -3
- cognite/neat/v0/plugins/__init__.py +4 -0
- cognite/neat/v0/plugins/_base.py +9 -0
- cognite/neat/v0/plugins/_data_model.py +48 -0
- cognite/neat/{plugins → v0/plugins}/_issues.py +1 -1
- cognite/neat/{plugins → v0/plugins}/_manager.py +7 -16
- cognite/neat/{session → v0/session}/_base.py +13 -10
- cognite/neat/{session → v0/session}/_collector.py +1 -1
- cognite/neat/v0/session/_diff.py +51 -0
- cognite/neat/{session → v0/session}/_drop.py +3 -3
- cognite/neat/{session → v0/session}/_explore.py +2 -2
- cognite/neat/{session → v0/session}/_fix.py +2 -2
- cognite/neat/{session → v0/session}/_inspect.py +3 -3
- cognite/neat/{session → v0/session}/_mapping.py +3 -3
- cognite/neat/{session → v0/session}/_plugin.py +4 -5
- cognite/neat/{session → v0/session}/_prepare.py +8 -8
- cognite/neat/{session → v0/session}/_read.py +33 -43
- cognite/neat/{session → v0/session}/_set.py +8 -8
- cognite/neat/{session → v0/session}/_show.py +5 -5
- cognite/neat/{session → v0/session}/_state.py +22 -8
- cognite/neat/{session → v0/session}/_subset.py +4 -4
- cognite/neat/{session → v0/session}/_template.py +11 -11
- cognite/neat/{session → v0/session}/_to.py +12 -12
- cognite/neat/{session → v0/session}/_wizard.py +1 -1
- cognite/neat/{session → v0/session}/engine/_load.py +1 -1
- cognite/neat/{session → v0/session}/exceptions.py +5 -5
- cognite/neat/v1.py +3 -0
- {cognite_neat-0.123.2.dist-info → cognite_neat-0.127.30.dist-info}/METADATA +9 -8
- cognite_neat-0.127.30.dist-info/RECORD +319 -0
- {cognite_neat-0.123.2.dist-info → cognite_neat-0.127.30.dist-info}/WHEEL +1 -1
- cognite/neat/core/_data_model/importers/_dtdl2data_model/__init__.py +0 -3
- cognite/neat/core/_data_model/importers/_dtdl2data_model/_unit_lookup.py +0 -224
- cognite/neat/core/_data_model/importers/_dtdl2data_model/dtdl_converter.py +0 -320
- cognite/neat/core/_data_model/importers/_dtdl2data_model/dtdl_importer.py +0 -155
- cognite/neat/core/_data_model/importers/_dtdl2data_model/spec.py +0 -363
- cognite/neat/core/_data_model/importers/_rdf/__init__.py +0 -5
- cognite/neat/core/_data_model/importers/_rdf/_imf2data_model.py +0 -98
- cognite/neat/core/_data_model/importers/_rdf/_owl2data_model.py +0 -87
- cognite/neat/core/_data_model/importers/_rdf/_shared.py +0 -168
- cognite/neat/core/_data_model/models/conceptual/_validation.py +0 -294
- cognite/neat/core/_data_model/models/entities/_loaders.py +0 -75
- cognite/neat/plugins/__init__.py +0 -3
- cognite/neat/plugins/data_model/importers/__init__.py +0 -5
- cognite/neat/plugins/data_model/importers/_base.py +0 -28
- cognite_neat-0.123.2.dist-info/RECORD +0 -197
- /cognite/neat/{core → _data_model}/__init__.py +0 -0
- /cognite/neat/{core/_client/_api → _data_model/deployer}/__init__.py +0 -0
- /cognite/neat/{core/_client/data_classes → _data_model/exporters/_table_exporter}/__init__.py +0 -0
- /cognite/neat/{core/_data_model → _data_model/importers/_table_importer}/__init__.py +0 -0
- /cognite/neat/{core/_instances → _data_model/models}/__init__.py +0 -0
- /cognite/neat/{core/_instances/extractors/_classic_cdf → _data_model/models/conceptual}/__init__.py +0 -0
- /cognite/neat/{core/_utils → _data_model/validation}/__init__.py +0 -0
- /cognite/neat/{plugins/data_model → _session/_html}/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_client/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_client/data_classes/data_modeling.py +0 -0
- /cognite/neat/{core → v0/core}/_client/data_classes/neat_sequence.py +0 -0
- /cognite/neat/{core → v0/core}/_client/data_classes/statistics.py +0 -0
- /cognite/neat/{core → v0/core}/_config.py +0 -0
- /cognite/neat/{core → v0/core}/_data_model/analysis/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_data_model/catalog/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_data_model/catalog/classic_model.xlsx +0 -0
- /cognite/neat/{core → v0/core}/_data_model/catalog/conceptual-imf-data-model.xlsx +0 -0
- /cognite/neat/{core → v0/core}/_data_model/catalog/hello_world_pump.xlsx +0 -0
- /cognite/neat/{core → v0/core}/_data_model/models/_base_unverified.py +0 -0
- /cognite/neat/{core → v0/core}/_data_model/models/conceptual/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_data_model/models/entities/_constants.py +0 -0
- /cognite/neat/{core → v0/core}/_data_model/models/entities/_wrapped.py +0 -0
- /cognite/neat/{core → v0/core}/_data_model/models/mapping/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_data_model/models/mapping/_classic2core.yaml +0 -0
- /cognite/neat/{core → v0/core}/_instances/_shared.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/_tracking/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -0
- /cognite/neat/{core → v0/core}/_instances/examples/Knowledge-Graph-Nordic44.xml +0 -0
- /cognite/neat/{core → v0/core}/_instances/examples/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
- /cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_assets.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_data_sets.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_events.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_files.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_labels.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/extractors/_classic_cdf/_timeseries.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/loaders/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/queries/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/queries/_base.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/queries/_queries.py +0 -0
- /cognite/neat/{core → v0/core}/_instances/transformers/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_issues/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_issues/formatters.py +0 -0
- /cognite/neat/{core → v0/core}/_shared.py +0 -0
- /cognite/neat/{core → v0/core}/_store/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_utils/io_.py +0 -0
- /cognite/neat/{core → v0/core}/_utils/reader/__init__.py +0 -0
- /cognite/neat/{core → v0/core}/_utils/time_.py +0 -0
- /cognite/neat/{core → v0/core}/_utils/xml_.py +0 -0
- /cognite/neat/{session → v0/session}/__init__.py +0 -0
- /cognite/neat/{session → v0/session}/_experimental.py +0 -0
- /cognite/neat/{session → v0/session}/_state/README.md +0 -0
- /cognite/neat/{session → v0/session}/engine/__init__.py +0 -0
- /cognite/neat/{session → v0/session}/engine/_import.py +0 -0
- /cognite/neat/{session → v0/session}/engine/_interface.py +0 -0
- {cognite_neat-0.123.2.dist-info → cognite_neat-0.127.30.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
import urllib.parse
|
|
3
|
+
import warnings
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from typing import cast
|
|
9
|
+
|
|
10
|
+
from cognite.client.data_classes.data_modeling import DataModelId, DataModelIdentifier
|
|
11
|
+
from rdflib import RDF, RDFS, Namespace, URIRef
|
|
12
|
+
from rdflib import Literal as RdfLiteral
|
|
13
|
+
from rdflib.query import ResultRow
|
|
14
|
+
|
|
15
|
+
from cognite.neat.v0.core._config import GLOBAL_CONFIG
|
|
16
|
+
from cognite.neat.v0.core._constants import NEAT
|
|
17
|
+
from cognite.neat.v0.core._data_model._shared import ImportedDataModel
|
|
18
|
+
from cognite.neat.v0.core._data_model.models import UnverifiedConceptualDataModel
|
|
19
|
+
from cognite.neat.v0.core._data_model.models._import_contexts import GraphContext
|
|
20
|
+
from cognite.neat.v0.core._data_model.models.conceptual import (
|
|
21
|
+
UnverifiedConcept,
|
|
22
|
+
UnverifiedConceptualMetadata,
|
|
23
|
+
UnverifiedConceptualProperty,
|
|
24
|
+
)
|
|
25
|
+
from cognite.neat.v0.core._data_model.models.entities import UnknownEntity
|
|
26
|
+
from cognite.neat.v0.core._issues.errors import NeatValueError
|
|
27
|
+
from cognite.neat.v0.core._issues.warnings import NeatValueWarning
|
|
28
|
+
from cognite.neat.v0.core._store import NeatInstanceStore
|
|
29
|
+
from cognite.neat.v0.core._utils.collection_ import iterate_progress_bar
|
|
30
|
+
from cognite.neat.v0.core._utils.rdf_ import split_uri
|
|
31
|
+
|
|
32
|
+
from ._base import BaseImporter
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Internal helper class
|
|
36
|
+
@dataclass
|
|
37
|
+
class _ReadProperties:
|
|
38
|
+
type_uri: URIRef
|
|
39
|
+
property_uri: URIRef
|
|
40
|
+
value_type: URIRef
|
|
41
|
+
parent_uri: URIRef | None
|
|
42
|
+
max_occurrence: int
|
|
43
|
+
instance_count: int
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class GraphImporter(BaseImporter[UnverifiedConceptualDataModel]):
|
|
47
|
+
"""Infers a data model from the triples in a Graph Store.
|
|
48
|
+
Args:
|
|
49
|
+
store: The graph store to read from.
|
|
50
|
+
data_model_id: The data model id to be used for the imported rules.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
_ORDERED_CONCEPTS_QUERY = """SELECT DISTINCT ?concept (count(?s) as ?instances )
|
|
54
|
+
WHERE { ?s a ?concept }
|
|
55
|
+
group by ?concept order by DESC(?instances)"""
|
|
56
|
+
|
|
57
|
+
_TYPE_PARENT_QUERY = f"""SELECT ?parent ?type
|
|
58
|
+
WHERE {{ ?s a ?type .
|
|
59
|
+
?type <{RDFS.subClassOf}> ?parent }}"""
|
|
60
|
+
|
|
61
|
+
_PROPERTIES_QUERY = """SELECT DISTINCT ?property ?valueType
|
|
62
|
+
WHERE {{
|
|
63
|
+
?s a <{type}> .
|
|
64
|
+
?s ?property ?object .
|
|
65
|
+
OPTIONAL {{ ?object a ?objectType }}
|
|
66
|
+
BIND(
|
|
67
|
+
IF(
|
|
68
|
+
isLiteral(?object), datatype(?object),
|
|
69
|
+
IF(BOUND(?objectType), ?objectType, <{unknown_type}>)
|
|
70
|
+
) AS ?valueType
|
|
71
|
+
)
|
|
72
|
+
}}"""
|
|
73
|
+
|
|
74
|
+
_MAX_OCCURRENCE_QUERY = """SELECT (MAX(?count) AS ?maxCount)
|
|
75
|
+
WHERE {{
|
|
76
|
+
{{
|
|
77
|
+
SELECT ?subject (COUNT(?object) AS ?count)
|
|
78
|
+
WHERE {{
|
|
79
|
+
?subject a <{type}> .
|
|
80
|
+
?subject <{property}> ?object .
|
|
81
|
+
}}
|
|
82
|
+
GROUP BY ?subject
|
|
83
|
+
}}
|
|
84
|
+
}}"""
|
|
85
|
+
|
|
86
|
+
def __init__(
|
|
87
|
+
self,
|
|
88
|
+
store: NeatInstanceStore,
|
|
89
|
+
data_model_id: DataModelIdentifier = ("neat_space", "NeatInferredDataModel", "v1"),
|
|
90
|
+
) -> None:
|
|
91
|
+
self.store = store
|
|
92
|
+
self.data_model_id = DataModelId.load(data_model_id)
|
|
93
|
+
if self.data_model_id.version is None:
|
|
94
|
+
raise NeatValueError("Version is required when setting a Data Model ID")
|
|
95
|
+
|
|
96
|
+
def to_data_model(self) -> ImportedDataModel[UnverifiedConceptualDataModel]:
|
|
97
|
+
metadata = self._create_default_metadata()
|
|
98
|
+
if not self.store.queries.select.has_data():
|
|
99
|
+
warnings.warn(NeatValueWarning("Cannot infer data model. No data found in the graph."), stacklevel=2)
|
|
100
|
+
return ImportedDataModel(UnverifiedConceptualDataModel(metadata, [], [], {}), None)
|
|
101
|
+
|
|
102
|
+
parent_by_child = self._read_parent_by_child_from_graph()
|
|
103
|
+
count_by_type = self._read_types_with_counts_from_graph()
|
|
104
|
+
if not count_by_type:
|
|
105
|
+
warnings.warn(
|
|
106
|
+
NeatValueWarning("Cannot infer data model. No RDF.type triples found in the graph."), stacklevel=2
|
|
107
|
+
)
|
|
108
|
+
return ImportedDataModel(UnverifiedConceptualDataModel(metadata, [], [], {}), None)
|
|
109
|
+
|
|
110
|
+
read_properties = self._read_concept_properties_from_graph(count_by_type, parent_by_child)
|
|
111
|
+
|
|
112
|
+
prefixes: dict[str, Namespace] = {}
|
|
113
|
+
concepts, properties = self._create_concepts_properties(read_properties, prefixes)
|
|
114
|
+
|
|
115
|
+
return ImportedDataModel(
|
|
116
|
+
UnverifiedConceptualDataModel(
|
|
117
|
+
metadata=metadata,
|
|
118
|
+
concepts=concepts,
|
|
119
|
+
properties=properties,
|
|
120
|
+
prefixes=prefixes,
|
|
121
|
+
),
|
|
122
|
+
context=GraphContext({"inferred_from": count_by_type}),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
def _read_parent_by_child_from_graph(self) -> dict[URIRef, URIRef]:
|
|
126
|
+
parent_by_child: dict[URIRef, URIRef] = {}
|
|
127
|
+
for result_row in self.store.dataset.query(self._TYPE_PARENT_QUERY):
|
|
128
|
+
parent_uri, child_uri = cast(tuple[URIRef, URIRef], result_row)
|
|
129
|
+
parent_by_child[child_uri] = parent_uri
|
|
130
|
+
return parent_by_child
|
|
131
|
+
|
|
132
|
+
def _read_types_with_counts_from_graph(self) -> dict[URIRef, int]:
|
|
133
|
+
count_by_type: dict[URIRef, int] = {}
|
|
134
|
+
# Reads all types and their instance counts from the graph
|
|
135
|
+
for result_row in self.store.dataset.query(self._ORDERED_CONCEPTS_QUERY):
|
|
136
|
+
type_uri, instance_count_literal = cast(tuple[URIRef, RdfLiteral], result_row)
|
|
137
|
+
count_by_type[type_uri] = instance_count_literal.toPython()
|
|
138
|
+
return count_by_type
|
|
139
|
+
|
|
140
|
+
def _read_concept_properties_from_graph(
|
|
141
|
+
self, count_by_type: dict[URIRef, int], parent_by_child: dict[URIRef, URIRef]
|
|
142
|
+
) -> list[_ReadProperties]:
|
|
143
|
+
read_properties: list[_ReadProperties] = []
|
|
144
|
+
|
|
145
|
+
total_instance_count = sum(count_by_type.values())
|
|
146
|
+
iterable = count_by_type.items()
|
|
147
|
+
if GLOBAL_CONFIG.use_iterate_bar_threshold and total_instance_count > GLOBAL_CONFIG.use_iterate_bar_threshold:
|
|
148
|
+
iterable = iterate_progress_bar(iterable, len(count_by_type), "Inferring types...") # type: ignore[assignment]
|
|
149
|
+
|
|
150
|
+
for type_uri, instance_count in iterable:
|
|
151
|
+
property_query = self._PROPERTIES_QUERY.format(type=type_uri, unknown_type=NEAT.UnknownType)
|
|
152
|
+
for result_row in self.store.dataset.query(property_query):
|
|
153
|
+
property_uri, value_type_uri = cast(tuple[URIRef, URIRef], result_row)
|
|
154
|
+
if property_uri == RDF.type:
|
|
155
|
+
continue
|
|
156
|
+
occurrence_query = self._MAX_OCCURRENCE_QUERY.format(type=type_uri, property=property_uri)
|
|
157
|
+
max_occurrence = 1 # default value
|
|
158
|
+
# We know that the _MAX_OCCURRENCE_QUERY will return a ResultRow
|
|
159
|
+
occurrence_results = list(cast(ResultRow, self.store.dataset.query(occurrence_query)))
|
|
160
|
+
if occurrence_results and occurrence_results[0] and occurrence_results[0][0]:
|
|
161
|
+
max_occurrence_literal = cast(RdfLiteral, occurrence_results[0][0])
|
|
162
|
+
max_occurrence = int(max_occurrence_literal.toPython())
|
|
163
|
+
read_properties.append(
|
|
164
|
+
_ReadProperties(
|
|
165
|
+
type_uri=type_uri,
|
|
166
|
+
property_uri=property_uri,
|
|
167
|
+
parent_uri=parent_by_child.get(type_uri),
|
|
168
|
+
value_type=value_type_uri,
|
|
169
|
+
max_occurrence=max_occurrence,
|
|
170
|
+
instance_count=instance_count,
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
return read_properties
|
|
174
|
+
|
|
175
|
+
def _create_concepts_properties(
|
|
176
|
+
self, read_properties: list[_ReadProperties], prefixes: dict[str, Namespace]
|
|
177
|
+
) -> tuple[list[UnverifiedConcept], list[UnverifiedConceptualProperty]]:
|
|
178
|
+
concepts: list[UnverifiedConcept] = []
|
|
179
|
+
properties: list[UnverifiedConceptualProperty] = []
|
|
180
|
+
|
|
181
|
+
# Help for IDE
|
|
182
|
+
type_uri: URIRef
|
|
183
|
+
parent_uri: URIRef
|
|
184
|
+
for parent_uri, parent_concepts_properties_iterable in itertools.groupby(
|
|
185
|
+
sorted(read_properties, key=lambda x: x.parent_uri or NEAT.EmptyType),
|
|
186
|
+
key=lambda x: x.parent_uri or NEAT.EmptyType,
|
|
187
|
+
):
|
|
188
|
+
parent_str: str | None = None
|
|
189
|
+
if parent_uri != NEAT.EmptyType:
|
|
190
|
+
parent_str, parent_cls = self._create_concept(parent_uri, set_instance_source=False, prefixes=prefixes)
|
|
191
|
+
concepts.append(parent_cls)
|
|
192
|
+
|
|
193
|
+
properties_by_concept_by_property = self._get_properties_by_concept_by_property(
|
|
194
|
+
parent_concepts_properties_iterable
|
|
195
|
+
)
|
|
196
|
+
for type_uri, properties_by_property_uri in properties_by_concept_by_property.items():
|
|
197
|
+
concept_str, concept = self._create_concept(
|
|
198
|
+
type_uri, set_instance_source=True, prefixes=prefixes, implements=parent_str
|
|
199
|
+
)
|
|
200
|
+
concepts.append(concept)
|
|
201
|
+
for property_uri, read_properties in properties_by_property_uri.items():
|
|
202
|
+
namespace, property_suffix = split_uri(property_uri)
|
|
203
|
+
(self._add_uri_namespace_to_prefixes(namespace, prefixes),)
|
|
204
|
+
properties.append(
|
|
205
|
+
self._create_property(
|
|
206
|
+
read_properties, concept_str, property_uri, urllib.parse.unquote(property_suffix), prefixes
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
return concepts, properties
|
|
210
|
+
|
|
211
|
+
@staticmethod
|
|
212
|
+
def _get_properties_by_concept_by_property(
|
|
213
|
+
parent_concept_properties_iterable: Iterable[_ReadProperties],
|
|
214
|
+
) -> dict[URIRef, dict[URIRef, list[_ReadProperties]]]:
|
|
215
|
+
properties_by_concept_by_property: dict[URIRef, dict[URIRef, list[_ReadProperties]]] = {}
|
|
216
|
+
for concept_uri, concept_properties_iterable in itertools.groupby(
|
|
217
|
+
sorted(parent_concept_properties_iterable, key=lambda x: x.type_uri), key=lambda x: x.type_uri
|
|
218
|
+
):
|
|
219
|
+
properties_by_concept_by_property[concept_uri] = defaultdict(list)
|
|
220
|
+
for read_prop in concept_properties_iterable:
|
|
221
|
+
properties_by_concept_by_property[concept_uri][read_prop.property_uri].append(read_prop)
|
|
222
|
+
return properties_by_concept_by_property
|
|
223
|
+
|
|
224
|
+
@classmethod
|
|
225
|
+
def _create_concept(
|
|
226
|
+
cls, type_uri: URIRef, set_instance_source: bool, prefixes: dict[str, Namespace], implements: str | None = None
|
|
227
|
+
) -> tuple[str, UnverifiedConcept]:
|
|
228
|
+
namespace, suffix = split_uri(type_uri)
|
|
229
|
+
cls._add_uri_namespace_to_prefixes(namespace, prefixes)
|
|
230
|
+
concept_str = urllib.parse.unquote(suffix)
|
|
231
|
+
return concept_str, UnverifiedConcept(
|
|
232
|
+
concept=concept_str, implements=implements, instance_source=type_uri if set_instance_source else None
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
def _create_property(
|
|
236
|
+
self,
|
|
237
|
+
read_properties: list[_ReadProperties],
|
|
238
|
+
concept_str: str,
|
|
239
|
+
property_uri: URIRef,
|
|
240
|
+
property_id: str,
|
|
241
|
+
prefixes: dict[str, Namespace],
|
|
242
|
+
) -> UnverifiedConceptualProperty:
|
|
243
|
+
first = read_properties[0]
|
|
244
|
+
value_type = self._get_value_type(read_properties, prefixes)
|
|
245
|
+
return UnverifiedConceptualProperty(
|
|
246
|
+
concept=concept_str,
|
|
247
|
+
property_=property_id,
|
|
248
|
+
max_count=first.max_occurrence,
|
|
249
|
+
value_type=value_type,
|
|
250
|
+
instance_source=[property_uri],
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
@classmethod
|
|
254
|
+
def _get_value_type(
|
|
255
|
+
cls, read_properties: list[_ReadProperties], prefixes: dict[str, Namespace]
|
|
256
|
+
) -> str | UnknownEntity:
|
|
257
|
+
value_types = {prop.value_type for prop in read_properties}
|
|
258
|
+
if len(value_types) == 1:
|
|
259
|
+
uri_ref = value_types.pop()
|
|
260
|
+
if uri_ref == NEAT.UnknownType:
|
|
261
|
+
return UnknownEntity()
|
|
262
|
+
namespace, suffix = split_uri(uri_ref)
|
|
263
|
+
cls._add_uri_namespace_to_prefixes(namespace, prefixes)
|
|
264
|
+
return suffix
|
|
265
|
+
uri_refs: list[str] = []
|
|
266
|
+
for uri_ref in value_types:
|
|
267
|
+
if uri_ref == NEAT.UnknownType:
|
|
268
|
+
return UnknownEntity()
|
|
269
|
+
namespace, suffix = split_uri(uri_ref)
|
|
270
|
+
cls._add_uri_namespace_to_prefixes(namespace, prefixes)
|
|
271
|
+
uri_refs.append(suffix)
|
|
272
|
+
# Sort the URIs to ensure deterministic output
|
|
273
|
+
return ", ".join(sorted(uri_refs))
|
|
274
|
+
|
|
275
|
+
def _create_default_metadata(self) -> UnverifiedConceptualMetadata:
|
|
276
|
+
now = datetime.now(timezone.utc)
|
|
277
|
+
name = self.data_model_id.external_id.replace("_", " ").title()
|
|
278
|
+
return UnverifiedConceptualMetadata(
|
|
279
|
+
space=self.data_model_id.space,
|
|
280
|
+
external_id=self.data_model_id.external_id,
|
|
281
|
+
# Validated in the constructor
|
|
282
|
+
version=cast(str, self.data_model_id.version),
|
|
283
|
+
name=name,
|
|
284
|
+
creator="NEAT",
|
|
285
|
+
created=now,
|
|
286
|
+
updated=now,
|
|
287
|
+
description="Inferred model from knowledge graph",
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
@classmethod
|
|
291
|
+
def _add_uri_namespace_to_prefixes(cls, namespace: str, prefixes: dict[str, Namespace]) -> None:
|
|
292
|
+
"""Add URI to prefixes dict if not already present
|
|
293
|
+
|
|
294
|
+
Args:
|
|
295
|
+
URI: URI from which namespace is being extracted
|
|
296
|
+
prefixes: Dict of prefixes and namespaces
|
|
297
|
+
"""
|
|
298
|
+
if Namespace(namespace) not in prefixes.values():
|
|
299
|
+
prefixes[f"prefix_{len(prefixes) + 1}"] = Namespace(namespace)
|
|
@@ -6,20 +6,20 @@ from cognite.client import data_modeling as dm
|
|
|
6
6
|
from rdflib import Graph, Namespace, URIRef
|
|
7
7
|
from typing_extensions import Self
|
|
8
8
|
|
|
9
|
-
from cognite.neat.core._constants import get_default_prefixes_and_namespaces
|
|
10
|
-
from cognite.neat.core._data_model._shared import ImportedDataModel
|
|
11
|
-
from cognite.neat.core._data_model.importers._base import BaseImporter
|
|
12
|
-
from cognite.neat.core._data_model.models._base_verified import RoleTypes
|
|
13
|
-
from cognite.neat.core._data_model.models.conceptual import (
|
|
9
|
+
from cognite.neat.v0.core._constants import get_default_prefixes_and_namespaces
|
|
10
|
+
from cognite.neat.v0.core._data_model._shared import ImportedDataModel
|
|
11
|
+
from cognite.neat.v0.core._data_model.importers._base import BaseImporter
|
|
12
|
+
from cognite.neat.v0.core._data_model.models._base_verified import RoleTypes
|
|
13
|
+
from cognite.neat.v0.core._data_model.models.conceptual import (
|
|
14
14
|
UnverifiedConceptualDataModel,
|
|
15
15
|
)
|
|
16
|
-
from cognite.neat.core._data_model.models.data_types import AnyURI
|
|
17
|
-
from cognite.neat.core._data_model.models.entities import UnknownEntity
|
|
18
|
-
from cognite.neat.core._issues import IssueList, MultiValueError
|
|
19
|
-
from cognite.neat.core._issues.errors import FileReadError
|
|
20
|
-
from cognite.neat.core._issues.errors._general import NeatValueError
|
|
21
|
-
from cognite.neat.core._store import NeatInstanceStore
|
|
22
|
-
from cognite.neat.core._utils.rdf_ import get_namespace
|
|
16
|
+
from cognite.neat.v0.core._data_model.models.data_types import AnyURI
|
|
17
|
+
from cognite.neat.v0.core._data_model.models.entities import UnknownEntity
|
|
18
|
+
from cognite.neat.v0.core._issues import IssueList, MultiValueError
|
|
19
|
+
from cognite.neat.v0.core._issues.errors import FileReadError
|
|
20
|
+
from cognite.neat.v0.core._issues.errors._general import NeatValueError
|
|
21
|
+
from cognite.neat.v0.core._store import NeatInstanceStore
|
|
22
|
+
from cognite.neat.v0.core._utils.rdf_ import get_namespace
|
|
23
23
|
|
|
24
24
|
DEFAULT_NON_EXISTING_NODE_TYPE = AnyURI()
|
|
25
25
|
|
|
@@ -130,7 +130,7 @@ class BaseRDFImporter(BaseImporter[UnverifiedConceptualDataModel]):
|
|
|
130
130
|
|
|
131
131
|
data_model = UnverifiedConceptualDataModel.load(data_model_dict)
|
|
132
132
|
self.issue_list.trigger_warnings()
|
|
133
|
-
return ImportedDataModel(data_model
|
|
133
|
+
return ImportedDataModel(data_model)
|
|
134
134
|
|
|
135
135
|
def _to_data_model_components(self) -> dict:
|
|
136
136
|
raise NotImplementedError()
|
|
@@ -10,25 +10,25 @@ from cognite.client import data_modeling as dm
|
|
|
10
10
|
from rdflib import RDF, RDFS, Graph, Namespace, URIRef
|
|
11
11
|
from rdflib import Literal as RdfLiteral
|
|
12
12
|
|
|
13
|
-
from cognite.neat.core._config import GLOBAL_CONFIG
|
|
14
|
-
from cognite.neat.core._constants import NEAT, get_default_prefixes_and_namespaces
|
|
15
|
-
from cognite.neat.core._data_model.analysis import DataModelAnalysis
|
|
16
|
-
from cognite.neat.core._data_model.models import ConceptualDataModel, data_types
|
|
17
|
-
from cognite.neat.core._data_model.models.conceptual import (
|
|
13
|
+
from cognite.neat.v0.core._config import GLOBAL_CONFIG
|
|
14
|
+
from cognite.neat.v0.core._constants import NEAT, get_default_prefixes_and_namespaces
|
|
15
|
+
from cognite.neat.v0.core._data_model.analysis import DataModelAnalysis
|
|
16
|
+
from cognite.neat.v0.core._data_model.models import ConceptualDataModel, data_types
|
|
17
|
+
from cognite.neat.v0.core._data_model.models.conceptual import (
|
|
18
18
|
Concept,
|
|
19
19
|
ConceptualMetadata,
|
|
20
20
|
UnverifiedConcept,
|
|
21
21
|
UnverifiedConceptualProperty,
|
|
22
22
|
)
|
|
23
|
-
from cognite.neat.core._data_model.models.data_types import AnyURI
|
|
24
|
-
from cognite.neat.core._data_model.models.entities._single_value import UnknownEntity
|
|
25
|
-
from cognite.neat.core._issues import IssueList
|
|
26
|
-
from cognite.neat.core._issues.warnings import PropertyValueTypeUndefinedWarning
|
|
27
|
-
from cognite.neat.core._store import NeatInstanceStore
|
|
28
|
-
from cognite.neat.core._store._provenance import INSTANCES_ENTITY
|
|
29
|
-
from cognite.neat.core._utils.collection_ import iterate_progress_bar
|
|
30
|
-
from cognite.neat.core._utils.rdf_ import remove_namespace_from_uri, uri_to_short_form
|
|
31
|
-
from cognite.neat.core._utils.text import NamingStandardization
|
|
23
|
+
from cognite.neat.v0.core._data_model.models.data_types import AnyURI
|
|
24
|
+
from cognite.neat.v0.core._data_model.models.entities._single_value import UnknownEntity
|
|
25
|
+
from cognite.neat.v0.core._issues import IssueList
|
|
26
|
+
from cognite.neat.v0.core._issues.warnings import PropertyValueTypeUndefinedWarning
|
|
27
|
+
from cognite.neat.v0.core._store import NeatInstanceStore
|
|
28
|
+
from cognite.neat.v0.core._store._provenance import INSTANCES_ENTITY
|
|
29
|
+
from cognite.neat.v0.core._utils.collection_ import iterate_progress_bar
|
|
30
|
+
from cognite.neat.v0.core._utils.rdf_ import remove_namespace_from_uri, uri_to_short_form
|
|
31
|
+
from cognite.neat.v0.core._utils.text import NamingStandardization
|
|
32
32
|
|
|
33
33
|
from ._base import DEFAULT_NON_EXISTING_NODE_TYPE, BaseRDFImporter
|
|
34
34
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""This module performs importing of various formats to one of serializations for which
|
|
2
|
+
there are loaders to data model pydantic class."""
|
|
3
|
+
|
|
4
|
+
from cognite.neat.v0.core._data_model.importers._rdf._base import BaseRDFImporter
|
|
5
|
+
from cognite.neat.v0.core._data_model.importers._rdf._shared import (
|
|
6
|
+
parse_concepts,
|
|
7
|
+
parse_properties,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
CLASSES_QUERY = """SELECT ?concept ?name ?description ?implements
|
|
11
|
+
WHERE {{
|
|
12
|
+
|
|
13
|
+
?concept a owl:Class .
|
|
14
|
+
OPTIONAL {{?concept rdfs:subClassOf ?implements }}.
|
|
15
|
+
OPTIONAL {{?concept rdfs:label|skos:prefLabel ?name }}.
|
|
16
|
+
OPTIONAL {{?concept rdfs:comment|skos:definition ?description}} .
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
FILTER (!isBlank(?concept ))
|
|
20
|
+
FILTER (!bound(?implements) || !isBlank(?implements))
|
|
21
|
+
|
|
22
|
+
FILTER (!bound(?name) || LANG(?name) = "" || LANGMATCHES(LANG(?name), "{language}"))
|
|
23
|
+
FILTER (!bound(?description) || LANG(?description) = "" || LANGMATCHES(LANG(?description), "{language}"))
|
|
24
|
+
|
|
25
|
+
}}
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
CLASSES_QUERY_PARAMETERS = {"concept", "name", "description", "implements"}
|
|
29
|
+
|
|
30
|
+
PROPERTIES_QUERY = """ SELECT ?concept ?property_ ?name ?description ?value_type ?min_count ?max_count ?default
|
|
31
|
+
WHERE {{
|
|
32
|
+
?property_ a ?property_Type.
|
|
33
|
+
FILTER (?property_Type IN (owl:ObjectProperty, owl:DatatypeProperty ) )
|
|
34
|
+
|
|
35
|
+
# --- 1. Explicit Domain Discovery ---
|
|
36
|
+
|
|
37
|
+
# A. Handling owl:domain when it is expressed as owl restriction
|
|
38
|
+
OPTIONAL {{
|
|
39
|
+
?property_ rdfs:domain ?domain_exp_node .
|
|
40
|
+
FILTER(isBlank(?domain_exp_node))
|
|
41
|
+
?domain_exp_node owl:unionOf|owl:intersectionOf ?exp_concepts_list .
|
|
42
|
+
?exp_concepts_list rdf:rest*/rdf:first ?explicit_concept.
|
|
43
|
+
}}
|
|
44
|
+
|
|
45
|
+
# B. Handling the domain when it is a single concept
|
|
46
|
+
OPTIONAL {{
|
|
47
|
+
?property_ rdfs:domain ?domain_exp_node .
|
|
48
|
+
FILTER(!isBlank(?domain_exp_node))
|
|
49
|
+
BIND(?domain_exp_node AS ?explicit_concept)
|
|
50
|
+
}}
|
|
51
|
+
|
|
52
|
+
# --- 2. Inherited Domain Discovery (Fallback) ---
|
|
53
|
+
|
|
54
|
+
# C. Handling inherited domain when parent domain is a restriction
|
|
55
|
+
OPTIONAL {{
|
|
56
|
+
?property_ rdfs:subPropertyOf ?parent_property .
|
|
57
|
+
?parent_property rdfs:domain ?parent_domain_node .
|
|
58
|
+
FILTER(isBlank(?parent_domain_node))
|
|
59
|
+
?parent_domain_node owl:unionOf|owl:intersectionOf ?parent_concepts_list .
|
|
60
|
+
?parent_concepts_list rdf:rest*/rdf:first ?inherited_concept.
|
|
61
|
+
}}
|
|
62
|
+
|
|
63
|
+
# D. Handling inherited domain when parent domain is a single concept
|
|
64
|
+
OPTIONAL {{
|
|
65
|
+
?property_ rdfs:subPropertyOf ?parent_property .
|
|
66
|
+
?parent_property rdfs:domain ?parent_domain_node .
|
|
67
|
+
FILTER(!isBlank(?parent_domain_node))
|
|
68
|
+
BIND(?parent_domain_node AS ?inherited_concept)
|
|
69
|
+
}}
|
|
70
|
+
|
|
71
|
+
# Final Concept Assignment with Priority ---
|
|
72
|
+
# COALESCE prioritizes ?explicit_concept over ?inherited_concept
|
|
73
|
+
BIND(COALESCE(?explicit_concept, ?inherited_concept) AS ?concept)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# Handling owl:range when it is expressed as owl restriction
|
|
77
|
+
OPTIONAL {{
|
|
78
|
+
?property_ rdfs:range ?range .
|
|
79
|
+
FILTER(isBlank(?range))
|
|
80
|
+
?range owl:unionOf|owl:intersectionOf ?value_types .
|
|
81
|
+
?value_types rdf:rest*/rdf:first ?value_type.
|
|
82
|
+
}}
|
|
83
|
+
|
|
84
|
+
# Handling the range when it is a single concept
|
|
85
|
+
OPTIONAL {{
|
|
86
|
+
?property_ rdfs:range ?range .
|
|
87
|
+
FILTER(!isBlank(?range))
|
|
88
|
+
BIND(?range AS ?value_type)
|
|
89
|
+
}}
|
|
90
|
+
|
|
91
|
+
OPTIONAL {{?property_ rdfs:label|skos:prefLabel ?name }}.
|
|
92
|
+
OPTIONAL {{?property_ rdfs:comment|skos:definition ?description}}.
|
|
93
|
+
OPTIONAL {{?property_ owl:maxCardinality ?max_count}}.
|
|
94
|
+
OPTIONAL {{?property_ owl:minCardinality ?min_count}}.
|
|
95
|
+
|
|
96
|
+
# FILTERS
|
|
97
|
+
FILTER (!isBlank(?property_))
|
|
98
|
+
FILTER (!bound(?name) || LANG(?name) = "" || LANGMATCHES(LANG(?name), "{language}"))
|
|
99
|
+
FILTER (!bound(?description) || LANG(?description) = "" || LANGMATCHES(LANG(?description), "{language}"))
|
|
100
|
+
}}
|
|
101
|
+
"""
|
|
102
|
+
PROPERTIES_QUERY_PARAMETERS = {
|
|
103
|
+
"concept",
|
|
104
|
+
"property_",
|
|
105
|
+
"name",
|
|
106
|
+
"description",
|
|
107
|
+
"value_type",
|
|
108
|
+
"min_count",
|
|
109
|
+
"max_count",
|
|
110
|
+
"default",
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class OWLImporter(BaseRDFImporter):
|
|
115
|
+
"""Convert OWL ontology to unverified data model.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
filepath: Path to OWL ontology
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
def _to_data_model_components(
|
|
122
|
+
self,
|
|
123
|
+
) -> dict:
|
|
124
|
+
concepts, issue_list = parse_concepts(
|
|
125
|
+
self.graph, CLASSES_QUERY, CLASSES_QUERY_PARAMETERS, self.language, self.issue_list
|
|
126
|
+
)
|
|
127
|
+
self.issue_list = issue_list
|
|
128
|
+
|
|
129
|
+
properties, issue_list = parse_properties(
|
|
130
|
+
self.graph, PROPERTIES_QUERY, PROPERTIES_QUERY_PARAMETERS, self.language, self.issue_list
|
|
131
|
+
)
|
|
132
|
+
self.issue_list = issue_list
|
|
133
|
+
|
|
134
|
+
components = {
|
|
135
|
+
"Metadata": self._metadata,
|
|
136
|
+
"Concepts": list(concepts.values()) if concepts else [],
|
|
137
|
+
"Properties": list(properties.values()) if properties else [],
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return components
|
|
141
|
+
|
|
142
|
+
@property
|
|
143
|
+
def description(self) -> str:
|
|
144
|
+
return f"Ontology {self.source_name} read as unverified data model"
|