cognite-neat 0.81.12__tar.gz → 0.82.1__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.
Potentially problematic release.
This version of cognite-neat might be problematic. Click here for more details.
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/PKG-INFO +1 -1
- cognite_neat-0.82.1/cognite/neat/_version.py +1 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_mock_graph_generator.py +2 -8
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/loaders/_rdf2dms.py +1 -1
- cognite_neat-0.82.1/cognite/neat/graph/queries/__init__.py +3 -0
- cognite_neat-0.82.1/cognite/neat/graph/queries/_base.py +99 -0
- cognite_neat-0.82.1/cognite/neat/graph/queries/_construct.py +185 -0
- cognite_neat-0.82.1/cognite/neat/graph/queries/_shared.py +159 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/stores/_base.py +24 -87
- cognite_neat-0.82.1/cognite/neat/rules/_shared.py +5 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/analysis/_information_rules.py +34 -58
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_inference2rules.py +5 -1
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_spreadsheet2rules.py +6 -1
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/__init__.py +4 -1
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/_base.py +1 -0
- cognite_neat-0.82.1/cognite/neat/rules/models/asset/__init__.py +10 -0
- cognite_neat-0.82.1/cognite/neat/rules/models/asset/_converter.py +4 -0
- cognite_neat-0.82.1/cognite/neat/rules/models/asset/_rules.py +156 -0
- cognite_neat-0.82.1/cognite/neat/rules/models/asset/_rules_input.py +171 -0
- cognite_neat-0.82.1/cognite/neat/rules/models/asset/_serializer.py +73 -0
- cognite_neat-0.82.1/cognite/neat/rules/models/asset/_validation.py +4 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/entities.py +56 -1
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/information/_rules.py +5 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/information/_rules_input.py +3 -6
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/utils.py +6 -1
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/data_contracts.py +5 -2
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/pyproject.toml +2 -4
- cognite_neat-0.81.12/cognite/neat/_version.py +0 -1
- cognite_neat-0.81.12/cognite/neat/rules/_shared.py +0 -5
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/LICENSE +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/README.md +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/asgi/metrics.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/configuration.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/context_manager/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/context_manager/manager.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/data_classes/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/data_classes/rest.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/explorer.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/routers/configuration.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/routers/core.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/routers/crud.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/routers/data_exploration.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/routers/metrics.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/routers/rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/routers/workflows.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/utils/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/utils/data_mapping.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/utils/logging.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/api/utils/query_templates.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/main.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/monitoring/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/monitoring/metrics.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/index.html +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/.gitignore +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/README.md +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/asset-manifest.json +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/favicon.ico +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/img/architect-icon.svg +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/img/developer-icon.svg +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/img/sme-icon.svg +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/index.html +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/logo192.png +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/manifest.json +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/robots.txt +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/static/css/main.38a62222.css +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/static/css/main.38a62222.css.map +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/static/js/main.ec7f72e2.js +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/static/js/main.ec7f72e2.js.LICENSE.txt +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/static/js/main.ec7f72e2.js.map +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/app/ui/neat-app/build/static/media/logo.8093b84df9ed36a174c629d6fe0b730d.svg +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/config.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/constants.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/exceptions.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/_shared.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/_tracking/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/_tracking/base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/_tracking/log.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/examples/Knowledge-Graph-Nordic44.xml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/examples/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/exceptions.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_classic_cdf/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_classic_cdf/_assets.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_classic_cdf/_events.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_classic_cdf/_files.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_classic_cdf/_labels.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_classic_cdf/_relationships.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_classic_cdf/_sequences.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_classic_cdf/_timeseries.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_dexpi.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_rdf_file.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/issues/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/issues/loader.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/loaders/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/loaders/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/models.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/stores/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/stores/_oxrdflib.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/stores/_provenance.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/transformers/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/transformers/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/transformers/_classic_cdf.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/issues.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44.xml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/examples/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/exceptions.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/extractors/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/extractors/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/extractors/_dexpi.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/extractors/_graph_capturing_sheet.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/extractors/_mock_graph_generator.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/_asset_loader.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/_exceptions.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/core/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/core/labels.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/core/models.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/core/rdf_to_assets.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/core/rdf_to_relationships.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/rdf_to_dms.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/loaders/validator.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/models.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/stores/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/stores/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/stores/_graphdb_store.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/stores/_memory_store.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/stores/_oxigraph_store.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/stores/_oxrdflib.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/stores/_rdf_to_graph.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/transformations/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/transformations/entity_matcher.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/transformations/query_generator/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/transformations/query_generator/sparql.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/graph/transformations/transformer.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/analysis.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/Rules-Nordic44-to-TNT.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/Rules-Nordic44-to-graphql.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/power-grid-containers.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/power-grid-example.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/power-grid-model.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/rules-template.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/sheet2cdf-transformation-rules.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/skos-rules.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/source-to-solution-mapping-rules.xlsx +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/examples/wind-energy.owl +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exceptions.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_core/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_core/rules2labels.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_rules2dms.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_rules2excel.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_rules2graphql.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_rules2ontology.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_rules2pydantic_models.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_rules2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_rules2triples.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/exporters/_validation.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_dict2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_dms2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_graph2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_json2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_owl2rules/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_owl2rules/_owl2classes.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_owl2rules/_owl2metadata.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_owl2rules/_owl2properties.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_owl2rules/_owl2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_spreadsheet2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_xsd2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/importers/_yaml2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/models/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/models/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/models/raw_rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/models/rdfpath.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/models/rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/models/tables.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/rules/models/value_types.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Export_DMS/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Export_Rules_to_Ontology/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Extract_DEXPI_Graph_and_Export_Rules/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Import_DMS/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Ontology_to_Data_Model/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Validate_Rules/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Validate_Solution_Model/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Visualize_Data_Model_Using_Mock_Graph/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/legacy/workflows/examples/Visualize_Semantic_Data_Model/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/py.typed +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/analysis/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/analysis/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/examples/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/examples/wind-energy.owl +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/exceptions.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/exporters/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/exporters/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/exporters/_rules2dms.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/exporters/_rules2excel.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/exporters/_rules2ontology.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/exporters/_rules2yaml.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/exporters/_validation.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_dms2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_dtdl2rules/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_dtdl2rules/_unit_lookup.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_dtdl2rules/dtdl_converter.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_dtdl2rules/dtdl_importer.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_dtdl2rules/spec.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_owl2rules/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_owl2rules/_owl2classes.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_owl2rules/_owl2metadata.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_owl2rules/_owl2properties.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_owl2rules/_owl2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/importers/_yaml2rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/issues/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/issues/base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/issues/dms.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/issues/fileread.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/issues/formatters.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/issues/importing.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/issues/spreadsheet.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/issues/spreadsheet_file.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/_constants.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/_rdfpath.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/_types/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/_types/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/_types/_field.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/data_types.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/dms/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/dms/_converter.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/dms/_exporter.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/dms/_rules.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/dms/_rules_input.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/dms/_schema.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/dms/_serializer.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/dms/_validation.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/domain.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/information/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/information/_converter.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/information/_serializer.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/information/_validation.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/rules/models/wrapped_entities.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/auxiliary.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/cdf.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/cdf_classes.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/cdf_loaders/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/cdf_loaders/_base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/cdf_loaders/_data_modeling.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/cdf_loaders/_ingestion.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/cdf_loaders/data_classes.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/exceptions.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/spreadsheet.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/text.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/upload.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/utils/xml.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/_exceptions.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/base.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/cdf_store.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Export_DMS/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Export_Rules_to_Ontology/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Extract_DEXPI_Graph_and_Export_Rules/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Import_DMS/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Ontology_to_Data_Model/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Validate_Rules/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Validate_Solution_Model/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Visualize_Data_Model_Using_Mock_Graph/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/examples/Visualize_Semantic_Data_Model/workflow.yaml +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/manager.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/migration/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/migration/steps.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/migration/wf_manifests.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/model.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/current/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/current/graph_extractor.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/current/graph_loader.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/current/graph_store.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/current/rules_exporter.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/current/rules_importer.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/current/rules_validator.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/io/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/io/io_steps.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/legacy/__init__.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/legacy/graph_contextualization.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/legacy/graph_extractor.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/legacy/graph_loader.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/legacy/graph_store.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/legacy/graph_transformer.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/legacy/rules_exporter.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/lib/legacy/rules_importer.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps/step_model.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/steps_registry.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/tasks.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/triggers.py +0 -0
- {cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/workflows/utils.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.82.1"
|
{cognite_neat-0.81.12 → cognite_neat-0.82.1}/cognite/neat/graph/extractors/_mock_graph_generator.py
RENAMED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
It is a bit ugly and needs some proper refactoring, but it is not a priority at the moment.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
import logging
|
|
6
5
|
import random
|
|
7
6
|
import warnings
|
|
8
7
|
from collections import OrderedDict
|
|
@@ -87,11 +86,11 @@ def generate_triples(
|
|
|
87
86
|
stop_on_exception: bool = False,
|
|
88
87
|
allow_isolated_classes: bool = True,
|
|
89
88
|
) -> list[Triple]:
|
|
90
|
-
"""Generate mock triples based on data model defined
|
|
89
|
+
"""Generate mock triples based on data model defined in rules and desired number
|
|
91
90
|
of class instances
|
|
92
91
|
|
|
93
92
|
Args:
|
|
94
|
-
|
|
93
|
+
rules : Rules defining the data model
|
|
95
94
|
class_count: Target class count for each class in the ontology
|
|
96
95
|
stop_on_exception: To stop if exception is encountered or not, default is False
|
|
97
96
|
allow_isolated_classes: To allow generation of instances for classes that are not
|
|
@@ -107,11 +106,9 @@ def generate_triples(
|
|
|
107
106
|
if non_existing_classes := set(class_count.keys()) - defined_classes:
|
|
108
107
|
msg = f"Class count contains classes {non_existing_classes} for which properties are not defined in Data Model!"
|
|
109
108
|
if stop_on_exception:
|
|
110
|
-
logging.error(msg)
|
|
111
109
|
raise ValueError(msg)
|
|
112
110
|
else:
|
|
113
111
|
msg += " These classes will be ignored."
|
|
114
|
-
logging.warning(msg)
|
|
115
112
|
warnings.warn(msg, stacklevel=2)
|
|
116
113
|
for class_ in non_existing_classes:
|
|
117
114
|
class_count.pop(class_)
|
|
@@ -279,14 +276,12 @@ def _generate_mock_object_property_triples(
|
|
|
279
276
|
if property_definition.value_type not in instance_ids:
|
|
280
277
|
msg = f"Class {property_definition.value_type} not found in class count! "
|
|
281
278
|
if stop_on_exception:
|
|
282
|
-
logging.error(msg)
|
|
283
279
|
raise ValueError(msg)
|
|
284
280
|
else:
|
|
285
281
|
msg += (
|
|
286
282
|
f"Skipping creating triples for property {property_definition.name} "
|
|
287
283
|
f"of class {class_.suffix} which expects values of this type!"
|
|
288
284
|
)
|
|
289
|
-
logging.warning(msg)
|
|
290
285
|
warnings.warn(msg, stacklevel=2)
|
|
291
286
|
return []
|
|
292
287
|
|
|
@@ -354,7 +349,6 @@ def _generate_triples_per_class(
|
|
|
354
349
|
)
|
|
355
350
|
|
|
356
351
|
else:
|
|
357
|
-
logging.error(f"Property type {property_.value_type} not supported!")
|
|
358
352
|
raise ValueError(f"Property type {property_.value_type} not supported!")
|
|
359
353
|
|
|
360
354
|
return triples
|
|
@@ -93,7 +93,7 @@ class DMSLoader(CDFLoader[dm.InstanceApply]):
|
|
|
93
93
|
yield from issues
|
|
94
94
|
tracker.issue(issues)
|
|
95
95
|
class_name = self.class_by_view_id.get(view.as_id(), view.external_id)
|
|
96
|
-
triples = self.graph_store.
|
|
96
|
+
triples = self.graph_store.read(class_name)
|
|
97
97
|
for identifier, properties in _triples2dictionary(triples).items():
|
|
98
98
|
try:
|
|
99
99
|
yield self._create_node(identifier, properties, pydantic_cls, view_id)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
from typing import cast
|
|
3
|
+
|
|
4
|
+
from rdflib import RDF, Graph, URIRef
|
|
5
|
+
from rdflib.query import ResultRow
|
|
6
|
+
|
|
7
|
+
from cognite.neat.rules.models.entities import ClassEntity
|
|
8
|
+
from cognite.neat.rules.models.information import InformationRules
|
|
9
|
+
from cognite.neat.utils.utils import remove_namespace
|
|
10
|
+
|
|
11
|
+
from ._construct import build_construct_query
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Queries:
|
|
15
|
+
"""Helper class for storing standard queries for the graph store."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, graph: Graph, rules: InformationRules | None = None):
|
|
18
|
+
self.graph = graph
|
|
19
|
+
self.rules = rules
|
|
20
|
+
|
|
21
|
+
def list_instances_ids_of_class(self, class_uri: URIRef, limit: int = -1) -> list[URIRef]:
|
|
22
|
+
"""Get instances ids for a given class
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
class_uri: Class for which instances are to be found
|
|
26
|
+
limit: Max number of instances to return, by default -1 meaning all instances
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
List of class instance URIs
|
|
30
|
+
"""
|
|
31
|
+
query_statement = "SELECT DISTINCT ?subject WHERE { ?subject a <class> .} LIMIT X".replace(
|
|
32
|
+
"class", class_uri
|
|
33
|
+
).replace("LIMIT X", "" if limit == -1 else f"LIMIT {limit}")
|
|
34
|
+
return [cast(tuple, res)[0] for res in list(self.graph.query(query_statement))]
|
|
35
|
+
|
|
36
|
+
def list_instances_of_type(self, class_uri: URIRef) -> list[ResultRow]:
|
|
37
|
+
"""Get all triples for instances of a given class
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
class_uri: Class for which instances are to be found
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
List of triples for instances of the given class
|
|
44
|
+
"""
|
|
45
|
+
query = (
|
|
46
|
+
f"SELECT ?instance ?prop ?value "
|
|
47
|
+
f"WHERE {{ ?instance rdf:type <{class_uri}> . ?instance ?prop ?value . }} order by ?instance "
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Select queries gives an iterable of result rows
|
|
51
|
+
return cast(list[ResultRow], list(self.graph.query(query)))
|
|
52
|
+
|
|
53
|
+
def triples_of_type_instances(self, rdf_type: str) -> list[tuple[str, str, str]]:
|
|
54
|
+
"""Get all triples of a given type.
|
|
55
|
+
|
|
56
|
+
This method assumes the graph has been transformed into the default namespace.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
if self.rules:
|
|
60
|
+
query = (
|
|
61
|
+
f"SELECT ?instance ?prop ?value "
|
|
62
|
+
f"WHERE {{ ?instance a <{self.rules.metadata.namespace[rdf_type]}> . ?instance ?prop ?value . }} "
|
|
63
|
+
"order by ?instance"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
result = self.graph.query(query)
|
|
67
|
+
|
|
68
|
+
# We cannot include the RDF.type in case there is a neat:type property
|
|
69
|
+
return [remove_namespace(*triple) for triple in result if triple[1] != RDF.type] # type: ignore[misc, index]
|
|
70
|
+
else:
|
|
71
|
+
warnings.warn("No rules found for the graph store, returning empty list.", stacklevel=2)
|
|
72
|
+
return []
|
|
73
|
+
|
|
74
|
+
def construct_instances_of_class(self, class_: str, properties_optional: bool = True) -> list[tuple[str, str, str]]:
|
|
75
|
+
"""CONSTRUCT instances for a given class from the graph store
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
class_: Class entity for which we want to generate query
|
|
79
|
+
properties_optional: Whether to make all properties optional, default True
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
List of triples for instances of the given class
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
if self.rules and (
|
|
86
|
+
query := build_construct_query(
|
|
87
|
+
ClassEntity(prefix=self.rules.metadata.prefix, suffix=class_),
|
|
88
|
+
self.graph,
|
|
89
|
+
self.rules,
|
|
90
|
+
properties_optional,
|
|
91
|
+
)
|
|
92
|
+
):
|
|
93
|
+
result = self.graph.query(query)
|
|
94
|
+
|
|
95
|
+
# We cannot include the RDF.type in case there is a neat:type property
|
|
96
|
+
return [remove_namespace(*triple) for triple in result if triple[1] != RDF.type] # type: ignore[misc, index]
|
|
97
|
+
else:
|
|
98
|
+
warnings.warn("No rules found for the graph store, returning empty list.", stacklevel=2)
|
|
99
|
+
return []
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import cast
|
|
3
|
+
|
|
4
|
+
from rdflib import Graph, URIRef
|
|
5
|
+
|
|
6
|
+
from cognite.neat.rules.analysis import InformationArchitectRulesAnalysis
|
|
7
|
+
from cognite.neat.rules.models._rdfpath import (
|
|
8
|
+
AllReferences,
|
|
9
|
+
Hop,
|
|
10
|
+
RDFPath,
|
|
11
|
+
SingleProperty,
|
|
12
|
+
Traversal,
|
|
13
|
+
)
|
|
14
|
+
from cognite.neat.rules.models.entities import ClassEntity
|
|
15
|
+
from cognite.neat.rules.models.information import InformationProperty, InformationRules
|
|
16
|
+
from cognite.neat.utils.utils import most_occurring_element
|
|
17
|
+
|
|
18
|
+
from ._shared import Triple, hop2property_path
|
|
19
|
+
|
|
20
|
+
_QUERY_TEMPLATE = """CONSTRUCT {{ {graph_template} }}
|
|
21
|
+
WHERE {{ {graph_pattern}
|
|
22
|
+
{filter}
|
|
23
|
+
}}"""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def build_construct_query(
|
|
27
|
+
class_: ClassEntity,
|
|
28
|
+
graph: Graph,
|
|
29
|
+
rules: InformationRules,
|
|
30
|
+
properties_optional: bool = True,
|
|
31
|
+
class_instances: list[URIRef] | None = None,
|
|
32
|
+
) -> str | None:
|
|
33
|
+
"""Builds a CONSTRUCT query for a given class and rules and optionally filters by class instances.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
class_ : The class entity for which the query is generated.
|
|
37
|
+
graph : The graph containing instances of classes.
|
|
38
|
+
rules : The information rules to use for query generation.
|
|
39
|
+
properties_optional : Whether to make all properties optional. Defaults to True.
|
|
40
|
+
class_instances : List of class instances to filter by. Defaults to None (no filter, return all instances).
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
str: CONSTRUCT query.
|
|
44
|
+
|
|
45
|
+
!!! note "On CONSTRUCT Query"
|
|
46
|
+
CONSTRUCT query is composed of two parts: graph template and graph pattern.
|
|
47
|
+
Graph template is used the shape of instance acquired using graph pattern.
|
|
48
|
+
This allows us to create a new graph with the new shape without actually modifying
|
|
49
|
+
the original graph, or creating new instances.
|
|
50
|
+
|
|
51
|
+
The CONSTRUCT query is far less forgiving than the SELECT query. It will not return
|
|
52
|
+
anything if one of the properties that define the "shape" of the class instance is missing.
|
|
53
|
+
This is the reason why there is an option to make all properties optional, so that
|
|
54
|
+
the query will return all instances that have at least one property defined.
|
|
55
|
+
"""
|
|
56
|
+
if (
|
|
57
|
+
transformations := InformationArchitectRulesAnalysis(rules)
|
|
58
|
+
.class_property_pairs(only_rdfpath=True, consider_inheritance=True)
|
|
59
|
+
.get(class_, None)
|
|
60
|
+
):
|
|
61
|
+
templates, patterns = to_construct_triples(
|
|
62
|
+
graph, list(transformations.values()), rules.prefixes, properties_optional
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return _QUERY_TEMPLATE.format(
|
|
66
|
+
graph_template="\n".join(triples2sparql_statement(templates)),
|
|
67
|
+
graph_pattern="\n".join(triples2sparql_statement(patterns)),
|
|
68
|
+
filter="" if not class_instances else add_filter(class_instances),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
else:
|
|
72
|
+
return None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def add_filter(class_instances: list[URIRef]):
|
|
76
|
+
class_instances_formatted = [f"<{instance}>" for instance in class_instances]
|
|
77
|
+
return f"FILTER (?instance IN ({', '.join(class_instances_formatted)}))"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def to_construct_triples(
|
|
81
|
+
graph: Graph, transformations: list[InformationProperty], prefixes: dict, properties_optional: bool = True
|
|
82
|
+
) -> tuple[list[Triple], list[Triple]]:
|
|
83
|
+
"""Converts transformations of a class to CONSTRUCT triples which are used to generate CONSTRUCT query
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
graph: Graph containing instances of classes (used for property inference for hops)
|
|
87
|
+
transformations : List of transformations to use to form triples
|
|
88
|
+
prefixes : Dictionary of prefixes for namespaces
|
|
89
|
+
properties_optional : Flag indicating if properties should be optional. Defaults to True.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
tuple: Tuple of triples that define graph template and graph pattern parts of CONSTRUCT query
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
!!! note "Purely inherited transformations"
|
|
96
|
+
Assumption that neat makes is that in case of purely inherited transformations
|
|
97
|
+
we will type instance with class to which transformation belongs to.
|
|
98
|
+
|
|
99
|
+
Otherwise we will type instance with class that is most occurring in non-inherited
|
|
100
|
+
transformations.
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
# TODO: Add handling of UNIONs in rules
|
|
104
|
+
|
|
105
|
+
templates = []
|
|
106
|
+
patterns = []
|
|
107
|
+
non_inherited_starting_rdf_types = []
|
|
108
|
+
|
|
109
|
+
for transformation in transformations:
|
|
110
|
+
traversal = cast(RDFPath, transformation.transformation).traversal
|
|
111
|
+
|
|
112
|
+
# keeping track of starting rdf types of non-inherited transformations/properties
|
|
113
|
+
if isinstance(traversal, Traversal) and not transformation.inherited:
|
|
114
|
+
non_inherited_starting_rdf_types.append(traversal.class_.id)
|
|
115
|
+
|
|
116
|
+
graph_template_triple = Triple(
|
|
117
|
+
subject="?instance",
|
|
118
|
+
predicate=f"{transformation.class_.prefix}:{transformation.property_}",
|
|
119
|
+
object=f'?{re.sub(r"[^_a-zA-Z0-9/_]", "_", str(transformation.property_).lower())}',
|
|
120
|
+
optional=False,
|
|
121
|
+
)
|
|
122
|
+
templates.append(graph_template_triple)
|
|
123
|
+
|
|
124
|
+
# use case AllReferences: binding instance to certain rdf property
|
|
125
|
+
if isinstance(traversal, AllReferences):
|
|
126
|
+
graph_pattern_triple = Triple(
|
|
127
|
+
subject="BIND(?instance", predicate="AS", object=f"{graph_template_triple.object})", optional=False
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# use case SingleProperty: simple property traversal
|
|
131
|
+
elif isinstance(traversal, SingleProperty):
|
|
132
|
+
graph_pattern_triple = Triple(
|
|
133
|
+
subject=graph_template_triple.subject,
|
|
134
|
+
predicate=traversal.property.id,
|
|
135
|
+
object=graph_template_triple.object,
|
|
136
|
+
optional=True if properties_optional else not transformation.is_mandatory,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# use case Hop: property traversal with multiple hops turned into property path
|
|
140
|
+
# see: https://www.oxfordsemantic.tech/faqs/what-is-a-property-path
|
|
141
|
+
elif isinstance(traversal, Hop):
|
|
142
|
+
graph_pattern_triple = Triple(
|
|
143
|
+
subject="?instance",
|
|
144
|
+
predicate=hop2property_path(graph, traversal, prefixes),
|
|
145
|
+
object=graph_template_triple.object,
|
|
146
|
+
optional=True if properties_optional else not transformation.is_mandatory,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# other type of rdfpaths are skipped
|
|
150
|
+
else:
|
|
151
|
+
continue
|
|
152
|
+
|
|
153
|
+
patterns.append(graph_pattern_triple)
|
|
154
|
+
|
|
155
|
+
# Add first triple for graph pattern stating type of object
|
|
156
|
+
# we use most occurring here to pull out most occurring rdf type of the starting
|
|
157
|
+
# node of the transformation, or the class itself to which the transformation is
|
|
158
|
+
# defined for.
|
|
159
|
+
# This is safeguard in case there are multiple classes in the graph pattern
|
|
160
|
+
patterns.insert(
|
|
161
|
+
0,
|
|
162
|
+
Triple(
|
|
163
|
+
subject="?instance",
|
|
164
|
+
predicate="a",
|
|
165
|
+
object=(
|
|
166
|
+
most_occurring_element(non_inherited_starting_rdf_types)
|
|
167
|
+
if non_inherited_starting_rdf_types
|
|
168
|
+
else str(transformation.class_)
|
|
169
|
+
),
|
|
170
|
+
optional=False,
|
|
171
|
+
),
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
return templates, patterns
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def triples2sparql_statement(triples: list[Triple]):
|
|
178
|
+
return [
|
|
179
|
+
(
|
|
180
|
+
f"OPTIONAL {{ {triple.subject} {triple.predicate} {triple.object} . }}"
|
|
181
|
+
if triple.optional
|
|
182
|
+
else f"{triple.subject} {triple.predicate} {triple.object} ."
|
|
183
|
+
)
|
|
184
|
+
for triple in triples
|
|
185
|
+
]
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from collections.abc import Iterable
|
|
3
|
+
from typing import ClassVar, cast
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
6
|
+
from rdflib import Graph, Literal, Namespace
|
|
7
|
+
from rdflib.term import URIRef
|
|
8
|
+
|
|
9
|
+
from cognite.neat.constants import PREFIXES
|
|
10
|
+
from cognite.neat.rules.models._rdfpath import (
|
|
11
|
+
Hop,
|
|
12
|
+
Step,
|
|
13
|
+
)
|
|
14
|
+
from cognite.neat.utils.utils import remove_namespace, uri_to_short_form
|
|
15
|
+
|
|
16
|
+
if sys.version_info >= (3, 11):
|
|
17
|
+
from typing import Self
|
|
18
|
+
else:
|
|
19
|
+
from typing_extensions import Self
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Triple(BaseModel):
|
|
23
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(
|
|
24
|
+
populate_by_name=True, arbitrary_types_allowed=True, strict=False, extra="allow"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
subject: str | URIRef
|
|
28
|
+
predicate: str | URIRef
|
|
29
|
+
object: str | URIRef | Literal | None = None
|
|
30
|
+
optional: bool = Field(
|
|
31
|
+
description="Indicates whether a triple is optional, used when building SPARQL query",
|
|
32
|
+
default=False,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def from_rdflib_triple(cls, triple: tuple[URIRef, URIRef, URIRef | Literal]) -> Self:
|
|
37
|
+
return cls(subject=triple[0], predicate=triple[1], object=triple[2])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def generate_prefix_header(prefixes: dict[str, Namespace] = PREFIXES) -> str:
|
|
41
|
+
"""Generate prefix header which is added to SPARQL query and allows for shorten query statements
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
prefixes : dict
|
|
46
|
+
Dict containing prefix - namespace pairs, default PREFIXES
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
str
|
|
51
|
+
Prefix header
|
|
52
|
+
"""
|
|
53
|
+
return "".join(f"PREFIX {key}:<{value}>\n" for key, value in prefixes.items())
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def get_predicate_id(
|
|
57
|
+
graph: Graph, subject_type_id: str, object_type_id: str, prefixes: dict[str, Namespace] = PREFIXES
|
|
58
|
+
) -> URIRef:
|
|
59
|
+
"""Returns predicate (aka property) URI (i.e., ID) that connects subject and object
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
graph : Graph
|
|
64
|
+
Data model graph or data model instance (aka knowledge graph)
|
|
65
|
+
subject_type_id : str
|
|
66
|
+
ID of subject type (aka subject class)
|
|
67
|
+
object_type_id : str
|
|
68
|
+
ID of object type (aka object class)
|
|
69
|
+
prefixes : dict, optional
|
|
70
|
+
Dict containing prefix - namespace pairs, default PREFIXES
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
URIRef
|
|
75
|
+
ID of predicate (aka property) connecting subject and object
|
|
76
|
+
"""
|
|
77
|
+
query = """
|
|
78
|
+
|
|
79
|
+
SELECT ?predicateTypeID
|
|
80
|
+
WHERE {
|
|
81
|
+
?subjectInstanceID a subjectTypeID .
|
|
82
|
+
?objectInstanceID a objectTypeID .
|
|
83
|
+
?subjectInstanceID ?predicateTypeID ?objectInstanceID .
|
|
84
|
+
} LIMIT 1"""
|
|
85
|
+
|
|
86
|
+
query = query.replace("insertPrefixes", generate_prefix_header(prefixes))
|
|
87
|
+
final_query = query.replace("subjectTypeID", subject_type_id).replace("objectTypeID", object_type_id)
|
|
88
|
+
res = list(cast(tuple, graph.query(final_query)))
|
|
89
|
+
|
|
90
|
+
if len(res) != 1:
|
|
91
|
+
raise ValueError("Subject and Object must have exactly 1 relation!")
|
|
92
|
+
|
|
93
|
+
return res[0][0]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def hop2property_path(graph: Graph, hop: Hop, prefixes: dict[str, Namespace]) -> str:
|
|
97
|
+
"""Converts hop to property path string
|
|
98
|
+
|
|
99
|
+
Parameters
|
|
100
|
+
----------
|
|
101
|
+
graph : Graph
|
|
102
|
+
Graph containing instances of classes
|
|
103
|
+
hop : Hop
|
|
104
|
+
Hop to convert
|
|
105
|
+
prefixes : dict[str, Namespace]
|
|
106
|
+
Dictionary of prefixes to use for compression and predicate querying
|
|
107
|
+
|
|
108
|
+
Returns
|
|
109
|
+
-------
|
|
110
|
+
str
|
|
111
|
+
Property path string for hop traversal (e.g. ^rdf:type/rdfs:subClassOf)
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
# setting previous step to origin, as we are starting from there
|
|
115
|
+
previous_step = Step(class_=hop.class_, direction="origin")
|
|
116
|
+
|
|
117
|
+
# add triples for all steps until destination
|
|
118
|
+
property_path = ""
|
|
119
|
+
for current_step in hop.traversal:
|
|
120
|
+
sub_entity, obj_entity = (
|
|
121
|
+
(current_step, previous_step) if current_step.direction == "source" else (previous_step, current_step)
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
predicate_raw = get_predicate_id(graph, sub_entity.class_.id, obj_entity.class_.id, prefixes)
|
|
125
|
+
|
|
126
|
+
predicate = uri_to_short_form(predicate_raw, prefixes)
|
|
127
|
+
|
|
128
|
+
predicate = f"^{predicate}" if current_step.direction == "source" else predicate
|
|
129
|
+
property_path += f"{predicate}/"
|
|
130
|
+
|
|
131
|
+
previous_step = current_step
|
|
132
|
+
|
|
133
|
+
if previous_step.property:
|
|
134
|
+
return property_path + previous_step.property.id
|
|
135
|
+
else:
|
|
136
|
+
# removing "/" at the end of property path if there is no property at the end
|
|
137
|
+
return property_path[:-1]
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def triples2dictionary(triples: Iterable[tuple[URIRef, URIRef, str | URIRef]]) -> dict[URIRef, dict[str, list[str]]]:
|
|
141
|
+
"""Converts list of triples to dictionary"""
|
|
142
|
+
dictionary: dict[URIRef, dict[str, list[str]]] = {}
|
|
143
|
+
for triple in triples:
|
|
144
|
+
id_: str
|
|
145
|
+
property_: str
|
|
146
|
+
value: str
|
|
147
|
+
uri: URIRef
|
|
148
|
+
|
|
149
|
+
id_, property_, value = remove_namespace(*triple) # type: ignore[misc]
|
|
150
|
+
uri = triple[0]
|
|
151
|
+
|
|
152
|
+
if uri not in dictionary:
|
|
153
|
+
dictionary[uri] = {"external_id": [id_]}
|
|
154
|
+
|
|
155
|
+
if property_ not in dictionary[uri]:
|
|
156
|
+
dictionary[uri][property_] = [value]
|
|
157
|
+
else:
|
|
158
|
+
dictionary[uri][property_].append(value)
|
|
159
|
+
return dictionary
|
|
@@ -5,18 +5,17 @@ from datetime import datetime, timezone
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from typing import cast
|
|
7
7
|
|
|
8
|
-
from rdflib import
|
|
8
|
+
from rdflib import Graph, Namespace, URIRef
|
|
9
9
|
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore
|
|
10
|
-
from rdflib.query import ResultRow
|
|
11
10
|
|
|
12
11
|
from cognite.neat.constants import DEFAULT_NAMESPACE
|
|
13
12
|
from cognite.neat.graph._shared import MIMETypes
|
|
14
13
|
from cognite.neat.graph.extractors import RdfFileExtractor, TripleExtractors
|
|
15
14
|
from cognite.neat.graph.models import Triple
|
|
15
|
+
from cognite.neat.graph.queries import Queries
|
|
16
16
|
from cognite.neat.graph.transformers import Transformers
|
|
17
17
|
from cognite.neat.rules.models.entities import ClassEntity
|
|
18
18
|
from cognite.neat.rules.models.information import InformationRules
|
|
19
|
-
from cognite.neat.utils import remove_namespace
|
|
20
19
|
from cognite.neat.utils.auxiliary import local_import
|
|
21
20
|
|
|
22
21
|
from ._provenance import Change, Provenance
|
|
@@ -59,32 +58,30 @@ class NeatGraphStore:
|
|
|
59
58
|
)
|
|
60
59
|
|
|
61
60
|
if rules:
|
|
62
|
-
self.rules
|
|
63
|
-
self.base_namespace = self.rules.metadata.namespace
|
|
64
|
-
self.provenance.append(
|
|
65
|
-
Change.record(
|
|
66
|
-
activity=f"{type(self)}.rules",
|
|
67
|
-
start=_start,
|
|
68
|
-
end=datetime.now(timezone.utc),
|
|
69
|
-
description=f"Added rules to graph store as {type(self.rules).__name__}",
|
|
70
|
-
)
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
if self.rules.prefixes:
|
|
74
|
-
self._upsert_prefixes(self.rules.prefixes)
|
|
75
|
-
self.provenance.append(
|
|
76
|
-
Change.record(
|
|
77
|
-
activity=f"{type(self).__name__}._upsert_prefixes",
|
|
78
|
-
start=_start,
|
|
79
|
-
end=datetime.now(timezone.utc),
|
|
80
|
-
description="Upsert prefixes to graph store",
|
|
81
|
-
)
|
|
82
|
-
)
|
|
83
|
-
|
|
61
|
+
self.add_rules(rules)
|
|
84
62
|
else:
|
|
85
63
|
self.base_namespace = DEFAULT_NAMESPACE
|
|
86
64
|
|
|
87
|
-
self.queries =
|
|
65
|
+
self.queries = Queries(self.graph, self.rules)
|
|
66
|
+
|
|
67
|
+
def add_rules(self, rules: InformationRules) -> None:
|
|
68
|
+
"""This method is used to add rules to the graph store and it is the only correct
|
|
69
|
+
way to add rules to the graph store, after the graph store has been initialized."""
|
|
70
|
+
|
|
71
|
+
self.rules = rules
|
|
72
|
+
self.base_namespace = self.rules.metadata.namespace
|
|
73
|
+
self.queries = Queries(self.graph, self.rules)
|
|
74
|
+
self.provenance.append(
|
|
75
|
+
Change.record(
|
|
76
|
+
activity=f"{type(self)}.rules",
|
|
77
|
+
start=datetime.now(timezone.utc),
|
|
78
|
+
end=datetime.now(timezone.utc),
|
|
79
|
+
description=f"Added rules to graph store as {type(self.rules).__name__}",
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
if self.rules.prefixes:
|
|
84
|
+
self._upsert_prefixes(self.rules.prefixes)
|
|
88
85
|
|
|
89
86
|
def _upsert_prefixes(self, prefixes: dict[str, Namespace]) -> None:
|
|
90
87
|
"""Adds prefixes to the graph store."""
|
|
@@ -181,7 +178,7 @@ class NeatGraphStore:
|
|
|
181
178
|
warnings.warn("Desired type not found in graph!", stacklevel=2)
|
|
182
179
|
return []
|
|
183
180
|
|
|
184
|
-
return
|
|
181
|
+
return self.queries.construct_instances_of_class(class_)
|
|
185
182
|
|
|
186
183
|
def _parse_file(
|
|
187
184
|
self,
|
|
@@ -281,63 +278,3 @@ class NeatGraphStore:
|
|
|
281
278
|
description=transformer.description,
|
|
282
279
|
)
|
|
283
280
|
)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
class _Queries:
|
|
287
|
-
"""Helper class for storing standard queries for the graph store."""
|
|
288
|
-
|
|
289
|
-
def __init__(self, store: NeatGraphStore):
|
|
290
|
-
self.store = store
|
|
291
|
-
|
|
292
|
-
def list_instances_ids_of_class(self, class_uri: URIRef, limit: int = -1) -> list[URIRef]:
|
|
293
|
-
"""Get instances ids for a given class
|
|
294
|
-
|
|
295
|
-
Args:
|
|
296
|
-
class_uri: Class for which instances are to be found
|
|
297
|
-
limit: Max number of instances to return, by default -1 meaning all instances
|
|
298
|
-
|
|
299
|
-
Returns:
|
|
300
|
-
List of class instance URIs
|
|
301
|
-
"""
|
|
302
|
-
query_statement = "SELECT DISTINCT ?subject WHERE { ?subject a <class> .} LIMIT X".replace(
|
|
303
|
-
"class", class_uri
|
|
304
|
-
).replace("LIMIT X", "" if limit == -1 else f"LIMIT {limit}")
|
|
305
|
-
return [cast(tuple, res)[0] for res in list(self.store.graph.query(query_statement))]
|
|
306
|
-
|
|
307
|
-
def list_instances_of_type(self, class_uri: URIRef) -> list[ResultRow]:
|
|
308
|
-
"""Get all triples for instances of a given class
|
|
309
|
-
|
|
310
|
-
Args:
|
|
311
|
-
class_uri: Class for which instances are to be found
|
|
312
|
-
|
|
313
|
-
Returns:
|
|
314
|
-
List of triples for instances of the given class
|
|
315
|
-
"""
|
|
316
|
-
query = (
|
|
317
|
-
f"SELECT ?instance ?prop ?value "
|
|
318
|
-
f"WHERE {{ ?instance rdf:type <{class_uri}> . ?instance ?prop ?value . }} order by ?instance "
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
# Select queries gives an iterable of result rows
|
|
322
|
-
return cast(list[ResultRow], list(self.store.graph.query(query)))
|
|
323
|
-
|
|
324
|
-
def triples_of_type_instances(self, rdf_type: str) -> list[tuple[str, str, str]]:
|
|
325
|
-
"""Get all triples of a given type.
|
|
326
|
-
|
|
327
|
-
This method assumes the graph has been transformed into the default namespace.
|
|
328
|
-
"""
|
|
329
|
-
|
|
330
|
-
if self.store.rules:
|
|
331
|
-
query = (
|
|
332
|
-
f"SELECT ?instance ?prop ?value "
|
|
333
|
-
f"WHERE {{ ?instance a <{self.store.rules.metadata.namespace[rdf_type]}> . ?instance ?prop ?value . }} "
|
|
334
|
-
"order by ?instance"
|
|
335
|
-
)
|
|
336
|
-
|
|
337
|
-
result = self.store.graph.query(query)
|
|
338
|
-
|
|
339
|
-
# We cannot include the RDF.type in case there is a neat:type property
|
|
340
|
-
return [remove_namespace(*triple) for triple in result if triple[1] != RDF.type] # type: ignore[misc, index]
|
|
341
|
-
else:
|
|
342
|
-
warnings.warn("No rules found for the graph store, returning empty list.", stacklevel=2)
|
|
343
|
-
return []
|