Skip to content

Commit

Permalink
Merge branch 'ci/dependabot-updates' into dependabot/pip/ci/dependabo…
Browse files Browse the repository at this point in the history
…t-updates/mkdocstrings-python-legacy--approx-eq-0.25.1
  • Loading branch information
francescalb committed May 8, 2024
2 parents ad45b7d + f418dd3 commit 0e71086
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/ambv/black
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black
name: Blacken
Expand Down
2 changes: 1 addition & 1 deletion ontopy/excelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def _add_entities(
or row["Other annotations"] == "nan"
):
for annotation in row["Other annotations"].split(";"):
key, value = annotation.split("=")
key, value = annotation.split("=", 1)
entity[key.strip(" ")] = english(value.strip(" "))

remaining_rows.difference_update(added_rows)
Expand Down
51 changes: 48 additions & 3 deletions ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ def save(
write_catalog_file=False,
append_catalog=False,
catalog_file="catalog-v001.xml",
**kwargs,
) -> Path:
"""Writes the ontology to file.
Expand Down Expand Up @@ -915,6 +916,7 @@ def save(
# pylint: disable=redefined-builtin,too-many-arguments
# pylint: disable=too-many-statements,too-many-branches
# pylint: disable=too-many-locals,arguments-renamed,invalid-name

if not _validate_installed_version(
package="rdflib", min_version="6.0.0"
) and format == FMAP.get("ttl", ""):
Expand All @@ -940,7 +942,9 @@ def save(
raise TypeError("`filename` and `format` cannot both be None.")
else:
file = filename
filepath = os.path.join(dir, file)
filepath = os.path.join(
dir, file if isinstance(file, (str, Path)) else file.name
)
returnpath = filepath

dir = Path(filepath).resolve().parent
Expand Down Expand Up @@ -980,6 +984,7 @@ def save(
recursive=False,
squash=False,
write_catalog_file=False,
**kwargs,
)

if write_catalog_file:
Expand Down Expand Up @@ -1045,7 +1050,7 @@ def save(

graph.serialize(destination=filepath, format=format)
elif format in OWLREADY2_FORMATS:
super().save(file=filepath, format=fmt)
super().save(file=filepath, format=fmt, **kwargs)
else:
# The try-finally clause is needed for cleanup and because
# we have to provide delete=False to NamedTemporaryFile
Expand All @@ -1056,7 +1061,7 @@ def save(
suffix=".owl", delete=False
) as handle:
tmpfile = handle.name
super().save(tmpfile, format="ntriples")
super().save(tmpfile, format="ntriples", **kwargs)
graph = rdflib.Graph()
graph.parse(tmpfile, format="ntriples")
graph.namespace_manager.bind(
Expand Down Expand Up @@ -1331,12 +1336,46 @@ def sync_reasoner(
Keyword arguments are passed to the underlying owlready2 function.
"""
# pylint: disable=too-many-branches

removed_equivalent = defaultdict(list)
removed_subclasses = defaultdict(list)

if reasoner == "FaCT++":
sync = sync_reasoner_factpp
elif reasoner == "Pellet":
sync = owlready2.sync_reasoner_pellet
elif reasoner == "HermiT":
sync = owlready2.sync_reasoner_hermit

# Remove custom data propertyes, otherwise HermiT will crash
datatype_iri = "http://www.w3.org/2000/01/rdf-schema#Datatype"

for cls in self.classes(imported=include_imported):
remove_eq = []
for i, r in enumerate(cls.equivalent_to):
if isinstance(r, owlready2.Restriction):
if (
hasattr(r.value.__class__, "iri")
and r.value.__class__.iri == datatype_iri
):
remove_eq.append(i)
removed_equivalent[cls].append(r)
for i in reversed(remove_eq):
del cls.equivalent_to[i]

remove_subcls = []
for i, r in enumerate(cls.is_a):
if isinstance(r, owlready2.Restriction):
if (
hasattr(r.value.__class__, "iri")
and r.value.__class__.iri == datatype_iri
):
remove_subcls.append(i)
removed_subclasses[cls].append(r)
for i in reversed(remove_subcls):
del cls.is_a[i]

