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  public class ObjectPropertyImpl extends OntologyPropertyImpl implements ubic.basecode.ontology.model.ObjectProperty {
36  
37      /**
38       *
39       */
40      private static final long serialVersionUID = 1L;
41      private final com.hp.hpl.jena.ontology.ObjectProperty resource;
42      private final Set<Restriction> additionalRestrictions;
43  
44      public ObjectPropertyImpl( ObjectProperty resource, Set<Restriction> additionalRestrictions ) {
45          super( resource );
46          this.isFunctional = resource.isFunctionalProperty();
47          this.resource = resource;
48          this.additionalRestrictions = additionalRestrictions;
49      }
50  
51      @Override
52      public Collection<OntologyTerm> getRange() {
53          ExtendedIterator<? extends OntResource> iterator = resource.listRange();
54          Collection<OntologyTerm> result = new HashSet<>();
55          while ( iterator.hasNext() ) {
56              OntResource r = iterator.next();
57              if ( r.isClass() ) {
58                  OntClass class1 = r.asClass();
59                  result.add( new OntologyTermImpl( class1, additionalRestrictions ) );
60              } else {
61                  log.warn( "Don't know how to deal with " + r );
62              }
63          }
64          return result;
65      }
66  }