|
20 | 20 | package ubic.basecode.ontology.jena; |
21 | 21 |
|
22 | 22 | import com.hp.hpl.jena.ontology.*; |
23 | | -import com.hp.hpl.jena.rdf.model.NodeIterator; |
24 | | -import com.hp.hpl.jena.rdf.model.Property; |
25 | | -import com.hp.hpl.jena.rdf.model.Resource; |
26 | | -import com.hp.hpl.jena.rdf.model.ResourceFactory; |
| 23 | +import com.hp.hpl.jena.rdf.model.*; |
27 | 24 | import com.hp.hpl.jena.rdfxml.xmlinput.ARPErrorNumbers; |
28 | 25 | import com.hp.hpl.jena.rdfxml.xmlinput.ParseException; |
| 26 | +import com.hp.hpl.jena.reasoner.ReasonerFactory; |
| 27 | +import com.hp.hpl.jena.reasoner.rulesys.OWLFBRuleReasonerFactory; |
| 28 | +import com.hp.hpl.jena.reasoner.rulesys.OWLMicroReasonerFactory; |
| 29 | +import com.hp.hpl.jena.reasoner.rulesys.OWLMiniReasonerFactory; |
| 30 | +import com.hp.hpl.jena.reasoner.transitiveReasoner.TransitiveReasonerFactory; |
29 | 31 | import com.hp.hpl.jena.util.iterator.ExtendedIterator; |
30 | 32 | import com.hp.hpl.jena.vocabulary.DC_11; |
31 | 33 | import org.apache.commons.lang3.RandomStringUtils; |
|
40 | 42 | import ubic.basecode.ontology.providers.OntologyService; |
41 | 43 | import ubic.basecode.ontology.search.OntologySearchException; |
42 | 44 | import ubic.basecode.ontology.search.OntologySearchResult; |
43 | | -import ubic.basecode.util.Configuration; |
44 | 45 |
|
45 | 46 | import javax.annotation.Nullable; |
46 | 47 | import java.io.IOException; |
@@ -472,13 +473,8 @@ public Set<OntologyTerm> getChildren( Collection<OntologyTerm> terms, boolean di |
472 | 473 |
|
473 | 474 | @Override |
474 | 475 | public boolean isEnabled() { |
475 | | - // quick path: just lookup the configuration |
476 | | - String configParameter = "load." + getOntologyName(); |
477 | | - if ( Boolean.TRUE.equals( Configuration.getBoolean( configParameter ) ) ) { |
478 | | - return true; |
479 | | - } |
480 | 476 | // could have forced, without setting config |
481 | | - return getState().isPresent(); |
| 477 | + return isOntologyEnabled() || isOntologyLoaded() || isInitializationThreadAlive(); |
482 | 478 | } |
483 | 479 |
|
484 | 480 | @Override |
@@ -549,25 +545,69 @@ public void waitForInitializationThread() throws InterruptedException { |
549 | 545 | protected abstract String getOntologyUrl(); |
550 | 546 |
|
551 | 547 | /** |
552 | | - * Delegates the call as to load the model into memory or leave it on disk. Simply delegates to either |
553 | | - * OntologyLoader.loadMemoryModel( url ); OR OntologyLoader.loadPersistentModel( url, spec ); |
554 | | - */ |
555 | | - protected abstract OntologyModel loadModel( boolean processImports, LanguageLevel languageLevel, InferenceMode inferenceMode ) throws IOException; |
556 | | - |
557 | | - |
558 | | - /** |
559 | | - * Load a model from a given input stream. |
| 548 | + * Indicate if this ontology is enabled. |
560 | 549 | */ |
561 | | - protected abstract OntologyModel loadModelFromStream( InputStream stream, boolean processImports, LanguageLevel languageLevel, InferenceMode inferenceMode ) throws IOException; |
| 550 | + protected abstract boolean isOntologyEnabled(); |
562 | 551 |
|
563 | 552 | /** |
564 | 553 | * A name for caching this ontology, or null to disable caching. |
565 | 554 | * <p> |
566 | 555 | * Note that if null is returned, the ontology will not have full-text search capabilities. |
567 | 556 | */ |
568 | 557 | @Nullable |
569 | | - protected String getCacheName() { |
570 | | - return getOntologyName(); |
| 558 | + protected abstract String getCacheName(); |
| 559 | + |
| 560 | + /** |
| 561 | + * Delegates the call as to load the model into memory or leave it on disk. Simply delegates to either |
| 562 | + * OntologyLoader.loadMemoryModel( url ); OR OntologyLoader.loadPersistentModel( url, spec ); |
| 563 | + */ |
| 564 | + protected OntologyModel loadModel( boolean processImports, LanguageLevel languageLevel, InferenceMode inferenceMode ) throws IOException { |
| 565 | + return new OntologyModelImpl( OntologyLoader.loadMemoryModel( this.getOntologyUrl(), this.getCacheName(), processImports, this.getSpec( languageLevel, inferenceMode ) ) ); |
| 566 | + } |
| 567 | + |
| 568 | + /** |
| 569 | + * Load a model from a given input stream. |
| 570 | + */ |
| 571 | + protected OntologyModel loadModelFromStream( InputStream is, boolean processImports, LanguageLevel languageLevel, InferenceMode inferenceMode ) throws IOException { |
| 572 | + return new OntologyModelImpl( OntologyLoader.loadMemoryModel( is, this.getOntologyUrl(), processImports, this.getSpec( languageLevel, inferenceMode ) ) ); |
| 573 | + } |
| 574 | + |
| 575 | + private OntModelSpec getSpec( LanguageLevel languageLevel, InferenceMode inferenceMode ) { |
| 576 | + String profile; |
| 577 | + switch ( languageLevel ) { |
| 578 | + case FULL: |
| 579 | + profile = ProfileRegistry.OWL_LANG; |
| 580 | + break; |
| 581 | + case DL: |
| 582 | + profile = ProfileRegistry.OWL_DL_LANG; |
| 583 | + break; |
| 584 | + case LITE: |
| 585 | + profile = ProfileRegistry.OWL_LITE_LANG; |
| 586 | + break; |
| 587 | + default: |
| 588 | + throw new UnsupportedOperationException( String.format( "Unsupported OWL language level %s.", languageLevel ) ); |
| 589 | + } |
| 590 | + ReasonerFactory reasonerFactory; |
| 591 | + switch ( inferenceMode ) { |
| 592 | + case FULL: |
| 593 | + reasonerFactory = OWLFBRuleReasonerFactory.theInstance(); |
| 594 | + break; |
| 595 | + case MINI: |
| 596 | + reasonerFactory = OWLMiniReasonerFactory.theInstance(); |
| 597 | + break; |
| 598 | + case MICRO: |
| 599 | + reasonerFactory = OWLMicroReasonerFactory.theInstance(); |
| 600 | + break; |
| 601 | + case TRANSITIVE: |
| 602 | + reasonerFactory = TransitiveReasonerFactory.theInstance(); |
| 603 | + break; |
| 604 | + case NONE: |
| 605 | + reasonerFactory = null; |
| 606 | + break; |
| 607 | + default: |
| 608 | + throw new UnsupportedOperationException( String.format( "Unsupported inference level %s.", inferenceMode ) ); |
| 609 | + } |
| 610 | + return new OntModelSpec( ModelFactory.createMemModelMaker(), null, reasonerFactory, profile ); |
571 | 611 | } |
572 | 612 |
|
573 | 613 | @Override |
|
0 commit comments