11/*
22 * The basecode project
3- *
3+ *
44 * Copyright (c) 2007-2019 University of British Columbia
5- *
5+ *
66 * Licensed under the Apache License, Version 2.0 (the "License");
77 * you may not use this file except in compliance with the License.
88 * You may obtain a copy of the License at
1616 * limitations under the License.
1717 *
1818 */
19- package ubic .basecode .ontology .model ;
19+ package ubic .basecode .ontology .jena ;
2020
21+ import com .hp .hpl .jena .ontology .OntResource ;
22+ import com .hp .hpl .jena .rdf .model .Resource ;
23+ import com .hp .hpl .jena .vocabulary .OWL2 ;
2124import org .slf4j .Logger ;
2225import org .slf4j .LoggerFactory ;
26+ import ubic .basecode .ontology .model .OntologyResource ;
27+
28+ import java .util .Comparator ;
29+ import java .util .Objects ;
2330
2431/**
2532 * @author pavlidis
26- *
2733 */
2834public abstract class AbstractOntologyResource implements OntologyResource {
2935
3036 protected static Logger log = LoggerFactory .getLogger ( AbstractOntologyResource .class );
3137
3238 private static final long serialVersionUID = 1L ;
3339
40+ private transient final OntResource res ;
41+
42+ protected AbstractOntologyResource ( OntResource resource ) {
43+ this .res = resource ;
44+ }
45+
46+ @ Override
47+ public String getUri () {
48+ return res .getURI ();
49+ }
50+
51+ public String getLabel () {
52+ String label = res .getLabel ( "EN" );
53+ if ( label == null ) {
54+ label = res .getLabel ( null );
55+ }
56+ if ( label == null ) {
57+ label = res .getLocalName ();
58+ }
59+ if ( label == null ) {
60+ label = res .getURI ();
61+ }
62+ return label ;
63+ }
64+
65+ @ Override
66+ public boolean isObsolete () {
67+ return res .hasLiteral ( OWL2 .deprecated , true );
68+ }
69+
3470 @ Override
3571 public int compareTo ( OntologyResource other ) {
36- return this . getUri (). compareTo ( other .getUri () );
72+ return Objects . compare ( getUri (), other .getUri (), Comparator . nullsLast ( Comparator . naturalOrder () ) );
3773 }
3874
3975 @ Override
4076 public boolean equals ( Object obj ) {
4177 if ( this == obj ) return true ;
4278 if ( obj == null ) return false ;
4379 if ( getClass () != obj .getClass () ) return false ;
44- final AbstractOntologyResource other = ( AbstractOntologyResource ) obj ;
80+ final OntologyResource other = ( OntologyResource ) obj ;
4581 if ( getLabel () == null ) {
4682 if ( other .getLabel () != null ) return false ;
4783 } else if ( !getLabel ().equals ( other .getLabel () ) ) return false ;
@@ -51,16 +87,17 @@ public boolean equals( Object obj ) {
5187 return true ;
5288 }
5389
54- @ Override
55- public abstract String getUri ();
56-
5790 @ Override
5891 public int hashCode () {
59- final int PRIME = 31 ;
60- int result = 1 ;
61- result = PRIME * result + ( ( getLabel () == null ) ? 0 : getLabel ().hashCode () );
62- result = PRIME * result + ( ( getUri () == null ) ? 0 : getUri ().hashCode () );
63- return result ;
92+ return Objects .hash ( getLabel (), getUri () );
6493 }
6594
66- }
95+ @ Override
96+ public String toString () {
97+ String s = getLabel ();
98+ if ( s == null ) {
99+ s = res .toString ();
100+ }
101+ return s ;
102+ }
103+ }
0 commit comments