Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add IMF rules importer (#552) #571

Merged
merged 9 commits into from
Jul 24, 2024
Merged

feat: Add IMF rules importer (#552) #571

merged 9 commits into from
Jul 24, 2024

Conversation

nikokaoja
Copy link
Collaborator

@nikokaoja nikokaoja commented Jul 24, 2024

@bhtvedt made this PR:

  • feat: Add IMF rules importer

A new step for importing rules has been added. The step converts Information Modelling Framework (IMF) types, given as SHACL shapes, into rules.

The new importer follows the compliance rules set by the OWL Importer, but most of the logic are, in this case, included the SPARQL queries. However, the validation checks are kept to ensure conformance.

The IMF identifiers are given as UUIDs, but CDF does not allow identifiers starting with a number. All the relevant identifiers are therefore prefixed with "IMF_"

IMF - attributes are properties that are described with several triples. An attribute contains relations to reference data describing the meaning of the attribute, as well as potential qualifiers and units of measure. To ensure that this information is included the attributes are created as both a class and property. This punning is required to ensure that both the usage of the attribute relative to an IMF block or terminal and the relationship to relevant reference data is captured.

  • fix: Update value type

In cases where a sh:property points to a sh:class or a sh:qualifiedValueShape the corresponding value is set as the expected value type of the property.

The logic should also cover rdfs:range.


* feat: Add IMF rules importer

A ned step for importing rules has been added. The step converts
Information Modelling Framework (IMF) types, given as SHACL shapes,
into rules.

The new importer follows the compliance rules set by the OWL Importer,
but most of the logic are, in this case, included the SPARQL queries.
However, the validation checks are kept to ensure conformance.

The IMF identifiers are given as UUIDs, but CDF does not allow identifiers
starting with a number. All the relevant identifiers are therefore prefixed
with "IMF_"

IMF - attributes are properties that are described with several triples.
An attribute contains relations to reference data describing the meaning
of the attribute, as well as potential qualifiers and units of measure.
To ensure that this information is included the attributes are created as
both a class and property. This punning is required to ensure that both
the usage of the attribute relative to an IMF block or terminal and the
relationship to relevant reference data is captured.

* fix: Update value type

In cases where a sh:property points to a sh:class or a sh:qualifiedValueShape
the corresponding value is set as the expected value type of the property.

The logic should also cover rdfs:range.

---------

Co-authored-by: Tvedt <bard.tvedt@akersolutions.com>
Copy link

github-actions bot commented Jul 24, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
12913 8493 66% 60% 🟢

New Files

File Coverage Status
cognite/neat/rules/importers/_rdf/init.py 100% 🟢
cognite/neat/rules/importers/_rdf/_imf2rules/init.py 100% 🟢
cognite/neat/rules/importers/_rdf/_imf2rules/_imf2classes.py 33% 🟢
cognite/neat/rules/importers/_rdf/_imf2rules/_imf2metadata.py 67% 🟢
cognite/neat/rules/importers/_rdf/_imf2rules/_imf2properties.py 33% 🟢
cognite/neat/rules/importers/_rdf/_owl2rules/_owl2classes.py 92% 🟢
cognite/neat/rules/importers/_rdf/_owl2rules/_owl2metadata.py 100% 🟢
cognite/neat/rules/importers/_rdf/_owl2rules/_owl2properties.py 92% 🟢
cognite/neat/rules/importers/_rdf/_owl2rules/_owl2rules.py 94% 🟢
cognite/neat/rules/importers/_rdf/_shared.py 84% 🟢
TOTAL 79% 🟢

Modified Files

File Coverage Status
cognite/neat/_version.py 100% 🟢
cognite/neat/rules/importers/init.py 77% 🟢
cognite/neat/workflows/steps/lib/current/rules_importer.py 0% 🟢
TOTAL 59% 🟢

updated for commit: abf0904 by action🐍

Copy link
Collaborator

@doctrino doctrino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few concerns around dealing with errors and warnings, but that can be moved to a future maintenance task.

Most important thing to address is whether the init signature is correct and whether to introduce factory methods.


Args:
filepath: Path to OWL ontology
filepath: Path to RDF file containing the SHACL Shapes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this take in filepath? It looks like you immediately start up a graph. So suggest that the init takes a Graph, or a NeatStore, and then have a factory method for this.

"Properties": parse_owl_properties(graph),
"Metadata": parse_imf_metadata(),
"Classes": parse_imf_to_classes(graph),
"Properties": parse_imf_to_properties(graph),
}

components = make_components_compliant(components)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below there is no catching of errors if the InformationRules failes

for class_, class_grouped_df in class_grouped_dfs:
property_grouped_dfs = class_grouped_df.groupby("Property")
for property_, property_grouped_df in property_grouped_dfs:
clean_list += [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be warnings here if there are multiple values for any of the properties or is that not possible?

@nikokaoja nikokaoja merged commit 6ab0dd3 into main Jul 24, 2024
7 checks passed
@nikokaoja nikokaoja deleted the NEAT-384-IMFImporter branch July 24, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants