Skip to content

Commit 1c9d00b

Browse files
authored
Excel2onto improve errormsg (#890)
# Description The excel2onto feature failed with bad error messages for: - Leading or trailing white spaces in iris of imported ontologies. These are now removed. - the code failed with bad warnings if extra non-existing annotations were added. Improved error message and skip the annotation if option --force is chosen.
1 parent 5699203 commit 1c9d00b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

ontopy/excelparser.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ def get_metadata_from_dataframe( # pylint: disable=too-many-locals,too-many-bra
518518
# for location in imports:
519519
location = row["Imported ontologies"]
520520
if not pd.isna(location) and location not in locations:
521+
location = location.strip()
521522
imported = onto.world.get_ontology(location).load()
522523
onto.imported_ontologies.append(imported)
523524
catalog[imported.base_iri.rstrip("#/")] = location
@@ -847,7 +848,24 @@ def _add_entities(
847848
):
848849
for annotation in row["Other annotations"].split(";"):
849850
key, value = annotation.split("=", 1)
850-
entity[key.strip(" ")] = english(value.strip(" "))
851+
try:
852+
entity[key.strip(" ")] = english(value.strip(" "))
853+
except NoSuchLabelError as exc:
854+
msg = (
855+
f"Error in Other annotation assignment for: "
856+
f"{entity}. "
857+
f"Annotation to be Evaluated: {annotation}. "
858+
f"{exc}. Are you sure that the annotation"
859+
f" {annotation} is added to the "
860+
"AnnotationsProperties tab correctly?"
861+
)
862+
if force is True:
863+
warnings.warn(msg)
864+
entities_with_errors[
865+
"errors_in_properties"
866+
].append(entity.name)
867+
else:
868+
raise ExcelError(msg) from exc
851869

852870
remaining_rows.difference_update(added_rows)
853871
# Detect infinite loop...

0 commit comments

Comments
 (0)