Skip to content

Commit 6d59041

Browse files
committed
Added obsoletion menu.
1 parent 9e2216b commit 6d59041

File tree

5 files changed

+107
-5
lines changed

5 files changed

+107
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# OBO annotations editor #
22

3-
A plug-in for Protege that provides entry fields for standard OBO annotation properties.
3+
A plug-in for Protege that provides entry fields for standard OBO annotation properties, as well as menu actions such as term obsoletion.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.geneontology</groupId>
66
<artifactId>obo-annotations-plugin</artifactId>
7-
<version>0.3.0</version>
7+
<version>0.4.0</version>
88
<packaging>bundle</packaging>
99

1010
<name>OBO Annotations Editor</name>
@@ -33,7 +33,7 @@
3333
<developer>
3434
<id>balhoff</id>
3535
<name>Jim Balhoff</name>
36-
<email>jim@balhoff.org</email>
36+
<email>balhoff@renci.org</email>
3737
</developer>
3838
</developers>
3939

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.protege.oboeditor.menu;
2+
3+
import java.util.Set;
4+
5+
import org.protege.editor.owl.ui.action.SelectedOWLEntityAction;
6+
import org.semanticweb.owlapi.model.OWLAnnotation;
7+
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
8+
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
9+
import org.semanticweb.owlapi.model.OWLClass;
10+
import org.semanticweb.owlapi.model.OWLClassExpression;
11+
import org.semanticweb.owlapi.model.OWLDataFactory;
12+
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
13+
import org.semanticweb.owlapi.model.OWLEntity;
14+
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
15+
import org.semanticweb.owlapi.model.OWLHasKeyAxiom;
16+
import org.semanticweb.owlapi.model.OWLLiteral;
17+
import org.semanticweb.owlapi.model.OWLOntology;
18+
import org.semanticweb.owlapi.model.OWLOntologyManager;
19+
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
20+
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
21+
22+
public class ObsoleteEntityMenuAction extends SelectedOWLEntityAction {
23+
24+
private static final long serialVersionUID = -1431847694761565949L;
25+
26+
@Override
27+
protected void actionPerformed(OWLEntity entity) {
28+
final OWLOntologyManager manager = this.getOWLModelManager().getOWLOntologyManager();
29+
final OWLDataFactory factory = this.getOWLDataFactory();
30+
final OWLOntology ontology = this.getOWLModelManager().getActiveOntology();
31+
this.relabel(entity);
32+
manager.addAxiom(ontology, factory.getDeprecatedOWLAnnotationAssertionAxiom(entity.getIRI()));
33+
if (entity.isOWLClass()) {
34+
final OWLClass ontClass = entity.asOWLClass();
35+
for (OWLEquivalentClassesAxiom axiom : ontology.getEquivalentClassesAxioms(ontClass)) {
36+
manager.removeAxiom(ontology, axiom);
37+
final Set<OWLClassExpression> otherClasses = axiom.getClassExpressionsMinus(ontClass);
38+
final Set<OWLAnnotation> annotations = axiom.getAnnotations();
39+
if (otherClasses.size() > 1) {
40+
final OWLEquivalentClassesAxiom newAxiom = factory.getOWLEquivalentClassesAxiom(otherClasses, annotations);
41+
manager.addAxiom(ontology, newAxiom);
42+
}
43+
}
44+
for (OWLSubClassOfAxiom axiom : ontology.getSubClassAxiomsForSubClass(ontClass)) {
45+
manager.removeAxiom(ontology, axiom);
46+
}
47+
for (OWLSubClassOfAxiom axiom : ontology.getSubClassAxiomsForSuperClass(ontClass)) {
48+
manager.removeAxiom(ontology, axiom);
49+
}
50+
for (OWLHasKeyAxiom axiom : ontology.getHasKeyAxioms(ontClass)) {
51+
manager.removeAxiom(ontology, axiom);
52+
}
53+
for (OWLDisjointClassesAxiom axiom : ontology.getDisjointClassesAxioms(ontClass)) {
54+
manager.removeAxiom(ontology, axiom);
55+
final Set<OWLClassExpression> otherClasses = axiom.getClassExpressionsMinus(ontClass);
56+
final Set<OWLAnnotation> annotations = axiom.getAnnotations();
57+
if (otherClasses.size() > 1) {
58+
final OWLDisjointClassesAxiom newAxiom = factory.getOWLDisjointClassesAxiom(otherClasses, annotations);
59+
manager.addAxiom(ontology, newAxiom);
60+
}
61+
}
62+
}
63+
if (entity.isOWLNamedIndividual()) {
64+
//TODO
65+
}
66+
if (entity.isOWLObjectProperty()) {
67+
//TODO
68+
}
69+
}
70+
71+
@Override
72+
protected void disposeAction() throws Exception {}
73+
74+
private void relabel(OWLEntity entity) {
75+
final OWLOntologyManager manager = this.getOWLModelManager().getOWLOntologyManager();
76+
final OWLDataFactory factory = this.getOWLDataFactory();
77+
final OWLAnnotationProperty rdfsLabel = factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
78+
final OWLOntology ontology = this.getOWLModelManager().getActiveOntology();
79+
for (OWLAnnotationAssertionAxiom annotation : ontology.getAnnotationAssertionAxioms(entity.getIRI())) {
80+
if (annotation.getProperty().equals(rdfsLabel)) {
81+
if (annotation.getValue() instanceof OWLLiteral) {
82+
final Set<OWLAnnotation> annotationAnnotations = annotation.getAnnotations();
83+
final OWLLiteral literal = (OWLLiteral)(annotation.getValue());
84+
final String newLabel = "obsolete " + literal.getLiteral();
85+
final OWLLiteral newLiteral = factory.getOWLLiteral(newLabel);
86+
final OWLAnnotationAssertionAxiom newAxiom = factory.getOWLAnnotationAssertionAxiom(rdfsLabel, entity.getIRI(), newLiteral, annotationAnnotations);
87+
manager.removeAxiom(ontology, annotation);
88+
manager.addAxiom(ontology, newAxiom);
89+
}
90+
}
91+
}
92+
}
93+
94+
}

src/main/resources/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@
88
<headerColor value="B1CAF6"/>
99
<category value="OBO"/>
1010
</extension>
11+
12+
<extension id="menu.ObsoleteEntity" name="Make entity obsolete" point="org.protege.editor.core.application.EditorKitMenuAction">
13+
<class value="org.protege.oboeditor.menu.ObsoleteEntityMenuAction"/>
14+
<name value="Make entity obsolete"/>
15+
<toolTip value="Deprecates the selected entity and removes its defining axioms."/>
16+
<path value="org.protege.editor.core.application.menu.EditMenu/SlotOBO-Z"/>
17+
<editorKitId value="OWLEditorKit"/>
18+
</extension>
1119

1220
</plugin>

update.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
id=org.protege.oboeditor
2-
version=0.3.0
3-
download=https://github.com/owlcollab/protege-obo-plugin/releases/download/v0.3.0/obo-annotations-plugin-0.3.0.jar
2+
version=0.4.0
3+
download=https://github.com/owlcollab/protege-obo-plugin/releases/download/v0.4.0/obo-annotations-plugin-0.4.0.jar
44
name=OBO Annotations Editor
55
readme=https://raw.githubusercontent.com/owlcollab/protege-obo-plugin/master/README.md
66
license=https://opensource.org/licenses/BSD-3-Clause

0 commit comments

Comments
 (0)