Skip to content

Commit c9d4d7c

Browse files
committed
Relocate and move Gemma's simple ontology implementation under ubic.basecode.ontology.simple
1 parent de95a12 commit c9d4d7c

6 files changed

Lines changed: 152 additions & 52 deletions

File tree

src/ubic/basecode/ontology/model/OntologyTerm.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ default Collection<OntologyTerm> getParents( boolean direct, boolean includeAddi
9595
/**
9696
* @deprecated use {@link #getLabel()} instead.
9797
*/
98+
@Nullable
9899
@Deprecated
99100
String getTerm();
100101

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package ubic.basecode.ontology.simple;
2+
3+
import ubic.basecode.ontology.model.OntologyResource;
4+
5+
import javax.annotation.Nullable;
6+
import java.io.Serializable;
7+
import java.util.Objects;
8+
9+
/**
10+
* @author poirigui
11+
*/
12+
public abstract class AbstractOntologyResourceSimple implements OntologyResource, Serializable {
13+
14+
@Nullable
15+
private final String uri, label;
16+
17+
protected AbstractOntologyResourceSimple( @Nullable String uri, @Nullable String label ) {
18+
this.uri = uri;
19+
this.label = label;
20+
}
21+
22+
@Override
23+
public String getLocalName() {
24+
return uri;
25+
}
26+
27+
@Nullable
28+
@Override
29+
public String getLabel() {
30+
return label;
31+
}
32+
33+
@Nullable
34+
@Override
35+
public String getComment() {
36+
return null;
37+
}
38+
39+
@Override
40+
@Nullable
41+
public String getUri() {
42+
return uri;
43+
}
44+
45+
@Override
46+
public boolean isObsolete() {
47+
return false;
48+
}
49+
50+
@Override
51+
public boolean equals( Object obj ) {
52+
if ( this == obj ) return true;
53+
if ( obj == null ) return false;
54+
if ( getClass() != obj.getClass() ) return false;
55+
final OntologyResource other = ( OntologyResource ) obj;
56+
if ( getLabel() == null ) {
57+
if ( other.getLabel() != null ) return false;
58+
} else if ( !getLabel().equals( other.getLabel() ) ) return false;
59+
if ( getUri() == null ) {
60+
if ( other.getUri() != null ) return false;
61+
} else if ( !getUri().equals( other.getUri() ) ) return false;
62+
return true;
63+
}
64+
65+
@Override
66+
public int hashCode() {
67+
return Objects.hash( label, uri );
68+
}
69+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ubic.basecode.ontology.simple;
2+
3+
import ubic.basecode.ontology.model.OntologyIndividual;
4+
5+
import javax.annotation.Nullable;
6+
7+
/**
8+
* @author poirigui
9+
*/
10+
public class OntologyIndividualSimple extends AbstractOntologyResourceSimple implements OntologyIndividual {
11+
12+
private final OntologyTermSimple instanceOf;
13+
14+
/**
15+
* Create a new simple ontology individual.
16+
* @param uri a URI for the term, of null for a free-text term
17+
* @param label a label for the term
18+
* @param instanceOf the term this individual is an instance of which must be simple since this class has to be
19+
* {@link java.io.Serializable}.
20+
*/
21+
public OntologyIndividualSimple( @Nullable String uri, @Nullable String label, OntologyTermSimple instanceOf ) {
22+
super( uri, label );
23+
this.instanceOf = instanceOf;
24+
}
25+
26+
@Override
27+
public OntologyTermSimple getInstanceOf() {
28+
return instanceOf;
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ubic.basecode.ontology.simple;
2+
3+
import ubic.basecode.ontology.model.OntologyProperty;
4+
5+
import javax.annotation.Nullable;
6+
7+
/**
8+
* Simple in-memory implementation of {@link OntologyProperty}.
9+
* @author poirigui
10+
*/
11+
public class OntologyPropertySimple extends AbstractOntologyResourceSimple implements OntologyProperty {
12+
13+
/**
14+
*
15+
* @param uri an URI or null if this is a free-text property
16+
* @param label a label for the property
17+
*/
18+
public OntologyPropertySimple( @Nullable String uri, @Nullable String label ) {
19+
super( uri, label );
20+
}
21+
22+
@Override
23+
public boolean isFunctional() {
24+
return false;
25+
}
26+
}

src/ubic/basecode/ontology/model/OntologyTermSimple.java renamed to src/ubic/basecode/ontology/simple/OntologyTermSimple.java

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,41 @@
1212
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1313
* specific language governing permissions and limitations under the License.
1414
*/
15-
package ubic.basecode.ontology.model;
15+
package ubic.basecode.ontology.simple;
16+
17+
import ubic.basecode.ontology.model.AnnotationProperty;
18+
import ubic.basecode.ontology.model.OntologyIndividual;
19+
import ubic.basecode.ontology.model.OntologyRestriction;
20+
import ubic.basecode.ontology.model.OntologyTerm;
1621

1722
import javax.annotation.Nullable;
18-
import java.io.Serializable;
1923
import java.util.Collection;
20-
import java.util.Objects;
2124

2225
/**
2326
* A light-weight version of OntologyTerms. Only supports a subset of the functionality of OntologyTermImpl (namely, it
2427
* is missing the inference components)
2528
*
2629
* @author Paul
2730
*/
28-
@SuppressWarnings("unused")
29-
public class OntologyTermSimple implements OntologyTerm, Serializable {
30-
31-
/**
32-
*
33-
*/
34-
private static final long serialVersionUID = -2589717267279872909L;
31+
public class OntologyTermSimple extends AbstractOntologyResourceSimple implements OntologyTerm {
3532

36-
private final String description;
37-
private final boolean obsolete;
38-
private final String term;
33+
@Nullable
3934
private final String uri;
35+
@Nullable
36+
private final String label;
37+
@Nullable
38+
private final String comment;
39+
private final boolean obsolete;
4040

41-
public OntologyTermSimple( String uri, String term ) {
42-
this( uri, term, "", false );
41+
public OntologyTermSimple( @Nullable String uri, @Nullable String label ) {
42+
this( uri, label, "", false );
4343
}
4444

45-
public OntologyTermSimple( String uri, String term, String description, boolean isObsolete ) {
45+
public OntologyTermSimple( @Nullable String uri, @Nullable String label, @Nullable String comment, boolean isObsolete ) {
46+
super( uri, label );
4647
this.uri = uri;
47-
this.term = term;
48-
this.description = description;
48+
this.label = label;
49+
this.comment = comment;
4950
this.obsolete = isObsolete;
5051
}
5152

@@ -75,26 +76,17 @@ public Collection<OntologyTerm> getChildren( boolean direct, boolean includeAddi
7576
throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
7677
}
7778

79+
@Nullable
7880
@Override
7981
public String getComment() {
80-
return this.description;
82+
return this.comment;
8183
}
8284

8385
@Override
8486
public Collection<OntologyIndividual> getIndividuals( boolean direct ) {
8587
throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
8688
}
8789

88-
@Override
89-
public String getLabel() {
90-
return term;
91-
}
92-
93-
@Override
94-
public String getLocalName() {
95-
return term;
96-
}
97-
9890
@Override
9991
public Collection<OntologyTerm> getParents( boolean direct, boolean includeAdditionalProperties, boolean keepObsoletes ) {
10092
throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
@@ -116,10 +108,12 @@ public boolean isTermObsolete() {
116108
}
117109

118110
@Override
111+
@Nullable
119112
public String getTerm() {
120-
return this.term;
113+
return this.label;
121114
}
122115

116+
@Nullable
123117
@Override
124118
public String getUri() {
125119
return this.uri;
@@ -129,24 +123,4 @@ public String getUri() {
129123
public boolean isObsolete() {
130124
return obsolete;
131125
}
132-
133-
@Override
134-
public boolean equals( Object obj ) {
135-
if ( this == obj ) return true;
136-
if ( obj == null ) return false;
137-
if ( getClass() != obj.getClass() ) return false;
138-
final OntologyResource other = ( OntologyResource ) obj;
139-
if ( getLabel() == null ) {
140-
if ( other.getLabel() != null ) return false;
141-
} else if ( !getLabel().equals( other.getLabel() ) ) return false;
142-
if ( getUri() == null ) {
143-
if ( other.getUri() != null ) return false;
144-
} else if ( !getUri().equals( other.getUri() ) ) return false;
145-
return true;
146-
}
147-
148-
@Override
149-
public int hashCode() {
150-
return Objects.hash( getLabel(), getUri() );
151-
}
152126
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
*
2+
* Simple ontology implementation.
33
*/
44
@ParametersAreNonnullByDefault
5-
package ubic.basecode.ontology;
5+
package ubic.basecode.ontology.simple;
66

77
import javax.annotation.ParametersAreNonnullByDefault;

0 commit comments

Comments
 (0)