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+ }
0 commit comments