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 org.jspecify.annotations.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 @Nullable
61 @Override
62 public String getContents() {
63 if ( this.object == null ) {
64 return null;
65 } else if ( object.isResource() ) {
66
67 Resource r = ( Resource ) object;
68 Statement s = r.getProperty( RDFS.label );
69 if ( s != null ) {
70 return s.getObject().toString();
71 } else {
72 return null;
73 }
74 } else {
75 return ( String ) object.visitWith( new RDFVisitor() {
76
77 @Override
78 public Object visitBlank( Resource r, AnonId id ) {
79 return r.getLocalName();
80 }
81
82 @Override
83 public Object visitLiteral( Literal l ) {
84 return l.toString().replaceAll( "\\^\\^.+", "" );
85 }
86
87 @Override
88 public Object visitURI( Resource r, String uri ) {
89 return r.getLocalName();
90 }
91 } );
92 }
93 }
94
95 @Override
96 public boolean isObsolete() {
97 return super.isObsolete() || property.hasSuperProperty( OBO.ObsoleteProperty, false );
98 }
99
100 @Override
101 public boolean equals( @Nullable Object obj ) {
102 if ( this == obj ) return true;
103 if ( !( obj instanceof AnnotationProperty ) ) {
104 return false;
105 }
106 final AnnotationProperty other = ( AnnotationProperty ) obj;
107 if ( other instanceof AnnotationPropertyImpl ) {
108 return super.equals( other )
109 && Objects.equals( property, ( ( AnnotationPropertyImpl ) other ).property )
110 && Objects.equals( object, ( ( AnnotationPropertyImpl ) other ).object );
111 } else {
112 return super.equals( other )
113 && Objects.equals( getProperty(), other.getProperty() )
114 && Objects.equals( getContents(), other.getContents() );
115 }
116 }
117
118 @Override
119 public int hashCode() {
120 return Objects.hash( super.hashCode(), property, object );
121 }
122
123 @Override
124 public String toString() {
125 return property.getLocalName() + " " + object;
126 }
127 }