1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package ubic.basecode.ontology.jena;
20
21 import com.hp.hpl.jena.rdf.model.*;
22 import com.hp.hpl.jena.vocabulary.RDFS;
23 import ubic.basecode.ontology.model.AnnotationProperty;
24
25 import javax.annotation.Nullable;
26 import java.util.Objects;
27
28
29
30
31
32
33 class AnnotationPropertyImpl extends AbstractOntologyResource implements AnnotationProperty {
34
35 private final com.hp.hpl.jena.ontology.AnnotationProperty property;
36 @Nullable
37 private final RDFNode object;
38
39
40
41
42
43 public AnnotationPropertyImpl( com.hp.hpl.jena.ontology.AnnotationProperty prop, @Nullable RDFNode object ) {
44 super( prop );
45 this.property = prop;
46 this.object = object;
47 }
48
49 @Override
50 public String getProperty() {
51 if ( property.getLabel( null ) != null ) {
52 return property.getLabel( null );
53 } else if ( property.getLocalName() != null ) {
54 return property.getLocalName();
55 } else {
56 return property.toString();
57 }
58 }
59
60 @Override
61 public String getContents() {
62 if ( this.object == null ) {
63 return null;
64 } else if ( object.isResource() ) {
65
66 Resource r = ( Resource ) object;
67 Statement s = r.getProperty( RDFS.label );
68 if ( s != null ) {
69 return s.getObject().toString();
70 } else {
71 return null;
72 }
73 } else {
74 return ( String ) object.visitWith( new RDFVisitor() {
75
76 @Override
77 public Object visitBlank( Resource r, AnonId id ) {
78 return r.getLocalName();
79 }
80
81 @Override
82 public Object visitLiteral( Literal l ) {
83 return l.toString().replaceAll( "\\^\\^.+", "" );
84 }
85
86 @Override
87 public Object visitURI( Resource r, String uri ) {
88 return r.getLocalName();
89 }
90 } );
91 }
92 }
93
94 @Override
95 public boolean isObsolete() {
96 return super.isObsolete() || property.hasSuperProperty( OBO.ObsoleteProperty, false );
97 }
98
99 @Override
100 public boolean equals( @Nullable Object obj ) {
101 if ( this == obj ) return true;
102 if ( obj == null ) return false;
103 if ( obj instanceof AnnotationPropertyImpl ) {
104 final AnnotationPropertyImpl/basecode/ontology/jena/AnnotationPropertyImpl.html#AnnotationPropertyImpl">AnnotationPropertyImpl other = ( AnnotationPropertyImpl ) obj;
105 return super.equals( other )
106 && Objects.equals( object, other.object );
107 } else if ( obj instanceof AnnotationProperty ) {
108 final AnnotationPropertyubic/basecode/ontology/model/AnnotationProperty.html#AnnotationProperty">AnnotationProperty other = ( AnnotationProperty ) obj;
109 return super.equals( other )
110 && Objects.equals( getContents(), other.getContents() );
111 }
112 return false;
113 }
114
115 @Override
116 public int hashCode() {
117 return Objects.hash( super.hashCode(), object );
118 }
119
120 @Override
121 public String toString() {
122 return property.getLocalName() + " " + object;
123 }
124
125 }