View Javadoc
1   /*
2    * The basecode project
3    * 
4    * Copyright (c) 2007-2019 University of British Columbia
5    * 
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   *
18   */
19  package ubic.basecode.ontology.model;
20  
21  import java.util.Collection;
22  import java.util.HashSet;
23  
24  import com.hp.hpl.jena.ontology.ObjectProperty;
25  import com.hp.hpl.jena.ontology.OntClass;
26  import com.hp.hpl.jena.ontology.OntResource;
27  import com.hp.hpl.jena.util.iterator.ExtendedIterator;
28  
29  /**
30   * @author pavlidis
31   * 
32   */
33  public class ObjectPropertyImpl extends OntologyPropertyImpl implements ubic.basecode.ontology.model.ObjectProperty {
34  
35      /**
36       * 
37       */
38      private static final long serialVersionUID = 1L;
39      private com.hp.hpl.jena.ontology.ObjectProperty resource;
40  
41      public ObjectPropertyImpl( ObjectProperty resource ) {
42          this.isFunctional = resource.isFunctionalProperty();
43          this.resource = resource;
44      }
45  
46      @Override
47      public String getLabel() {
48          return this.toString();
49      }
50  
51      @Override
52      public Collection<OntologyTerm> getRange() {
53          ExtendedIterator<? extends OntResource> iterator = resource.listRange();
54          Collection<OntologyTerm> result = new HashSet<OntologyTerm>();
55          while ( iterator.hasNext() ) {
56              OntResource r = iterator.next();
57              if ( r.isClass() ) {
58                  OntClass class1 = r.asClass();
59                  result.add( new OntologyTermImpl( class1 ) );
60              } else {
61                  log.warn( "Don't know how to deal with " + r );
62              }
63          }
64          return result;
65      }
66  
67      @Override
68      public String getUri() {
69          return resource.getURI();
70      }
71  
72      @Override
73      public String toString() {
74          String label = resource.getLabel( "EN" );
75          if ( label == null ) label = resource.getLabel( null );
76          if ( label == null ) label = resource.getLocalName();
77          if ( label == null ) label = resource.getURI();
78          if ( label == null ) label = resource.toString();
79          if ( label == null ) label = "[no string version available!]";
80          return label;
81      }
82  }