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

Fix serialised ontology iri #341

Merged
merged 4 commits into from
Jan 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions ontopy/excelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pyparsing
import pandas as pd
import ontopy
from ontopy import World, get_ontology
from ontopy import World
from ontopy.utils import NoSuchLabelError
from ontopy.manchester import evaluate
import owlready2 # pylint: disable=C0411
Expand Down Expand Up @@ -64,10 +64,7 @@ def create_ontology_from_pandas( # pylint: disable=too-many-locals,too-many-bra
data = data.astype({"prefLabel": "str"})

# Make new ontology
world = World()
onto = world.get_ontology(base_iri)

onto, catalog = get_metadata_from_dataframe(metadata, onto)
onto, catalog = get_metadata_from_dataframe(metadata, base_iri)

# base_iri from metadata if it exists and base_iri_from_metadata
if not base_iri_from_metadata:
Expand Down Expand Up @@ -155,17 +152,14 @@ def create_ontology_from_pandas( # pylint: disable=too-many-locals,too-many-bra

def get_metadata_from_dataframe( # pylint: disable=too-many-locals,too-many-branches,too-many-statements
metadata: pd.DataFrame,
onto: owlready2.Ontology = None,
base_iri: str,
base_iri_from_metadata: bool = True,
catalog: dict = None,
) -> Tuple[ontopy.ontology.Ontology, dict]:
"""
Populate ontology with metada from pd.DataFrame
Create ontology with metadata from pd.DataFrame
"""

if onto is None:
francescalb marked this conversation as resolved.
Show resolved Hide resolved
onto = get_ontology()

# base_iri from metadata if it exists and base_iri_from_metadata
if base_iri_from_metadata:
try:
Expand All @@ -175,10 +169,13 @@ def get_metadata_from_dataframe( # pylint: disable=too-many-locals,too-many-bra
"More than one Ontology IRI given. The first was chosen."
)
base_iri = base_iris[0] + "#"
onto.base_iri = base_iri
except (TypeError, ValueError, AttributeError):
pass

# Make new ontology
world = World()
onto = world.get_ontology(base_iri)

# Get imported ontologies from metadata
try:
imported_ontology_paths = _parse_literal(
Expand Down