2424import com .hp .hpl .jena .rdf .arp .ParseException ;
2525import com .hp .hpl .jena .rdf .model .Property ;
2626import com .hp .hpl .jena .rdf .model .Resource ;
27- import com .hp .hpl .jena .shared .JenaException ;
2827import com .hp .hpl .jena .util .iterator .ExtendedIterator ;
2928import org .apache .commons .lang3 .RandomStringUtils ;
3029import org .apache .commons .lang3 .StringUtils ;
3130import org .apache .commons .lang3 .time .StopWatch ;
3231import org .slf4j .Logger ;
3332import org .slf4j .LoggerFactory ;
34- import ubic .basecode .ontology .jena .search .OntologyIndexer ;
35- import ubic .basecode .ontology .jena .search .OntologySearch ;
36- import ubic .basecode .ontology .jena .search .SearchIndex ;
3733import ubic .basecode .ontology .jena .vocabulary .BFO ;
3834import ubic .basecode .ontology .jena .vocabulary .RO ;
3935import ubic .basecode .ontology .model .OntologyIndividual ;
36+ import ubic .basecode .ontology .model .OntologyModel ;
4037import ubic .basecode .ontology .model .OntologyResource ;
4138import ubic .basecode .ontology .model .OntologyTerm ;
4239import ubic .basecode .ontology .providers .OntologyService ;
@@ -201,7 +198,12 @@ private void initialize( @Nullable InputStream stream, boolean forceLoad, boolea
201198 return ;
202199
203200 try {
204- model = stream != null ? loadModelFromStream ( stream , processImports , inferenceMode ) : loadModel ( processImports , inferenceMode ); // can take a while.
201+ OntologyModel m = stream != null ? loadModelFromStream ( stream , processImports , inferenceMode ) : loadModel ( processImports , inferenceMode ); // can take a while.
202+ if ( m instanceof OntologyModelImpl ) {
203+ model = ( ( OntologyModelImpl ) m ).getOntModel ();
204+ } else {
205+ throw new RuntimeException ( "Only Jena-based ontology models are supported." );
206+ }
205207 } catch ( Exception e ) {
206208 if ( isCausedByInterrupt ( e ) ) {
207209 return ;
@@ -491,7 +493,7 @@ public Collection<OntologyIndividual> getTermIndividuals( String uri ) {
491493
492494 @ Override
493495 public Set <OntologyTerm > getParents ( Collection <OntologyTerm > terms , boolean direct ,
494- boolean includeAdditionalProperties , boolean keepObsoletes ) {
496+ boolean includeAdditionalProperties , boolean keepObsoletes ) {
495497 Lock lock = rwLock .readLock ();
496498 try {
497499 lock .lock ();
@@ -510,7 +512,7 @@ public Set<OntologyTerm> getParents( Collection<OntologyTerm> terms, boolean dir
510512
511513 @ Override
512514 public Set <OntologyTerm > getChildren ( Collection <OntologyTerm > terms , boolean direct ,
513- boolean includeAdditionalProperties , boolean keepObsoletes ) {
515+ boolean includeAdditionalProperties , boolean keepObsoletes ) {
514516 Lock lock = rwLock .readLock ();
515517 try {
516518 lock .lock ();
@@ -615,13 +617,13 @@ public void waitForInitializationThread() throws InterruptedException {
615617 * Delegates the call as to load the model into memory or leave it on disk. Simply delegates to either
616618 * OntologyLoader.loadMemoryModel( url ); OR OntologyLoader.loadPersistentModel( url, spec );
617619 */
618- protected abstract OntModel loadModel ( boolean processImports , InferenceMode inferenceMode ) throws JenaException , IOException ;
620+ protected abstract OntologyModel loadModel ( boolean processImports , InferenceMode inferenceMode ) throws IOException ;
619621
620622
621623 /**
622624 * Load a model from a given input stream.
623625 */
624- protected abstract OntModel loadModelFromStream ( InputStream stream , boolean processImports , InferenceMode inferenceMode ) throws JenaException , IOException ;
626+ protected abstract OntologyModel loadModelFromStream ( InputStream stream , boolean processImports , InferenceMode inferenceMode ) throws IOException ;
625627
626628 /**
627629 * A name for caching this ontology, or null to disable caching.
@@ -633,6 +635,17 @@ protected String getCacheName() {
633635 return getOntologyName ();
634636 }
635637
638+ private OntModelSpec getSpec ( InferenceMode inferenceMode ) {
639+ switch ( inferenceMode ) {
640+ case TRANSITIVE :
641+ return OntModelSpec .OWL_MEM_TRANS_INF ;
642+ case NONE :
643+ return OntModelSpec .OWL_MEM ;
644+ default :
645+ throw new UnsupportedOperationException ( String .format ( "Unsupported inference level %s." , inferenceMode ) );
646+ }
647+ }
648+
636649 @ Override
637650 public void index ( boolean force ) {
638651 String cacheName = getCacheName ();
0 commit comments