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.jena;
20  
21  import java.util.Collection;
22  import java.util.HashSet;
23  import java.util.Set;
24  
25  import com.hp.hpl.jena.ontology.ObjectProperty;
26  import com.hp.hpl.jena.ontology.OntClass;
27  import com.hp.hpl.jena.ontology.OntResource;
28  import com.hp.hpl.jena.ontology.Restriction;
29  import com.hp.hpl.jena.util.iterator.ExtendedIterator;
30  import ubic.basecode.ontology.model.OntologyTerm;
31  
32  /**
33   * @author pavlidis
34   */
35  class ObjectPropertyImpl extends OntologyPropertyImpl implements ubic.basecode.ontology.model.ObjectProperty {
36  
37      private final com.hp.hpl.jena.ontology.ObjectProperty resource;
38      private final Set<Restriction> additionalRestrictions;
39  
40      public ObjectPropertyImpl( ObjectProperty resource, Set<Restriction> additionalRestrictions ) {
41          super( resource );
42          this.resource = resource;
43          this.additionalRestrictions = additionalRestrictions;
44      }
45  
46      @Override
47      public Collection<OntologyTerm> getRange() {
48          ExtendedIterator<? extends OntResource> iterator = resource.listRange();
49          Collection<OntologyTerm> result = new HashSet<>();
50          while ( iterator.hasNext() ) {
51              OntResource r = iterator.next();
52              if ( r.isClass() ) {
53                  OntClass class1 = r.asClass();
54                  result.add( new OntologyTermImpl( class1, additionalRestrictions ) );
55              } else {
56                  log.warn( "Don't know how to deal with " + r );
57              }
58          }
59          return result;
60      }
61  }