Skip to content

Commit

Permalink
fix imf import error (#586)
Browse files Browse the repository at this point in the history
* fix imf import error

* fix failures with OWL

* added test

* bump version added changelog
  • Loading branch information
nikokaoja authored Aug 20, 2024
1 parent d318c7d commit 6cb8f85
Show file tree
Hide file tree
Showing 12 changed files with 991 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: run-explorer run-tests run-linters build-ui build-python build-docker run-docker compose-up
version="0.88.2"
version="0.88.3"
run-explorer:
@echo "Running explorer API server..."
# open "http://localhost:8000/static/index.html" || true
Expand Down
2 changes: 1 addition & 1 deletion cognite/neat/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.88.2"
__version__ = "0.88.3"
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def parse_imf_to_classes(graph: Graph, language: str = "en") -> list[dict]:
BIND(IF(!bound(?parent) && ?type = imf:AttributeType, imf:Attribute, ?parent) AS ?parentClass)
# Rebind the IRI of the IMF-type to the ?reference variable to align with dataframe column headers
# This is solely for readability, the ?imfClass could have been returnered directly instead of ?reference
# This is solely for readability, the ?imfClass could have been returned directly instead of ?reference
BIND(?imfClass AS ?reference)
FILTER (!isBlank(?class))
Expand Down
8 changes: 5 additions & 3 deletions cognite/neat/rules/importers/_rdf/_imf2rules/_imf2rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IMFImporter(BaseImporter):
"""

def __init__(self, filepath: Path):
self.owl_filepath = filepath
self.filepath = filepath

@overload
def to_rules(self, errors: Literal["raise"], role: RoleTypes | None = None) -> VerifiedRules: ...
Expand All @@ -47,11 +47,13 @@ def to_rules(
) -> tuple[VerifiedRules | None, IssueList]: ...

def to_rules(
self, errors: Literal["raise", "continue"] = "continue", role: RoleTypes | None = None
self,
errors: Literal["raise", "continue"] = "continue",
role: RoleTypes | None = None,
) -> tuple[VerifiedRules | None, IssueList] | VerifiedRules:
graph = Graph()
try:
graph.parse(self.owl_filepath)
graph.parse(self.filepath)
except Exception as e:
raise Exception(f"Could not parse owl file: {e}") from e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def parse_owl_classes(graph: Graph, language: str = "en") -> list[dict]:
FILTER (!bound(?parentClass) || !isBlank(?parentClass))
FILTER (!bound(?name) || LANG(?name) = "" || LANGMATCHES(LANG(?name), "en"))
FILTER (!bound(?description) || LANG(?description) = "" || LANGMATCHES(LANG(?description), "en"))
BIND(?class AS ?reference)
}
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def parse_owl_properties(graph: Graph, language: str = "en") -> list[dict]:
FILTER (!bound(?description) || LANG(?description) = "" || LANGMATCHES(LANG(?description), "en"))
BIND(IF(bound(?minCount), ?minCount, 0) AS ?minCount)
BIND(IF(bound(?maxCount), ?maxCount, 1) AS ?maxCount)
BIND(?property AS ?reference)
}
"""

Expand Down
6 changes: 3 additions & 3 deletions cognite/neat/rules/importers/_rdf/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def parse_raw_classes_dataframe(query_results: list[tuple]) -> pd.DataFrame:
"Comment",
],
)

if df.empty:
return df

# # remove NaNs
df.replace(np.nan, "", regex=True, inplace=True)

df.Reference = df.Class
df.Class = df.Class.apply(lambda x: remove_namespace_from_uri(x))
df["Match Type"] = len(df) * [MatchType.exact]
df["Comment"] = len(df) * [None]
Expand Down Expand Up @@ -202,7 +202,7 @@ def parse_raw_properties_dataframe(query_results: list[tuple]) -> pd.DataFrame:
return df

df.replace(np.nan, "", regex=True, inplace=True)
df.Reference = df.Reference if df.Reference.unique() else df.Property.copy(deep=True)

df.Class = df.Class.apply(lambda x: remove_namespace_from_uri(x))
df.Property = df.Property.apply(lambda x: remove_namespace_from_uri(x))
df["Value Type"] = df["Value Type"].apply(lambda x: remove_namespace_from_uri(x))
Expand Down Expand Up @@ -231,7 +231,7 @@ def clean_up_properties(df: pd.DataFrame) -> pd.DataFrame:
"Min Count": property_grouped_df["Min Count"].unique()[0],
"Max Count": property_grouped_df["Max Count"].unique()[0],
"Default": property_grouped_df["Default"].unique()[0],
"Reference": property_grouped_df["Reference"].unique()[0] or property_,
"Reference": property_grouped_df["Reference"].unique()[0],
"Match Type": property_grouped_df["Match Type"].unique()[0],
"Comment": property_grouped_df["Comment"].unique()[0],
"_property_type": property_grouped_df["_property_type"].unique()[0],
Expand Down
9 changes: 9 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Changes are grouped as follows:
- `Security` in case of vulnerabilities.


## [0.88.3] - 20-08-24
### Fixed
- IMF rules importer failing due to references
### Improved
- Handling of references for OWL importer
### Added
- Test for IMF importer


## [0.88.2] - 24-07-24
### Added
- IMF rules importer
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cognite-neat"
version = "0.88.2"
version = "0.88.3"
readme = "README.md"
description = "Knowledge graph transformation"
authors = [
Expand Down
1 change: 1 addition & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
GRAPH_CAPTURING_SHEET = DATA_FOLDER / "sheet2cdf-graph-capturing.xlsx"
WIND_ONTOLOGY = DATA_FOLDER / "wind-energy.owl"
DEXPI_EXAMPLE = DATA_FOLDER / "depxi_example.xml"
IMF_EXAMPLE = DATA_FOLDER / "TempTransmitterComplete.ttl"

CLASSIC_CDF_EXTRACTOR_DATA = DATA_FOLDER / "class_cdf_extractor_data"
Loading

0 comments on commit 6cb8f85

Please sign in to comment.