Skip to content

Commit 93fa4ab

Browse files
authored
Merge branch 'ci/dependabot-updates' into dependabot/pip/ci/dependabot-updates/pytest-cov-approx-eq-5.0
2 parents 5ee0e9a + 78d3677 commit 93fa4ab

9 files changed

Lines changed: 207 additions & 23 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v4.6.0
44
hooks:
55
- id: check-symlinks
66
- id: check-xml
@@ -17,7 +17,7 @@ repos:
1717
args: [--markdown-linebreak-ext=md]
1818

1919
- repo: https://github.com/ambv/black
20-
rev: 24.2.0
20+
rev: 24.3.0
2121
hooks:
2222
- id: black
2323
name: Blacken

emmopy/emmocheck.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,30 @@ def test_number_of_labels(self):
7373
"""
7474
exceptions = set(
7575
(
76-
"terms.license",
76+
"0.1.homepage", # foaf:homepage
77+
"0.1.logo",
78+
"0.1.page",
79+
"0.1.name",
80+
"bibo:doi",
81+
"core.altLabel",
82+
"core.hiddenLabel",
83+
"core.prefLabel",
7784
"terms.abstract",
85+
"terms.alternative",
86+
"terms:bibliographicCitation",
7887
"terms.contributor",
88+
"terms.created",
7989
"terms.creator",
90+
"terms.hasFormat",
91+
"terms.identifier",
92+
"terms.issued",
93+
"terms.license",
94+
"terms.modified",
8095
"terms.publisher",
96+
"terms.source",
8197
"terms.title",
82-
"core.prefLabel",
83-
"core.altLabel",
84-
"core.hiddenLabel",
85-
"foaf.logo",
86-
"0.1.logo", # foaf.logo
98+
"vann:preferredNamespacePrefix",
99+
"vann:preferredNamespaceUri",
87100
)
88101
)
89102
exceptions.update(

ontopy/ontology.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,15 +1004,19 @@ def save(
10041004
# Make a copy of the owlready2 graph object to not mess with
10051005
# owlready2 internals
10061006
graph = rdflib.Graph()
1007-
graph_owlready2 = self.world.as_rdflib_graph()
1008-
for triple in graph_owlready2.triples((None, None, None)):
1007+
for triple in self.world.as_rdflib_graph():
10091008
graph.add(triple)
10101009

1011-
# Add namespaces
1012-
graph.namespace_manager.bind("", rdflib.Namespace(self.base_iri))
1013-
graph.namespace_manager.bind(
1014-
"swrl", rdflib.Namespace("http://www.w3.org/2003/11/swrl#")
1015-
)
1010+
# Add common namespaces unknown to rdflib
1011+
extra_namespaces = [
1012+
("", self.base_iri),
1013+
("swrl", "http://www.w3.org/2003/11/swrl#"),
1014+
("bibo", "http://purl.org/ontology/bibo/"),
1015+
]
1016+
for prefix, iri in extra_namespaces:
1017+
graph.namespace_manager.bind(
1018+
prefix, rdflib.Namespace(iri), override=False
1019+
)
10161020

10171021
# Remove all ontology-declarations in the graph that are
10181022
# not the current ontology.

ontopy/utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,3 +835,38 @@ def recur(o):
835835
)
836836

837837
return layout
838+
839+
840+
def copy_annotation(onto, src, dst):
841+
"""In all classes and properties in `onto`, copy annotation `src` to `dst`.
842+
843+
Arguments:
844+
onto: Ontology to work on.
845+
src: Name of source annotation.
846+
dst: Name or IRI of destination annotation. Use IRI if the
847+
destination annotation is not already in the ontology.
848+
"""
849+
if onto.world[src]:
850+
src = onto.world[src]
851+
else:
852+
src = onto[src]
853+
854+
if onto.world[dst]:
855+
dst = onto.world[dst]
856+
elif dst in onto:
857+
dst = onto[dst]
858+
else:
859+
if "://" not in dst:
860+
raise ValueError(
861+
"new destination annotation property must be provided as "
862+
"a full IRI"
863+
)
864+
name = min(dst.rsplit("#")[-1], dst.rsplit("/")[-1], key=len)
865+
iri = dst
866+
dst = onto.new_annotation_property(name, owlready2.AnnotationProperty)
867+
dst.iri = iri
868+
869+
for e in onto.get_entities():
870+
new = getattr(e, src.name).first()
871+
if new and new not in getattr(e, dst.name):
872+
getattr(e, dst.name).append(new)

tests/test_get_by_label.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ def test_get_by_label_emmo(emmo: "Ontology") -> None:
109109
assert emmo[emmo.Atom.iri] == emmo.Atom
110110

111111
# Load an ontology with imported sub-ontologies
112+
# Note that this test also includes testing of loading
113+
# ontology with catalog file directly from the web
114+
# It is therefore not duplicated in test_load.
112115
onto = get_ontology(
113-
"https://raw.githubusercontent.com/BIG-MAP/BattINFO/master/battinfo.ttl"
116+
"https://raw.githubusercontent.com/emmo-repo/domain-battery/master/battery.ttl"
114117
).load()
115118
assert onto.Electrolyte.prefLabel.en.first() == "Electrolyte"
116119

tests/test_load.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ def test_load(repo_dir: "Path", testonto: "Ontology") -> None:
3535
assert str(testonto.TestClass.prefLabel.first()) == "TestClass"
3636

3737
# Use catalog file when downloading from web
38-
onto = get_ontology(
39-
"https://raw.githubusercontent.com/BIG-MAP/BattINFO/master/"
40-
"battinfo.ttl"
41-
).load()
42-
assert str(onto.Electrolyte.prefLabel.first()) == "Electrolyte"
38+
# This is tested in test_get_by_label in which some additional tests
39+
# are performed on labels.
4340

4441
with pytest.raises(
4542
EMMOntoPyException,

tests/testonto/domainonto.ttl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@prefix : <https://w3id.org/emmo/domain-onto#> .
2+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
3+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
4+
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
5+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
6+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
7+
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
8+
@prefix dcterms: <http://purl.org/dc/terms/> .
9+
@prefix emmo: <https://www.w3.org/emmo#> .
10+
11+
12+
<https://w3id/org/emmo/domain-onto> rdf:type owl:Ontology ;
13+
owl:versionIRI <https://w3id/org/emmo/domain-onto/0.1.0> ;
14+
owl:versionInfo "0.1.0" ;
15+
dcterms:abstract "Test for an EMMO-based domain ontolgoy."@en .
16+
17+
18+
:testclass rdf:type owl:Class ;
19+
rdfs:subClassOf owl:Thing ;
20+
skos:prefLabel "TestClass"@en ;
21+
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "A test class."@en .
22+
23+
:testobjectproperty rdf:type owl:ObjectProperty ;
24+
rdfs:domain :testclass ;
25+
rdfs:range :testclass ;
26+
skos:prefLabel "hasObjectProperty"@en .
27+
28+
:testannotationproperty rdf:type owl:AnnotationProperty ;
29+
rdfs:domain :testclass ;
30+
rdfs:range rdfs:Literal ;
31+
skos:prefLabel "hasAnnotationProperty"@en .
32+
33+
:testdatatypeproperty rdf:type owl:DatatypeProperty ;
34+
rdfs:domain :testclass ;
35+
rdfs:range xsd:string ;
36+
skos:prefLabel "hasDataProperty"@en .
37+
38+
39+
# Declare skos:prefLabel, emmo:elucidation and emmo:definition here
40+
# since we are not importing these ontologies
41+
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 a owl:AnnotationProperty ;
42+
rdfs:subPropertyOf rdfs:comment ;
43+
skos:prefLabel "elucidation"@en ;
44+
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 .
45+
46+
:EMMO_70fe84ff_99b6_4206_a9fc_9a8931836d84 a owl:AnnotationProperty ;
47+
rdfs:subPropertyOf rdfs:comment ;
48+
skos:prefLabel "definition"@en ;
49+
rdfs:comment "Precise and univocal description of an ontological entity in the framework of an axiomatic system."@en .
50+
51+
skos:prefLabel a owl:AnnotationProperty .

tests/tools/test_ontoconvert.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,39 @@ def test_run() -> None:
3939
assert re.search("@prefix : <https://w3id.org/ex/testonto#>", output2)
4040
assert re.search("<https://w3id.org/ex/testonto> .* owl:Ontology", output2)
4141
assert re.search("testclass .* owl:Class", output2)
42+
43+
# Test 3 - copy-emmo-annotations
44+
infile3 = ontodir / "domainonto.ttl"
45+
outfile3 = outdir / "test_ontoconvert3.ttl"
46+
ontoconvert.main(
47+
[
48+
"--copy-emmo-annotations",
49+
"--iri=https://w3id.org/ex/testonto",
50+
"--base-iri=https://w3id.org/ex/testonto#",
51+
str(infile3),
52+
str(outfile3),
53+
]
54+
)
55+
input3 = infile3.read_text()
56+
output3 = outfile3.read_text()
57+
assert 'rdfs:label "hasAnnotationProperty"@en' not in input3
58+
assert 'rdfs:label "hasAnnotationProperty"@en' in output3
59+
assert 'rdfs:comment "A test class."@en' not in input3
60+
assert 'rdfs:comment "A test class."@en' in output3
61+
62+
# Test 4 - copy-annotation with source as annotation label
63+
infile4 = ontodir / "testonto.ttl"
64+
outfile4 = outdir / "test_ontoconvert3.ttl"
65+
ontoconvert.main(
66+
[
67+
"-c prefLabel-->http://www.w3.org/2004/02/skos/core#hiddenLabel",
68+
"--iri=https://w3id.org/ex/testonto",
69+
"--base-iri=https://w3id.org/ex/testonto#",
70+
str(infile4),
71+
str(outfile4),
72+
]
73+
)
74+
input4 = infile4.read_text()
75+
output4 = outfile4.read_text()
76+
assert not re.search('skos:hiddenLabel "hasAnnotationProperty"@en', input4)
77+
assert re.search('skos:hiddenLabel "hasAnnotationProperty"@en', output4)

tools/ontoconvert

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import warnings
77
from rdflib.util import guess_format
88

99
from ontopy import get_ontology
10-
from ontopy.utils import annotate_source, rename_iris
10+
from ontopy.utils import annotate_source, rename_iris, copy_annotation
1111

1212

1313
def main(argv: list = None):
@@ -59,6 +59,36 @@ def main(argv: list = None):
5959
"The default is to append to it."
6060
),
6161
)
62+
parser.add_argument(
63+
"--copy-annotation",
64+
"-c",
65+
action="append",
66+
default=[],
67+
metavar="FROM-->TO",
68+
help=(
69+
"Copy annotation FROM to annotation TO in each class and "
70+
"property in the ontology. FROM and TO may be given as "
71+
"full IRIs or (if they already exists as annotations in the "
72+
"ontology) as entity names. "
73+
"This option be given multiple times."
74+
),
75+
)
76+
parser.add_argument(
77+
"--copy-emmo-annotations",
78+
"-e",
79+
action="store_true",
80+
help=(
81+
"Make a copy of EMMO annotations to plain RDFS for increased "
82+
"interoperability. "
83+
"Alias for: `--copy-annotation="
84+
"http://www.w3.org/2004/02/skos/core#prefLabel"
85+
"-->http://www.w3.org/2000/01/rdf-schema#label "
86+
"--copy-annotation=elucidation"
87+
"-->http://www.w3.org/2000/01/rdf-schema#comment`"
88+
"--copy-annotation=definition"
89+
"-->http://www.w3.org/2000/01/rdf-schema#comment`"
90+
),
91+
)
6292
parser.add_argument(
6393
"--no-catalog",
6494
"-n",
@@ -72,7 +102,7 @@ def main(argv: list = None):
72102
"--infer",
73103
"-i",
74104
nargs="?",
75-
const="FaCT++",
105+
const="HermiT",
76106
choices=["HermiT", "Pellet", "FaCT++"],
77107
metavar="NAME",
78108
help=(
@@ -188,6 +218,17 @@ def main(argv: list = None):
188218
if not output_format:
189219
output_format = "xml"
190220

221+
# Annotations to copy with --copy-emmo-annotations
222+
if args.copy_emmo_annotations:
223+
args.copy_annotation.extend(
224+
[
225+
"http://www.w3.org/2004/02/skos/core#prefLabel"
226+
"-->http://www.w3.org/2000/01/rdf-schema#label",
227+
"elucidation-->http://www.w3.org/2000/01/rdf-schema#comment",
228+
"definition-->http://www.w3.org/2000/01/rdf-schema#comment",
229+
]
230+
)
231+
191232
# Perform conversion
192233
with warnings.catch_warnings(record=True) as warnings_handle:
193234
warnings.simplefilter("always")
@@ -218,6 +259,10 @@ def main(argv: list = None):
218259
debug=verbose,
219260
)
220261

262+
for cpy in args.copy_annotation:
263+
src, dst = cpy.split("-->", 1)
264+
copy_annotation(onto, src.strip(), dst.strip())
265+
221266
onto.save(
222267
args.output,
223268
format=output_format,

0 commit comments

Comments
 (0)