cognite-neat 0.110.0__tar.gz → 0.111.0__tar.gz
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-0.110.0 → cognite_neat-0.111.0}/PKG-INFO +1 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_alpha.py +6 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/_api/schema.py +26 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/data_classes/schema.py +1 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_constants.py +4 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/__init__.py +4 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_base.py +8 -16
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_classic.py +39 -9
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_relationships.py +23 -17
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_sequences.py +15 -17
- cognite_neat-0.111.0/cognite/neat/_graph/extractors/_dict.py +102 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_dms.py +27 -40
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_dms_graph.py +30 -3
- cognite_neat-0.111.0/cognite/neat/_graph/extractors/_raw.py +67 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/loaders/_base.py +20 -4
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/loaders/_rdf2dms.py +243 -89
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/queries/_base.py +137 -43
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/transformers/_classic_cdf.py +6 -22
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/_factory.py +9 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/errors/__init__.py +2 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/errors/_external.py +7 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/warnings/user_modeling.py +12 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/_constants.py +3 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/analysis/_base.py +29 -50
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/exporters/_rules2excel.py +1 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_rdf/_inference2rules.py +16 -10
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/_base_rules.py +0 -2
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/data_types.py +7 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/dms/_exporter.py +9 -8
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/dms/_rules.py +26 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/dms/_rules_input.py +5 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/dms/_validation.py +101 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/entities/_single_value.py +8 -3
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/entities/_wrapped.py +2 -2
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/information/_rules_input.py +1 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/information/_validation.py +64 -17
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/transformers/_converters.py +7 -2
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_base.py +2 -0
- cognite_neat-0.111.0/cognite/neat/_session/_explore.py +39 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_inspect.py +25 -6
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_read.py +67 -3
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_set.py +7 -1
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_state.py +6 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_to.py +115 -8
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_store/_graph_store.py +8 -4
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/rdf_.py +34 -3
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/text.py +72 -4
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/upload.py +2 -0
- cognite_neat-0.111.0/cognite/neat/_version.py +2 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/pyproject.toml +2 -2
- cognite_neat-0.110.0/cognite/neat/_version.py +0 -2
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/LICENSE +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/README.md +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/_api/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/_api/data_modeling_loaders.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/_api_client.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/data_classes/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/data_classes/data_modeling.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/data_classes/neat_sequence.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_client/testing.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_config.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/_shared.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/_tracking/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/_tracking/base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/_tracking/log.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/examples/Knowledge-Graph-Nordic44.xml +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/examples/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_assets.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_data_sets.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_events.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_files.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_labels.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_timeseries.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_dexpi.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_iodd.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_mock_graph_generator.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_rdf_file.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/loaders/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/queries/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/transformers/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/transformers/_base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/transformers/_iodd.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/transformers/_prune_graph.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/transformers/_rdfpath.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/transformers/_value_type.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/_base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/_contextmanagers.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/errors/_general.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/errors/_properties.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/errors/_resources.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/errors/_wrapper.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/formatters.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/warnings/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/warnings/_external.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/warnings/_general.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/warnings/_models.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/warnings/_properties.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_issues/warnings/_resources.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/_shared.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/analysis/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/catalog/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/catalog/classic_model.xlsx +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/catalog/hello_world_pump.xlsx +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/catalog/info-rules-imf.xlsx +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/exporters/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/exporters/_base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/exporters/_rules2dms.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/exporters/_rules2instance_template.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/exporters/_rules2ontology.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/exporters/_rules2yaml.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/exporters/_validation.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_dms2rules.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_dtdl2rules/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_dtdl2rules/_unit_lookup.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_dtdl2rules/dtdl_converter.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_dtdl2rules/dtdl_importer.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_dtdl2rules/spec.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_rdf/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_rdf/_base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_rdf/_imf2rules.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_rdf/_owl2rules.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_rdf/_shared.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_spreadsheet2rules.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/importers/_yaml2rules.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/_base_input.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/_types.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/dms/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/entities/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/entities/_constants.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/entities/_loaders.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/entities/_multi_value.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/entities/_types.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/information/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/information/_rules.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/mapping/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/mapping/_classic2core.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/models/mapping/_classic2core.yaml +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/transformers/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/transformers/_base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/transformers/_mapping.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_rules/transformers/_verification.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_collector.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_create.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_drop.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_fix.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_mapping.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_prepare.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_show.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_subset.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/_wizard.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/engine/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/engine/_import.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/engine/_interface.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/engine/_load.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_session/exceptions.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_shared.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_store/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_store/_provenance.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_store/_rules_store.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_store/exceptions.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/auth.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/auxiliary.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/collection_.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/graph_transformations_report.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/io_.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/reader/__init__.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/reader/_base.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/spreadsheet.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/time_.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_utils/xml_.py +0 -0
- {cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/py.typed +0 -0
|
@@ -15,3 +15,9 @@ class AlphaFlags:
|
|
|
15
15
|
standardize_naming = AlphaWarning("standardize_naming")
|
|
16
16
|
standardize_space_and_version = AlphaWarning("standardize_space_and_version")
|
|
17
17
|
data_model_subsetting = AlphaWarning("data_model_subsetting")
|
|
18
|
+
ontology_read = AlphaWarning("ontology_read")
|
|
19
|
+
imf_read = AlphaWarning("imf_read")
|
|
20
|
+
dexpi_read = AlphaWarning("dexpi_read")
|
|
21
|
+
aml_read = AlphaWarning("aml_read")
|
|
22
|
+
csv_read = AlphaWarning("csv_read")
|
|
23
|
+
to_ontology = AlphaWarning("to_ontology")
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from collections import defaultdict
|
|
2
2
|
from collections.abc import Iterable, Sequence
|
|
3
|
+
from graphlib import CycleError, TopologicalSorter
|
|
3
4
|
from typing import TYPE_CHECKING
|
|
4
5
|
|
|
5
6
|
from cognite.client import data_modeling as dm
|
|
@@ -126,3 +127,28 @@ class SchemaAPI:
|
|
|
126
127
|
if is_hierarchy_property(prop.container, prop.container_property_identifier):
|
|
127
128
|
hierarchical_properties_by_view_id[view.as_id()].add(prop_id)
|
|
128
129
|
return hierarchical_properties_by_view_id
|
|
130
|
+
|
|
131
|
+
@staticmethod
|
|
132
|
+
def get_view_order_by_direct_relation_constraints(views: Iterable[dm.View]) -> list[dm.ViewId]:
|
|
133
|
+
"""Sorts the views by container constraints."""
|
|
134
|
+
view_sequence = list(views)
|
|
135
|
+
view_ids_by_container: dict[dm.ContainerId, set[dm.ViewId]] = defaultdict(set)
|
|
136
|
+
for view in view_sequence:
|
|
137
|
+
for container_id in view.referenced_containers():
|
|
138
|
+
view_ids_by_container[container_id].add(view.as_id())
|
|
139
|
+
|
|
140
|
+
view_by_dependency: dict[dm.ViewId, set[dm.ViewId]] = {}
|
|
141
|
+
for view in view_sequence:
|
|
142
|
+
view_id = view.as_id()
|
|
143
|
+
view_by_dependency[view_id] = set()
|
|
144
|
+
for prop in view.properties.values():
|
|
145
|
+
if (
|
|
146
|
+
isinstance(prop, dm.MappedProperty)
|
|
147
|
+
and isinstance(prop.type, dm.DirectRelation)
|
|
148
|
+
and prop.type.container
|
|
149
|
+
):
|
|
150
|
+
view_by_dependency[view_id].update(view_ids_by_container[prop.type.container])
|
|
151
|
+
try:
|
|
152
|
+
return list(TopologicalSorter(view_by_dependency).static_order())
|
|
153
|
+
except CycleError as e:
|
|
154
|
+
raise NeatValueError("Cycle in direct relation constraints") from e
|
|
@@ -167,7 +167,7 @@ class DMSSchema:
|
|
|
167
167
|
if "." not in filename.stem:
|
|
168
168
|
continue
|
|
169
169
|
resource_type = filename.stem.rsplit(".", 1)[-1]
|
|
170
|
-
if attr_name := cls._FIELD_NAME_BY_RESOURCE_TYPE.get(resource_type):
|
|
170
|
+
if attr_name := cls._FIELD_NAME_BY_RESOURCE_TYPE.get(resource_type.casefold()):
|
|
171
171
|
data.setdefault(attr_name, [])
|
|
172
172
|
context.setdefault(attr_name, [])
|
|
173
173
|
try:
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import re
|
|
1
2
|
from collections.abc import Mapping
|
|
2
3
|
from pathlib import Path
|
|
3
4
|
from typing import TYPE_CHECKING
|
|
@@ -69,7 +70,9 @@ EXAMPLE_RULES = PACKAGE_DIRECTORY / "_rules" / "examples"
|
|
|
69
70
|
EXAMPLE_GRAPHS = PACKAGE_DIRECTORY / "_graph" / "examples"
|
|
70
71
|
EXAMPLE_WORKFLOWS = PACKAGE_DIRECTORY / "_workflows" / "examples"
|
|
71
72
|
|
|
72
|
-
DEFAULT_SPACE_URI = "http://purl.org/cognite/{space}#"
|
|
73
|
+
DEFAULT_SPACE_URI = "http://purl.org/cognite/space/{space}#"
|
|
74
|
+
SPACE_URI_PATTERN = re.compile(r"http://purl.org/cognite/space/(?P<space>[^#]+)#$")
|
|
75
|
+
DEFAULT_RAW_URI = "http://purl.org/cognite/raw#"
|
|
73
76
|
DEFAULT_NAMESPACE = Namespace("http://purl.org/cognite/neat/")
|
|
74
77
|
CDF_NAMESPACE = Namespace("https://cognitedata.com/")
|
|
75
78
|
DEFAULT_BASE_URI = URIRef(DEFAULT_NAMESPACE)
|
|
@@ -11,10 +11,12 @@ from ._classic_cdf._relationships import RelationshipsExtractor
|
|
|
11
11
|
from ._classic_cdf._sequences import SequencesExtractor
|
|
12
12
|
from ._classic_cdf._timeseries import TimeSeriesExtractor
|
|
13
13
|
from ._dexpi import DexpiExtractor
|
|
14
|
+
from ._dict import DictExtractor
|
|
14
15
|
from ._dms import DMSExtractor
|
|
15
16
|
from ._dms_graph import DMSGraphExtractor
|
|
16
17
|
from ._iodd import IODDExtractor
|
|
17
18
|
from ._mock_graph_generator import MockGraphGenerator
|
|
19
|
+
from ._raw import RAWExtractor
|
|
18
20
|
from ._rdf_file import RdfFileExtractor
|
|
19
21
|
|
|
20
22
|
__all__ = [
|
|
@@ -25,12 +27,14 @@ __all__ = [
|
|
|
25
27
|
"DMSGraphExtractor",
|
|
26
28
|
"DataSetExtractor",
|
|
27
29
|
"DexpiExtractor",
|
|
30
|
+
"DictExtractor",
|
|
28
31
|
"EventsExtractor",
|
|
29
32
|
"FilesExtractor",
|
|
30
33
|
"IODDExtractor",
|
|
31
34
|
"KnowledgeGraphExtractor",
|
|
32
35
|
"LabelsExtractor",
|
|
33
36
|
"MockGraphGenerator",
|
|
37
|
+
"RAWExtractor",
|
|
34
38
|
"RdfFileExtractor",
|
|
35
39
|
"RelationshipsExtractor",
|
|
36
40
|
"SequencesExtractor",
|
{cognite_neat-0.110.0 → cognite_neat-0.111.0}/cognite/neat/_graph/extractors/_classic_cdf/_base.py
RENAMED
|
@@ -61,8 +61,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
61
61
|
Args:
|
|
62
62
|
items (Iterable[T_CogniteResource]): An iterable of classic resource.
|
|
63
63
|
namespace (Namespace, optional): The namespace to use. Defaults to DEFAULT_NAMESPACE.
|
|
64
|
-
to_type (Callable[[T_CogniteResource], str | None], optional): A function to convert an item to a type.
|
|
65
|
-
Defaults to None. If None or if the function returns None, the asset will be set to the default type.
|
|
66
64
|
total (int, optional): The total number of items to load. If passed, you will get a progress bar if rich
|
|
67
65
|
is installed. Defaults to None.
|
|
68
66
|
limit (int, optional): The maximal number of items to load. Defaults to None. This is typically used for
|
|
@@ -87,7 +85,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
87
85
|
self,
|
|
88
86
|
items: Iterable[T_CogniteResource],
|
|
89
87
|
namespace: Namespace | None = None,
|
|
90
|
-
to_type: Callable[[T_CogniteResource], str | None] | None = None,
|
|
91
88
|
total: int | None = None,
|
|
92
89
|
limit: int | None = None,
|
|
93
90
|
unpack_metadata: bool = True,
|
|
@@ -99,7 +96,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
99
96
|
):
|
|
100
97
|
self.namespace = namespace or DEFAULT_NAMESPACE
|
|
101
98
|
self.items = items
|
|
102
|
-
self.to_type = to_type
|
|
103
99
|
self.total = total
|
|
104
100
|
self.limit = min(limit, total) if limit and total else limit
|
|
105
101
|
self.unpack_metadata = unpack_metadata
|
|
@@ -161,7 +157,7 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
161
157
|
if self._log_urirefs and hasattr(item, "external_id"):
|
|
162
158
|
self._uriref_by_external_id[item.external_id] = id_
|
|
163
159
|
|
|
164
|
-
type_ = self._get_rdf_type(
|
|
160
|
+
type_ = self._get_rdf_type()
|
|
165
161
|
|
|
166
162
|
# Set rdf type
|
|
167
163
|
triples: list[Triple] = [(id_, RDF.type, self.namespace[type_])]
|
|
@@ -215,16 +211,14 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
215
211
|
if value and (self.skip_metadata_values is None or value.casefold() not in self.skip_metadata_values):
|
|
216
212
|
yield (
|
|
217
213
|
id_,
|
|
218
|
-
self.namespace[key],
|
|
214
|
+
self.namespace[urllib.parse.quote(key)],
|
|
219
215
|
Literal(string_to_ideal_type(value)),
|
|
220
216
|
)
|
|
221
217
|
else:
|
|
222
218
|
yield id_, self.namespace.metadata, Literal(json.dumps(metadata), datatype=XSD._NS["json"])
|
|
223
219
|
|
|
224
|
-
def _get_rdf_type(self
|
|
220
|
+
def _get_rdf_type(self) -> str:
|
|
225
221
|
type_ = self._default_rdf_type
|
|
226
|
-
if self.to_type:
|
|
227
|
-
type_ = self.to_type(item) or type_
|
|
228
222
|
if self.prefix:
|
|
229
223
|
type_ = f"{self.prefix}{type_}"
|
|
230
224
|
return self._SPACE_PATTERN.sub("_", type_)
|
|
@@ -263,7 +257,11 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
263
257
|
"created_time",
|
|
264
258
|
"last_updated_time",
|
|
265
259
|
} and isinstance(raw, int):
|
|
266
|
-
|
|
260
|
+
try:
|
|
261
|
+
return Literal(datetime.fromtimestamp(raw / 1000, timezone.utc), datatype=XSD.dateTime)
|
|
262
|
+
except (OSError, ValueError) as e:
|
|
263
|
+
warnings.warn(NeatValueWarning(f"Failed to convert timestamp {raw} to datetime: {e!s}"), stacklevel=2)
|
|
264
|
+
return Literal(raw)
|
|
267
265
|
elif key == "labels":
|
|
268
266
|
from ._labels import LabelsExtractor
|
|
269
267
|
|
|
@@ -284,7 +282,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
284
282
|
client: CogniteClient,
|
|
285
283
|
data_set_external_id: str,
|
|
286
284
|
namespace: Namespace | None = None,
|
|
287
|
-
to_type: Callable[[T_CogniteResource], str | None] | None = None,
|
|
288
285
|
limit: int | None = None,
|
|
289
286
|
unpack_metadata: bool = True,
|
|
290
287
|
skip_metadata_values: Set[str] | None = DEFAULT_SKIP_METADATA_VALUES,
|
|
@@ -297,7 +294,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
297
294
|
return cls(
|
|
298
295
|
items,
|
|
299
296
|
namespace,
|
|
300
|
-
to_type,
|
|
301
297
|
total,
|
|
302
298
|
limit,
|
|
303
299
|
unpack_metadata,
|
|
@@ -321,7 +317,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
321
317
|
client: CogniteClient,
|
|
322
318
|
root_asset_external_id: str,
|
|
323
319
|
namespace: Namespace | None = None,
|
|
324
|
-
to_type: Callable[[T_CogniteResource], str | None] | None = None,
|
|
325
320
|
limit: int | None = None,
|
|
326
321
|
unpack_metadata: bool = True,
|
|
327
322
|
skip_metadata_values: Set[str] | None = DEFAULT_SKIP_METADATA_VALUES,
|
|
@@ -334,7 +329,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
334
329
|
return cls(
|
|
335
330
|
items,
|
|
336
331
|
namespace,
|
|
337
|
-
to_type,
|
|
338
332
|
total,
|
|
339
333
|
limit,
|
|
340
334
|
unpack_metadata,
|
|
@@ -357,7 +351,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
357
351
|
cls,
|
|
358
352
|
file_path: str | Path,
|
|
359
353
|
namespace: Namespace | None = None,
|
|
360
|
-
to_type: Callable[[T_CogniteResource], str | None] | None = None,
|
|
361
354
|
limit: int | None = None,
|
|
362
355
|
unpack_metadata: bool = True,
|
|
363
356
|
skip_metadata_values: Set[str] | None = DEFAULT_SKIP_METADATA_VALUES,
|
|
@@ -370,7 +363,6 @@ class ClassicCDFBaseExtractor(BaseExtractor, ABC, Generic[T_CogniteResource]):
|
|
|
370
363
|
return cls(
|
|
371
364
|
items,
|
|
372
365
|
namespace,
|
|
373
|
-
to_type,
|
|
374
366
|
total,
|
|
375
367
|
limit,
|
|
376
368
|
unpack_metadata,
|
|
@@ -102,6 +102,8 @@ class ClassicGraphExtractor(KnowledgeGraphExtractor):
|
|
|
102
102
|
limit_per_type: int | None = None,
|
|
103
103
|
prefix: str | None = None,
|
|
104
104
|
identifier: typing.Literal["id", "externalId"] = "id",
|
|
105
|
+
unpack_metadata: bool = False,
|
|
106
|
+
skip_sequence_rows: bool = False,
|
|
105
107
|
):
|
|
106
108
|
self._client = client
|
|
107
109
|
if sum([bool(data_set_external_id), bool(root_asset_external_id)]) != 1:
|
|
@@ -111,7 +113,7 @@ class ClassicGraphExtractor(KnowledgeGraphExtractor):
|
|
|
111
113
|
self._namespace = namespace or CLASSIC_CDF_NAMESPACE
|
|
112
114
|
self._extractor_args = dict(
|
|
113
115
|
namespace=self._namespace,
|
|
114
|
-
unpack_metadata=
|
|
116
|
+
unpack_metadata=unpack_metadata,
|
|
115
117
|
as_write=True,
|
|
116
118
|
camel_case=True,
|
|
117
119
|
limit=limit_per_type,
|
|
@@ -121,6 +123,7 @@ class ClassicGraphExtractor(KnowledgeGraphExtractor):
|
|
|
121
123
|
self._identifier = identifier
|
|
122
124
|
self._prefix = prefix
|
|
123
125
|
self._limit_per_type = limit_per_type
|
|
126
|
+
self._skip_sequence_rows = skip_sequence_rows
|
|
124
127
|
|
|
125
128
|
self._uris_by_external_id_by_type: dict[InstanceIdPrefix, dict[str, URIRef]] = defaultdict(dict)
|
|
126
129
|
self._source_external_ids_by_type: dict[InstanceIdPrefix, set[str]] = defaultdict(set)
|
|
@@ -133,6 +136,29 @@ class ClassicGraphExtractor(KnowledgeGraphExtractor):
|
|
|
133
136
|
self._extracted_data_sets = False
|
|
134
137
|
self._asset_external_ids_by_id: dict[int, str] = {}
|
|
135
138
|
self._dataset_external_ids_by_id: dict[int, str] = {}
|
|
139
|
+
self.neat_prefix_by_predicate_uri: dict[URIRef, str] = {
|
|
140
|
+
self._namespace["dataSetId"]: InstanceIdPrefix.data_set,
|
|
141
|
+
self._namespace["assetId"]: InstanceIdPrefix.asset,
|
|
142
|
+
self._namespace["assetIds"]: InstanceIdPrefix.asset,
|
|
143
|
+
self._namespace["parentId"]: InstanceIdPrefix.asset,
|
|
144
|
+
self._namespace["rootId"]: InstanceIdPrefix.asset,
|
|
145
|
+
self._namespace["labels"]: InstanceIdPrefix.label,
|
|
146
|
+
}
|
|
147
|
+
self.neat_prefix_by_type_uri: dict[URIRef, str] = {}
|
|
148
|
+
for extractor_cls, type_prefix in [
|
|
149
|
+
(AssetsExtractor, InstanceIdPrefix.asset),
|
|
150
|
+
(TimeSeriesExtractor, InstanceIdPrefix.time_series),
|
|
151
|
+
(SequencesExtractor, InstanceIdPrefix.sequence),
|
|
152
|
+
(EventsExtractor, InstanceIdPrefix.event),
|
|
153
|
+
(FilesExtractor, InstanceIdPrefix.file),
|
|
154
|
+
(RelationshipsExtractor, InstanceIdPrefix.relationship),
|
|
155
|
+
(LabelsExtractor, InstanceIdPrefix.label),
|
|
156
|
+
(DataSetExtractor, InstanceIdPrefix.data_set),
|
|
157
|
+
]:
|
|
158
|
+
rdf_type = extractor_cls._default_rdf_type # type: ignore[attr-defined]
|
|
159
|
+
if prefix:
|
|
160
|
+
rdf_type = f"{prefix}{rdf_type}"
|
|
161
|
+
self.neat_prefix_by_type_uri[self._namespace[rdf_type]] = type_prefix
|
|
136
162
|
|
|
137
163
|
def _get_activity_names(self) -> list[str]:
|
|
138
164
|
activities = [data_access_object.extractor_cls.__name__ for data_access_object in self._classic_node_types] + [
|
|
@@ -237,14 +263,14 @@ class ClassicGraphExtractor(KnowledgeGraphExtractor):
|
|
|
237
263
|
|
|
238
264
|
def _extract_core_start_nodes(self):
|
|
239
265
|
for core_node in self._classic_node_types:
|
|
266
|
+
kwargs = self._extractor_args.copy()
|
|
267
|
+
if core_node.extractor_cls == SequencesExtractor and self._skip_sequence_rows:
|
|
268
|
+
kwargs["skip_rows"] = True
|
|
269
|
+
|
|
240
270
|
if self._data_set_external_id:
|
|
241
|
-
extractor = core_node.extractor_cls.from_dataset(
|
|
242
|
-
self._client, self._data_set_external_id, **self._extractor_args
|
|
243
|
-
)
|
|
271
|
+
extractor = core_node.extractor_cls.from_dataset(self._client, self._data_set_external_id, **kwargs)
|
|
244
272
|
elif self._root_asset_external_id:
|
|
245
|
-
extractor = core_node.extractor_cls.from_hierarchy(
|
|
246
|
-
self._client, self._root_asset_external_id, **self._extractor_args
|
|
247
|
-
)
|
|
273
|
+
extractor = core_node.extractor_cls.from_hierarchy(self._client, self._root_asset_external_id, **kwargs)
|
|
248
274
|
else:
|
|
249
275
|
raise ValueError("Exactly one of data_set_external_id or root_asset_external_id must be set.")
|
|
250
276
|
|
|
@@ -273,7 +299,9 @@ class ClassicGraphExtractor(KnowledgeGraphExtractor):
|
|
|
273
299
|
# This is a private attribute, but we need to set it to log the target nodes.
|
|
274
300
|
extractor._log_target_nodes = True
|
|
275
301
|
if self._identifier == "id":
|
|
276
|
-
extractor.
|
|
302
|
+
extractor._uri_by_external_id_by_type = self._uris_by_external_id_by_type
|
|
303
|
+
elif self._identifier == "externalId":
|
|
304
|
+
extractor.lookup_dataset_external_id = self._lookup_dataset
|
|
277
305
|
|
|
278
306
|
yield from extractor.extract()
|
|
279
307
|
|
|
@@ -330,7 +358,9 @@ class ClassicGraphExtractor(KnowledgeGraphExtractor):
|
|
|
330
358
|
def _extract_labels(self):
|
|
331
359
|
for chunk in self._chunk(list(self._labels), description="Extracting labels"):
|
|
332
360
|
label_iterator = self._client.labels.retrieve(external_id=list(chunk), ignore_unknown_ids=True)
|
|
333
|
-
|
|
361
|
+
extractor = LabelsExtractor(label_iterator, **self._extractor_args)
|
|
362
|
+
extractor.lookup_dataset_external_id = self._lookup_dataset
|
|
363
|
+
yield from extractor.extract()
|
|
334
364
|
|
|
335
365
|
def _extract_data_sets(self):
|
|
336
366
|
for chunk in self._chunk(list(self._data_set_ids), description="Extracting data sets"):
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
import warnings
|
|
3
3
|
from collections import defaultdict
|
|
4
|
-
from collections.abc import
|
|
4
|
+
from collections.abc import Iterable, Set
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
@@ -26,7 +26,6 @@ class RelationshipsExtractor(ClassicCDFBaseExtractor[Relationship]):
|
|
|
26
26
|
self,
|
|
27
27
|
items: Iterable[Relationship],
|
|
28
28
|
namespace: Namespace | None = None,
|
|
29
|
-
to_type: Callable[[Relationship], str | None] | None = None,
|
|
30
29
|
total: int | None = None,
|
|
31
30
|
limit: int | None = None,
|
|
32
31
|
unpack_metadata: bool = True,
|
|
@@ -46,7 +45,6 @@ class RelationshipsExtractor(ClassicCDFBaseExtractor[Relationship]):
|
|
|
46
45
|
super().__init__(
|
|
47
46
|
to_iterate,
|
|
48
47
|
namespace=namespace,
|
|
49
|
-
to_type=to_type,
|
|
50
48
|
total=total,
|
|
51
49
|
limit=limit,
|
|
52
50
|
unpack_metadata=unpack_metadata,
|
|
@@ -56,7 +54,7 @@ class RelationshipsExtractor(ClassicCDFBaseExtractor[Relationship]):
|
|
|
56
54
|
prefix=prefix,
|
|
57
55
|
identifier=identifier,
|
|
58
56
|
)
|
|
59
|
-
self.
|
|
57
|
+
self._uri_by_external_id_by_type: dict[InstanceIdPrefix, dict[str, URIRef]] = defaultdict(dict)
|
|
60
58
|
self._target_triples: list[tuple[URIRef, URIRef, str, str]] = []
|
|
61
59
|
|
|
62
60
|
def _log_target_nodes_if_set(self, item: Relationship) -> Relationship:
|
|
@@ -67,25 +65,33 @@ class RelationshipsExtractor(ClassicCDFBaseExtractor[Relationship]):
|
|
|
67
65
|
return item
|
|
68
66
|
|
|
69
67
|
def _item2triples_special_cases(self, id_: URIRef, dumped: dict[str, Any]) -> list[Triple]:
|
|
70
|
-
if self.identifier == "externalId":
|
|
71
|
-
return []
|
|
72
68
|
triples: list[Triple] = []
|
|
73
69
|
if (source_external_id := dumped.pop("sourceExternalId")) and "sourceType" in dumped:
|
|
74
70
|
source_type = dumped["sourceType"]
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
source_prefix = InstanceIdPrefix.from_str(source_type)
|
|
72
|
+
if self.identifier == "id":
|
|
73
|
+
try:
|
|
74
|
+
source_uri = self._uri_by_external_id_by_type[source_prefix][source_external_id]
|
|
75
|
+
except KeyError:
|
|
76
|
+
warnings.warn(
|
|
77
|
+
NeatValueWarning(f"Missing externalId {source_external_id} for {source_type}"), stacklevel=2
|
|
78
|
+
)
|
|
79
|
+
else:
|
|
80
|
+
triples.append((id_, self.namespace["sourceExternalId"], source_uri))
|
|
81
|
+
elif self.identifier == "externalId":
|
|
82
|
+
triples.append(
|
|
83
|
+
(id_, self.namespace["sourceExternalId"], self.namespace[f"{source_prefix}{source_external_id}"])
|
|
82
84
|
)
|
|
83
|
-
else:
|
|
84
|
-
triples.append((id_, self.namespace["sourceExternalId"], source_uri))
|
|
85
85
|
if (target_external_id := dumped.pop("targetExternalId")) and "targetType" in dumped:
|
|
86
86
|
target_type = dumped["targetType"]
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if self.identifier == "id":
|
|
88
|
+
# We do not yet have the target nodes, so we log them for later extraction.
|
|
89
|
+
self._target_triples.append((id_, self.namespace["targetExternalId"], target_type, target_external_id))
|
|
90
|
+
elif self.identifier == "externalId":
|
|
91
|
+
target_prefix = InstanceIdPrefix.from_str(target_type)
|
|
92
|
+
triples.append(
|
|
93
|
+
(id_, self.namespace["targetExternalId"], self.namespace[f"{target_prefix}{target_external_id}"])
|
|
94
|
+
)
|
|
89
95
|
return triples
|
|
90
96
|
|
|
91
97
|
@classmethod
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import itertools
|
|
2
2
|
import json
|
|
3
3
|
import typing
|
|
4
|
-
from collections.abc import
|
|
4
|
+
from collections.abc import Iterable, Set
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
@@ -21,8 +21,6 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
21
21
|
Args:
|
|
22
22
|
items (Iterable[T_CogniteResource]): An iterable of classic resource.
|
|
23
23
|
namespace (Namespace, optional): The namespace to use. Defaults to DEFAULT_NAMESPACE.
|
|
24
|
-
to_type (Callable[[T_CogniteResource], str | None], optional): A function to convert an item to a type.
|
|
25
|
-
Defaults to None. If None or if the function returns None, the asset will be set to the default type.
|
|
26
24
|
total (int, optional): The total number of items to load. If passed, you will get a progress bar if rich
|
|
27
25
|
is installed. Defaults to None.
|
|
28
26
|
limit (int, optional): The maximal number of items to load. Defaults to None. This is typically used for
|
|
@@ -46,7 +44,6 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
46
44
|
self,
|
|
47
45
|
items: Iterable[NeatSequence],
|
|
48
46
|
namespace: Namespace | None = None,
|
|
49
|
-
to_type: Callable[[NeatSequence], str | None] | None = None,
|
|
50
47
|
total: int | None = None,
|
|
51
48
|
limit: int | None = None,
|
|
52
49
|
unpack_metadata: bool = True,
|
|
@@ -60,7 +57,6 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
60
57
|
super().__init__(
|
|
61
58
|
items,
|
|
62
59
|
namespace,
|
|
63
|
-
to_type,
|
|
64
60
|
total,
|
|
65
61
|
limit,
|
|
66
62
|
unpack_metadata,
|
|
@@ -78,7 +74,6 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
78
74
|
client: CogniteClient,
|
|
79
75
|
data_set_external_id: str,
|
|
80
76
|
namespace: Namespace | None = None,
|
|
81
|
-
to_type: Callable[[NeatSequence], str | None] | None = None,
|
|
82
77
|
limit: int | None = None,
|
|
83
78
|
unpack_metadata: bool = True,
|
|
84
79
|
skip_metadata_values: Set[str] | None = DEFAULT_SKIP_METADATA_VALUES,
|
|
@@ -87,12 +82,12 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
87
82
|
prefix: str | None = None,
|
|
88
83
|
identifier: typing.Literal["id", "externalId"] = "id",
|
|
89
84
|
unpack_columns: bool = False,
|
|
85
|
+
skip_rows: bool = False,
|
|
90
86
|
):
|
|
91
|
-
total, items = cls._handle_no_access(lambda: cls._from_dataset(client, data_set_external_id))
|
|
87
|
+
total, items = cls._handle_no_access(lambda: cls._from_dataset(client, data_set_external_id, skip_rows))
|
|
92
88
|
return cls(
|
|
93
89
|
items,
|
|
94
90
|
namespace,
|
|
95
|
-
to_type,
|
|
96
91
|
total,
|
|
97
92
|
limit,
|
|
98
93
|
unpack_metadata,
|
|
@@ -110,7 +105,6 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
110
105
|
client: CogniteClient,
|
|
111
106
|
root_asset_external_id: str,
|
|
112
107
|
namespace: Namespace | None = None,
|
|
113
|
-
to_type: Callable[[NeatSequence], str | None] | None = None,
|
|
114
108
|
limit: int | None = None,
|
|
115
109
|
unpack_metadata: bool = True,
|
|
116
110
|
skip_metadata_values: Set[str] | None = DEFAULT_SKIP_METADATA_VALUES,
|
|
@@ -119,12 +113,12 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
119
113
|
prefix: str | None = None,
|
|
120
114
|
identifier: typing.Literal["id", "externalId"] = "id",
|
|
121
115
|
unpack_columns: bool = False,
|
|
116
|
+
skip_rows: bool = False,
|
|
122
117
|
):
|
|
123
|
-
total, items = cls._handle_no_access(lambda: cls._from_hierarchy(client, root_asset_external_id))
|
|
118
|
+
total, items = cls._handle_no_access(lambda: cls._from_hierarchy(client, root_asset_external_id, skip_rows))
|
|
124
119
|
return cls(
|
|
125
120
|
items,
|
|
126
121
|
namespace,
|
|
127
|
-
to_type,
|
|
128
122
|
total,
|
|
129
123
|
limit,
|
|
130
124
|
unpack_metadata,
|
|
@@ -141,7 +135,6 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
141
135
|
cls,
|
|
142
136
|
file_path: str | Path,
|
|
143
137
|
namespace: Namespace | None = None,
|
|
144
|
-
to_type: Callable[[NeatSequence], str | None] | None = None,
|
|
145
138
|
limit: int | None = None,
|
|
146
139
|
unpack_metadata: bool = True,
|
|
147
140
|
skip_metadata_values: Set[str] | None = DEFAULT_SKIP_METADATA_VALUES,
|
|
@@ -155,7 +148,6 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
155
148
|
return cls(
|
|
156
149
|
items,
|
|
157
150
|
namespace,
|
|
158
|
-
to_type,
|
|
159
151
|
total,
|
|
160
152
|
limit,
|
|
161
153
|
unpack_metadata,
|
|
@@ -169,23 +161,29 @@ class SequencesExtractor(ClassicCDFBaseExtractor[NeatSequence]):
|
|
|
169
161
|
|
|
170
162
|
@classmethod
|
|
171
163
|
def _from_dataset(
|
|
172
|
-
cls, client: CogniteClient, data_set_external_id: str
|
|
164
|
+
cls, client: CogniteClient, data_set_external_id: str, skip_rows: bool = False
|
|
173
165
|
) -> tuple[int | None, Iterable[NeatSequence]]:
|
|
174
166
|
total = client.sequences.aggregate_count(
|
|
175
167
|
filter=SequenceFilter(data_set_ids=[{"externalId": data_set_external_id}])
|
|
176
168
|
)
|
|
177
169
|
items = client.sequences(data_set_external_ids=data_set_external_id)
|
|
178
|
-
|
|
170
|
+
if skip_rows:
|
|
171
|
+
return total, (NeatSequence.from_cognite_sequence(seq) for seq in items)
|
|
172
|
+
else:
|
|
173
|
+
return total, cls._lookup_rows(items, client)
|
|
179
174
|
|
|
180
175
|
@classmethod
|
|
181
176
|
def _from_hierarchy(
|
|
182
|
-
cls, client: CogniteClient, root_asset_external_id: str
|
|
177
|
+
cls, client: CogniteClient, root_asset_external_id: str, skip_rows: bool = False
|
|
183
178
|
) -> tuple[int | None, Iterable[NeatSequence]]:
|
|
184
179
|
total = client.sequences.aggregate_count(
|
|
185
180
|
filter=SequenceFilter(asset_subtree_ids=[{"externalId": root_asset_external_id}])
|
|
186
181
|
)
|
|
187
182
|
items = client.sequences(asset_subtree_external_ids=[root_asset_external_id])
|
|
188
|
-
|
|
183
|
+
if skip_rows:
|
|
184
|
+
return total, (NeatSequence.from_cognite_sequence(seq) for seq in items)
|
|
185
|
+
else:
|
|
186
|
+
return total, cls._lookup_rows(items, client)
|
|
189
187
|
|
|
190
188
|
@classmethod
|
|
191
189
|
def _from_file(cls, file_path: str | Path) -> tuple[int | None, Iterable[NeatSequence]]:
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import urllib.parse
|
|
3
|
+
from collections.abc import Callable, Iterable, Mapping, Set
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from cognite.client import data_modeling as dm
|
|
7
|
+
from cognite.client.data_classes.data_modeling.instances import Instance
|
|
8
|
+
from rdflib import XSD, Literal, Namespace, URIRef
|
|
9
|
+
|
|
10
|
+
from cognite.neat._shared import Triple
|
|
11
|
+
from cognite.neat._utils.auxiliary import string_to_ideal_type
|
|
12
|
+
|
|
13
|
+
from ._base import BaseExtractor
|
|
14
|
+
|
|
15
|
+
DEFAULT_EMPTY_VALUES = frozenset({"nan", "null", "none", "", " ", "nil", "n/a", "na", "unknown", "undefined"})
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class DictExtractor(BaseExtractor):
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
id_: URIRef,
|
|
22
|
+
data: Mapping[str, Any],
|
|
23
|
+
namespace: Namespace,
|
|
24
|
+
uri_ref_keys: set[str] | None = None,
|
|
25
|
+
empty_values: Set[str] = DEFAULT_EMPTY_VALUES,
|
|
26
|
+
str_to_ideal_type: bool = False,
|
|
27
|
+
unpack_json: bool = False,
|
|
28
|
+
) -> None:
|
|
29
|
+
self.id_ = id_
|
|
30
|
+
self.namespace = namespace
|
|
31
|
+
self.data = data
|
|
32
|
+
self.uri_ref_keys = uri_ref_keys or set()
|
|
33
|
+
self.empty_values = empty_values
|
|
34
|
+
self.str_to_ideal_type = str_to_ideal_type
|
|
35
|
+
self.unpack_json = unpack_json
|
|
36
|
+
|
|
37
|
+
def extract(self) -> Iterable[Triple]:
|
|
38
|
+
for key, value in self.data.items():
|
|
39
|
+
for predicate_str, object_ in self._get_predicate_objects_pair(key, value, self.unpack_json):
|
|
40
|
+
yield self.id_, self.namespace[urllib.parse.quote(predicate_str)], object_
|
|
41
|
+
|
|
42
|
+
def _get_predicate_objects_pair(
|
|
43
|
+
self, key: str, value: Any, unpack_json: bool
|
|
44
|
+
) -> Iterable[tuple[str, Literal | URIRef]]:
|
|
45
|
+
if key in self.uri_ref_keys and not isinstance(value, dict | list):
|
|
46
|
+
yield key, URIRef(self.namespace[urllib.parse.quote(value)])
|
|
47
|
+
if isinstance(value, str | float | bool | int):
|
|
48
|
+
yield key, Literal(value)
|
|
49
|
+
elif isinstance(value, dict) and unpack_json:
|
|
50
|
+
yield from self._unpack_json(value)
|
|
51
|
+
elif isinstance(value, dict):
|
|
52
|
+
# This object is a json object.
|
|
53
|
+
yield key, Literal(json.dumps(value), datatype=XSD._NS["json"])
|
|
54
|
+
elif isinstance(value, list):
|
|
55
|
+
for item in value:
|
|
56
|
+
yield from self._get_predicate_objects_pair(key, item, False)
|
|
57
|
+
|
|
58
|
+
def _unpack_json(self, value: dict, parent: str | None = None) -> Iterable[tuple[str, Literal | URIRef]]:
|
|
59
|
+
for sub_key, sub_value in value.items():
|
|
60
|
+
key = f"{parent}_{sub_key}" if parent else sub_key
|
|
61
|
+
if isinstance(sub_value, str):
|
|
62
|
+
if sub_value.casefold() in self.empty_values:
|
|
63
|
+
continue
|
|
64
|
+
if self.str_to_ideal_type:
|
|
65
|
+
yield key, Literal(string_to_ideal_type(sub_value))
|
|
66
|
+
else:
|
|
67
|
+
yield key, Literal(sub_value)
|
|
68
|
+
elif isinstance(sub_value, int | float | bool):
|
|
69
|
+
yield key, Literal(sub_value)
|
|
70
|
+
elif isinstance(sub_value, dict):
|
|
71
|
+
yield from self._unpack_json(sub_value, key)
|
|
72
|
+
elif isinstance(sub_value, list):
|
|
73
|
+
for no, item in enumerate(sub_value, 1):
|
|
74
|
+
if isinstance(item, dict):
|
|
75
|
+
yield from self._unpack_json(item, f"{key}_{no}")
|
|
76
|
+
else:
|
|
77
|
+
yield from self._get_predicate_objects_pair(key, item, self.unpack_json)
|
|
78
|
+
else:
|
|
79
|
+
yield key, Literal(str(sub_value))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class DMSPropertyExtractor(DictExtractor):
|
|
83
|
+
def __init__(
|
|
84
|
+
self,
|
|
85
|
+
id_: URIRef,
|
|
86
|
+
data: Mapping[str, Any],
|
|
87
|
+
namespace: Namespace,
|
|
88
|
+
as_uri_ref: Callable[[Instance | dm.DirectRelationReference], URIRef],
|
|
89
|
+
empty_values: Set[str] = DEFAULT_EMPTY_VALUES,
|
|
90
|
+
str_to_ideal_type: bool = False,
|
|
91
|
+
unpack_json: bool = False,
|
|
92
|
+
) -> None:
|
|
93
|
+
super().__init__(id_, data, namespace, None, empty_values, str_to_ideal_type, unpack_json)
|
|
94
|
+
self.as_uri_ref = as_uri_ref
|
|
95
|
+
|
|
96
|
+
def _get_predicate_objects_pair(
|
|
97
|
+
self, key: str, value: Any, unpack_json: bool
|
|
98
|
+
) -> Iterable[tuple[str, Literal | URIRef]]:
|
|
99
|
+
if isinstance(value, dict) and "space" in value and "externalId" in value:
|
|
100
|
+
yield key, self.as_uri_ref(dm.DirectRelationReference.load(value))
|
|
101
|
+
else:
|
|
102
|
+
yield from super()._get_predicate_objects_pair(key, value, unpack_json)
|