else:
raise ValueError(
f"Unknown reasoner '{reasoner}'. Supported reasoners "
Expand All @@ -1353,6 +1392,12 @@ def sync_reasoner(
else:
sync(self, **kwargs)

# Restore removed custom data properties
for cls, eqs in removed_equivalent.items():
cls.extend(eqs)
for cls, subcls in removed_subclasses.items():
cls.extend(subcls)

def sync_attributes( # pylint: disable=too-many-branches
self,
name_policy=None,
Expand Down
Binary file modified tests/test_excelparser/onto.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/test_excelparser/result_ontology/fromexcelonto.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

:EMMO_7c8ba943-15cf-5621-98a3-ed1e7e68fee8 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "A special boundary."@en ;
:EMMO_98871837-aa90-5eef-9a56-926ae8beebbb "\"A text about this type of boundary\""@en ;
:EMMO_98871837-aa90-5eef-9a56-926ae8beebbb "\"A text about this type of=boundary\""@en ;
rdfs:subClassOf :EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 ;
skos:prefLabel "SpecialBoundary"@en .

Expand Down
5 changes: 5 additions & 0 deletions tests/testonto/domainonto.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 a owl:AnnotationProperty ;
skos:prefLabel "elucidation"@en ;
rdfs:comment "Short enlightening explanation aimed to facilitate the user in drawing the connection (interpretation) between a OWL entity and the real world object(s) for which it stands."@en .

emmo:EMMO_c7b62dd7_063a_4c2a_8504_42f7264ba83f a owl:AnnotationProperty ;
rdfs:subPropertyOf rdfs:comment ;
skos:prefLabel "comment"@en ;
rdfs:comment "A text that add some information about the entity."@en .

:EMMO_70fe84ff_99b6_4206_a9fc_9a8931836d84 a owl:AnnotationProperty ;
rdfs:subPropertyOf rdfs:comment ;
skos:prefLabel "definition"@en ;
Expand Down
25 changes: 22 additions & 3 deletions tools/ontoconvert
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ from rdflib.util import guess_format
from ontopy import get_ontology
from ontopy.utils import annotate_source, rename_iris, copy_annotation

import owlready2 # pylint: disable=wrong-import-order
import owlready2.reasoning # pylint: disable=wrong-import-order


def main(argv: list = None):
"""Main run function.
Expand Down Expand Up @@ -84,8 +87,10 @@ def main(argv: list = None):
"http://www.w3.org/2004/02/skos/core#prefLabel"
"-->http://www.w3.org/2000/01/rdf-schema#label "
"--copy-annotation=elucidation"
"-->http://www.w3.org/2000/01/rdf-schema#comment`"
"-->http://www.w3.org/2000/01/rdf-schema#comment` "
"--copy-annotation=definition"
"-->http://www.w3.org/2000/01/rdf-schema#comment` "
"--copy-annotation=comment"
"-->http://www.w3.org/2000/01/rdf-schema#comment`"
),
)
Expand All @@ -107,7 +112,7 @@ def main(argv: list = None):
metavar="NAME",
help=(
"Add additional relations inferred by the reasoner. Supported "
'reasoners are "FaCT++" (default), "HermiT" and "Pellet".'
'reasoners are "HermiT" (default), "Pellet" and "FaCT++".'
),
)
parser.add_argument(
Expand All @@ -116,7 +121,14 @@ def main(argv: list = None):
action="store_true",
help="Do not infer imported ontologies.",
)
# To be implemented...
parser.add_argument(
"--java-executable",
help="Path to Java executable to use. Default is `java`.",
)
parser.add_argument(
"--java-memory",
help="Maximum memory allocated to Java in MB. Default is 2000.",
)
parser.add_argument(
"--iri",
"-I",
Expand Down Expand Up @@ -218,6 +230,12 @@ def main(argv: list = None):
if not output_format:
output_format = "xml"

# Settings for running Java
if args.java_executable:
owlready2.JAVA_EXE = args.java_executable
if args.java_memory:
owlready2.reasoning.JAVA_MEMORY = int(args.java_memory)

# Annotations to copy with --copy-emmo-annotations
if args.copy_emmo_annotations:
args.copy_annotation.extend(
Expand All @@ -226,6 +244,7 @@ def main(argv: list = None):
"-->http://www.w3.org/2000/01/rdf-schema#label",
"elucidation-->http://www.w3.org/2000/01/rdf-schema#comment",
"definition-->http://www.w3.org/2000/01/rdf-schema#comment",
"comment-->http://www.w3.org/2000/01/rdf-schema#comment",
]
)

Expand Down

0 comments on commit 0e71086

Please sign in to comment.