From 64085536518a685b860b91ebe5dd06906f1ab4ce Mon Sep 17 00:00:00 2001 From: hkir-dev Date: Fri, 1 Dec 2023 17:05:14 +0000 Subject: [PATCH 1/2] resolves issue #1163 --- docs/examples/example2_defined_by.owl | 26 ------------------- docs/examples/merged_defined_by.owl | 18 ------------- docs/merge.md | 4 +++ .../org/obolibrary/robot/AnnotateCommand.java | 4 ++- .../org/obolibrary/robot/MergeOperation.java | 6 +++-- .../obolibrary/robot/MergeOperationTest.java | 4 +-- .../src/test/resources/simple_defined_by.owl | 18 ------------- 7 files changed, 13 insertions(+), 67 deletions(-) diff --git a/docs/examples/example2_defined_by.owl b/docs/examples/example2_defined_by.owl index d15c175ac..4d66ccc07 100644 --- a/docs/examples/example2_defined_by.owl +++ b/docs/examples/example2_defined_by.owl @@ -107,33 +107,7 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/docs/examples/merged_defined_by.owl b/docs/examples/merged_defined_by.owl index d988d4fa2..64b7d520e 100644 --- a/docs/examples/merged_defined_by.owl +++ b/docs/examples/merged_defined_by.owl @@ -107,25 +107,7 @@ - - - - - - - - - - - - diff --git a/docs/merge.md b/docs/merge.md index b8d1a80c8..d601de544 100644 --- a/docs/merge.md +++ b/docs/merge.md @@ -36,13 +36,17 @@ It’s also possible to annotate the imported or merged ontology axioms with the * `--annotate-derived-from true`: annotates all axioms with the source's version IRI if it exists, else with the ontology IRI, using `prov:wasDerivedFrom`. If the axiom already has an annotation using this property (`prov:wasDerivedFrom`), the existing annotation will be kept and no new annotation will be added. +``` robot merge --catalog catalog.xml \ --input imports-nucleus.owl \ --annotate-derived-from true \ --output results/merged_derived_from.owl +``` * `--annotate-defined-by true`: annotates all entities (class, data, annotation, object property and named individual declaration axioms) with the source's IRI using `rdfs:isDefinedBy`. If the term already has an annotation using this property (`rdfs:isDefinedBy`), the existing annotation will be kept and no new annotation will be added. +``` robot merge --input example2.owl --input merge.owl \ --annotate-defined-by true \ --output results/merged_defined_by.owl +``` diff --git a/robot-command/src/main/java/org/obolibrary/robot/AnnotateCommand.java b/robot-command/src/main/java/org/obolibrary/robot/AnnotateCommand.java index 8a9d3499b..114444cb8 100644 --- a/robot-command/src/main/java/org/obolibrary/robot/AnnotateCommand.java +++ b/robot-command/src/main/java/org/obolibrary/robot/AnnotateCommand.java @@ -318,7 +318,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception OWLAnnotationProperty rdfsIsDefinedBy = ontology.getOWLOntologyManager().getOWLDataFactory().getRDFSIsDefinedBy(); for (OWLEntity owlEntity : ontology.getSignature()) { - OntologyHelper.addEntityAnnotation(ontology, owlEntity, rdfsIsDefinedBy, ontIRI, false); + if (!(owlEntity.isOWLDatatype() && owlEntity.asOWLDatatype().isBuiltIn())) { + OntologyHelper.addEntityAnnotation(ontology, owlEntity, rdfsIsDefinedBy, ontIRI, false); + } } } } diff --git a/robot-core/src/main/java/org/obolibrary/robot/MergeOperation.java b/robot-core/src/main/java/org/obolibrary/robot/MergeOperation.java index 92d1a13a4..08b4737da 100644 --- a/robot-core/src/main/java/org/obolibrary/robot/MergeOperation.java +++ b/robot-core/src/main/java/org/obolibrary/robot/MergeOperation.java @@ -363,8 +363,10 @@ private static void annotateWithOntologyIRI( OWLAnnotationProperty rdfsIsDefinedBy = targetOntology.getOWLOntologyManager().getOWLDataFactory().getRDFSIsDefinedBy(); for (OWLEntity owlEntity : sourceOntology.getSignature(includeImportsClosure)) { - OntologyHelper.addEntityAnnotation( - targetOntology, owlEntity, rdfsIsDefinedBy, ontIRI, false); + if (!(owlEntity.isOWLDatatype() && owlEntity.asOWLDatatype().isBuiltIn())) { + OntologyHelper.addEntityAnnotation( + targetOntology, owlEntity, rdfsIsDefinedBy, ontIRI, false); + } } } } diff --git a/robot-core/src/test/java/org/obolibrary/robot/MergeOperationTest.java b/robot-core/src/test/java/org/obolibrary/robot/MergeOperationTest.java index 6bf104b2f..b43bc885a 100644 --- a/robot-core/src/test/java/org/obolibrary/robot/MergeOperationTest.java +++ b/robot-core/src/test/java/org/obolibrary/robot/MergeOperationTest.java @@ -101,9 +101,9 @@ public void testMergeDefinedBy() throws IOException { assertEquals(5, simple.getAxiomCount()); OWLOntology merged = MergeOperation.merge(ontologies, false, false, true, false); - assertEquals(9, merged.getAxiomCount()); + assertEquals(8, merged.getAxiomCount()); OWLOntology expected = loadOntology("/simple_defined_by.owl"); - assertEquals(9, expected.getAxiomCount()); + assertEquals(8, expected.getAxiomCount()); assertIdentical(expected, merged); } } diff --git a/robot-core/src/test/resources/simple_defined_by.owl b/robot-core/src/test/resources/simple_defined_by.owl index 890c1075d..89ecdae4d 100644 --- a/robot-core/src/test/resources/simple_defined_by.owl +++ b/robot-core/src/test/resources/simple_defined_by.owl @@ -27,24 +27,6 @@ - - - - - - - - - - - - From f412fb76a3a7c7d51303c0ad8a4b55a56a133bc5 Mon Sep 17 00:00:00 2001 From: hkir-dev Date: Mon, 4 Dec 2023 13:49:28 +0000 Subject: [PATCH 2/2] exclude entities based on namespace --- CHANGELOG.md | 2 ++ docs/examples/example2_defined_by.owl | 36 ------------------- docs/examples/merged_defined_by.owl | 24 ------------- docs/merge.md | 6 ++-- .../org/obolibrary/robot/AnnotateCommand.java | 2 +- .../org/obolibrary/robot/MergeOperation.java | 2 +- .../obolibrary/robot/MergeOperationTest.java | 4 +-- .../src/test/resources/simple_defined_by.owl | 19 ---------- 8 files changed, 8 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37cfc19ea..60fc646d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - '--annotate-with-source true' does not work with extract --method subset [#1160] - Fix how Template adds entities to the QuotedEntityChecker [#1104] +- [`merge`] and 'annotate' operations '--annotate-defined-by' excludes reserved OWL 2 vocabularies [#1171] ## [1.9.5] - 2023-09-20 @@ -380,6 +381,7 @@ First official release of ROBOT! [`template`]: http://robot.obolibrary.org/template [`validate`]: http://robot.obolibrary.org/validate +[#1171]: https://github.com/ontodev/robot/pull/1171 [#1160]: https://github.com/ontodev/robot/pull/1160 [#1148]: https://github.com/ontodev/robot/pull/1148 [#1135]: https://github.com/ontodev/robot/pull/1135 diff --git a/docs/examples/example2_defined_by.owl b/docs/examples/example2_defined_by.owl index 4d66ccc07..82bb72339 100644 --- a/docs/examples/example2_defined_by.owl +++ b/docs/examples/example2_defined_by.owl @@ -78,30 +78,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -258,18 +234,6 @@ dummy individal 5 - - - - - - diff --git a/docs/examples/merged_defined_by.owl b/docs/examples/merged_defined_by.owl index 64b7d520e..e71912c17 100644 --- a/docs/examples/merged_defined_by.owl +++ b/docs/examples/merged_defined_by.owl @@ -78,30 +78,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/merge.md b/docs/merge.md index d601de544..d74f96ea8 100644 --- a/docs/merge.md +++ b/docs/merge.md @@ -36,17 +36,15 @@ It’s also possible to annotate the imported or merged ontology axioms with the * `--annotate-derived-from true`: annotates all axioms with the source's version IRI if it exists, else with the ontology IRI, using `prov:wasDerivedFrom`. If the axiom already has an annotation using this property (`prov:wasDerivedFrom`), the existing annotation will be kept and no new annotation will be added. -``` robot merge --catalog catalog.xml \ --input imports-nucleus.owl \ --annotate-derived-from true \ --output results/merged_derived_from.owl -``` * `--annotate-defined-by true`: annotates all entities (class, data, annotation, object property and named individual declaration axioms) with the source's IRI using `rdfs:isDefinedBy`. If the term already has an annotation using this property (`rdfs:isDefinedBy`), the existing annotation will be kept and no new annotation will be added. -``` robot merge --input example2.owl --input merge.owl \ --annotate-defined-by true \ --output results/merged_defined_by.owl -``` + +`--annotate-defined-by` excludes entities from the reserved OWL 2 vocabularies (RDF, RDFS, XSD and OWL). diff --git a/robot-command/src/main/java/org/obolibrary/robot/AnnotateCommand.java b/robot-command/src/main/java/org/obolibrary/robot/AnnotateCommand.java index 114444cb8..e35fc36b0 100644 --- a/robot-command/src/main/java/org/obolibrary/robot/AnnotateCommand.java +++ b/robot-command/src/main/java/org/obolibrary/robot/AnnotateCommand.java @@ -318,7 +318,7 @@ public CommandState execute(CommandState state, String[] args) throws Exception OWLAnnotationProperty rdfsIsDefinedBy = ontology.getOWLOntologyManager().getOWLDataFactory().getRDFSIsDefinedBy(); for (OWLEntity owlEntity : ontology.getSignature()) { - if (!(owlEntity.isOWLDatatype() && owlEntity.asOWLDatatype().isBuiltIn())) { + if (!owlEntity.getIRI().isReservedVocabulary()) { OntologyHelper.addEntityAnnotation(ontology, owlEntity, rdfsIsDefinedBy, ontIRI, false); } } diff --git a/robot-core/src/main/java/org/obolibrary/robot/MergeOperation.java b/robot-core/src/main/java/org/obolibrary/robot/MergeOperation.java index 08b4737da..6e5efa25d 100644 --- a/robot-core/src/main/java/org/obolibrary/robot/MergeOperation.java +++ b/robot-core/src/main/java/org/obolibrary/robot/MergeOperation.java @@ -363,7 +363,7 @@ private static void annotateWithOntologyIRI( OWLAnnotationProperty rdfsIsDefinedBy = targetOntology.getOWLOntologyManager().getOWLDataFactory().getRDFSIsDefinedBy(); for (OWLEntity owlEntity : sourceOntology.getSignature(includeImportsClosure)) { - if (!(owlEntity.isOWLDatatype() && owlEntity.asOWLDatatype().isBuiltIn())) { + if (!owlEntity.getIRI().isReservedVocabulary()) { OntologyHelper.addEntityAnnotation( targetOntology, owlEntity, rdfsIsDefinedBy, ontIRI, false); } diff --git a/robot-core/src/test/java/org/obolibrary/robot/MergeOperationTest.java b/robot-core/src/test/java/org/obolibrary/robot/MergeOperationTest.java index b43bc885a..386a4319c 100644 --- a/robot-core/src/test/java/org/obolibrary/robot/MergeOperationTest.java +++ b/robot-core/src/test/java/org/obolibrary/robot/MergeOperationTest.java @@ -101,9 +101,9 @@ public void testMergeDefinedBy() throws IOException { assertEquals(5, simple.getAxiomCount()); OWLOntology merged = MergeOperation.merge(ontologies, false, false, true, false); - assertEquals(8, merged.getAxiomCount()); + assertEquals(7, merged.getAxiomCount()); OWLOntology expected = loadOntology("/simple_defined_by.owl"); - assertEquals(8, expected.getAxiomCount()); + assertEquals(7, expected.getAxiomCount()); assertIdentical(expected, merged); } } diff --git a/robot-core/src/test/resources/simple_defined_by.owl b/robot-core/src/test/resources/simple_defined_by.owl index 89ecdae4d..06c23107a 100644 --- a/robot-core/src/test/resources/simple_defined_by.owl +++ b/robot-core/src/test/resources/simple_defined_by.owl @@ -8,25 +8,6 @@ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> - - - - - - - - - - - - -