Package ubic.basecode.ontology.jena
Class AbstractOntologyService
- java.lang.Object
-
- ubic.basecode.ontology.jena.AbstractOntologyService
-
- All Implemented Interfaces:
OntologyService
- Direct Known Subclasses:
AbstractOntologyMemoryBackedService,MedicOntologyService
public abstract class AbstractOntologyService extends Object implements OntologyService
Base class for Jena-based ontology services.- Author:
- kelsey
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description AbstractOntologyService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcancelInitializationThread()Cancel the initialization thread.voidcloseIndex()Do not do this except before re-indexing.Collection<OntologyIndividual>findIndividuals(String search, boolean keepObsoletes)Looks for any individuals that match the given search string.Collection<OntologyResource>findResources(String searchString, boolean keepObsoletes)Looks for any resources (terms or individuals) that match the given search stringCollection<OntologyTerm>findTerm(String search, boolean keepObsoletes)Looks for any terms that match the given search string.OntologyTermfindUsingAlternativeId(String alternativeId)Find a term using an alternative ID.Set<String>getAllURIs()Obtain all the resource URIs in this ontology.protected StringgetCacheName()A name for caching this ontology, or null to disable caching.Set<OntologyTerm>getChildren(Collection<OntologyTerm> terms, boolean direct, boolean includeAdditionalProperties, boolean keepObsoletes)Obtain all the children of a given set of terms.protected abstract StringgetOntologyName()The simple getOntologyName() of the ontology.protected abstract StringgetOntologyUrl()Defines the location of the ontology eg: MGEDSet<OntologyTerm>getParents(Collection<OntologyTerm> terms, boolean direct, boolean includeAdditionalProperties, boolean keepObsoletes)Obtain all the parents of a given set of terms.OntologyResourcegetResource(String uri)Looks through both Terms and Individuals for a OntologyResource that has a uri matching the uri given.OntologyTermgetTerm(String uri)Looks for a OntologyTerm that has the match in URI givenCollection<OntologyIndividual>getTermIndividuals(String uri)Obtain all the individuals for a given term URI.voidindex(boolean force)Index the ontology for performing full-text searches.voidinitialize(boolean forceLoad, boolean forceIndexing)Initialize this ontology service.voidinitialize(InputStream stream, boolean forceIndexing)Initialize this ontology service from a stream.booleanisEnabled()Check if this ontology is enabled.booleanisInitializationThreadAlive()Check if the initialization thread is alive.booleanisInitializationThreadCancelled()Check if the initialization thread is cancelled.booleanisOntologyLoaded()Used for determining if the Ontology has finished loading into memory.protected abstract com.hp.hpl.jena.ontology.OntModelloadModel()Delegates the call as to load the model into memory or leave it on disk.protected abstract com.hp.hpl.jena.ontology.OntModelloadModelFromStream(InputStream stream)Load a model from a given input stream.voidloadTermsInNameSpace(InputStream is, boolean forceIndex)For testing!voidstartInitializationThread(boolean forceLoad, boolean forceIndexing)Start the initialization thread.StringtoString()voidwaitForInitializationThread()Wait for the initialization thread to finish.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ubic.basecode.ontology.providers.OntologyService
findIndividuals, findResources, findTerm, getChildren, getParents
-
-
-
-
Method Detail
-
initialize
public void initialize(boolean forceLoad, boolean forceIndexing)Description copied from interface:OntologyServiceInitialize this ontology service.- Specified by:
initializein interfaceOntologyService- Parameters:
forceLoad- Force loading of ontology, even if it is already loadedforceIndexing- If forceLoad is also true, indexing will be performed. If you know the index is up-to-date, there's no need to do it again. Normally indexing is only done if there is no index, or if the ontology has changed since last loaded.
-
initialize
public void initialize(InputStream stream, boolean forceIndexing)
Description copied from interface:OntologyServiceInitialize this ontology service from a stream.Note that when this method of initialization is used, the ontology cache is not created on-disk.
- Specified by:
initializein interfaceOntologyService
-
closeIndex
public void closeIndex()
Do not do this except before re-indexing.
-
findIndividuals
public Collection<OntologyIndividual> findIndividuals(String search, boolean keepObsoletes) throws OntologySearchException
Description copied from interface:OntologyServiceLooks for any individuals that match the given search string.- Specified by:
findIndividualsin interfaceOntologyService- Parameters:
search- search querykeepObsoletes- retain obsolete terms- Throws:
OntologySearchException
-
findResources
public Collection<OntologyResource> findResources(String searchString, boolean keepObsoletes) throws OntologySearchException
Description copied from interface:OntologyServiceLooks for any resources (terms or individuals) that match the given search string- Specified by:
findResourcesin interfaceOntologyService- Parameters:
searchString- search querykeepObsoletes- retain obsolete terms- Throws:
OntologySearchException
-
findTerm
public Collection<OntologyTerm> findTerm(String search, boolean keepObsoletes) throws OntologySearchException
Description copied from interface:OntologyServiceLooks for any terms that match the given search string.- Specified by:
findTermin interfaceOntologyService- Parameters:
search- search querykeepObsoletes- retain obsolete terms- Throws:
OntologySearchException
-
findUsingAlternativeId
public OntologyTerm findUsingAlternativeId(String alternativeId)
Description copied from interface:OntologyServiceFind a term using an alternative ID.- Specified by:
findUsingAlternativeIdin interfaceOntologyService
-
getAllURIs
public Set<String> getAllURIs()
Description copied from interface:OntologyServiceObtain all the resource URIs in this ontology.- Specified by:
getAllURIsin interfaceOntologyService
-
getResource
public OntologyResource getResource(String uri)
Description copied from interface:OntologyServiceLooks through both Terms and Individuals for a OntologyResource that has a uri matching the uri given. If no OntologyTerm is found only then will ontologyIndividuals be searched. returns null if nothing is found.- Specified by:
getResourcein interfaceOntologyService
-
getTerm
public OntologyTerm getTerm(String uri)
Description copied from interface:OntologyServiceLooks for a OntologyTerm that has the match in URI given- Specified by:
getTermin interfaceOntologyService
-
getTermIndividuals
public Collection<OntologyIndividual> getTermIndividuals(String uri)
Description copied from interface:OntologyServiceObtain all the individuals for a given term URI.- Specified by:
getTermIndividualsin interfaceOntologyService
-
getParents
public Set<OntologyTerm> getParents(Collection<OntologyTerm> terms, boolean direct, boolean includeAdditionalProperties, boolean keepObsoletes)
Description copied from interface:OntologyServiceObtain all the parents of a given set of terms.- Specified by:
getParentsin interfaceOntologyService- Parameters:
terms- set of terms whose parents are retrieveddirect- only retain direct parentsincludeAdditionalProperties- also include parents matched via additional propertieskeepObsoletes- retain obsolete terms- Returns:
- a set of parent terms
-
getChildren
public Set<OntologyTerm> getChildren(Collection<OntologyTerm> terms, boolean direct, boolean includeAdditionalProperties, boolean keepObsoletes)
Description copied from interface:OntologyServiceObtain all the children of a given set of terms.- Specified by:
getChildrenin interfaceOntologyService- Parameters:
terms- set of terms whose children are retrieveddirect- only retain direct childrenincludeAdditionalProperties- also include children matched via additional propertieskeepObsoletes- retain obsolete terms- Returns:
- a set of child terms
-
isEnabled
public boolean isEnabled()
Description copied from interface:OntologyServiceCheck if this ontology is enabled.- Specified by:
isEnabledin interfaceOntologyService
-
isOntologyLoaded
public boolean isOntologyLoaded()
Description copied from interface:OntologyServiceUsed for determining if the Ontology has finished loading into memory. Although calls like getParents, getChildren will still work (its much faster once the ontologies have been preloaded into memory.)- Specified by:
isOntologyLoadedin interfaceOntologyService
-
startInitializationThread
public void startInitializationThread(boolean forceLoad, boolean forceIndexing)Description copied from interface:OntologyServiceStart the initialization thread.If the initialization thread is already running, this method does nothing. If the initialization thread previously completed, the ontology will be reinitialized.
- Specified by:
startInitializationThreadin interfaceOntologyService- Parameters:
forceLoad- Force loading of ontology, even if it is already loadedforceIndexing- If forceLoad is also true, indexing will be performed. If you know the index is up to date, there's no need to do it again. Normally indexing is only done if there is no index, or if the ontology has changed since last loaded.
-
isInitializationThreadAlive
public boolean isInitializationThreadAlive()
Description copied from interface:OntologyServiceCheck if the initialization thread is alive.- Specified by:
isInitializationThreadAlivein interfaceOntologyService
-
isInitializationThreadCancelled
public boolean isInitializationThreadCancelled()
Description copied from interface:OntologyServiceCheck if the initialization thread is cancelled.- Specified by:
isInitializationThreadCancelledin interfaceOntologyService
-
cancelInitializationThread
public void cancelInitializationThread()
Cancel the initialization thread.- Specified by:
cancelInitializationThreadin interfaceOntologyService
-
waitForInitializationThread
public void waitForInitializationThread() throws InterruptedExceptionDescription copied from interface:OntologyServiceWait for the initialization thread to finish.- Specified by:
waitForInitializationThreadin interfaceOntologyService- Throws:
InterruptedException
-
getOntologyName
protected abstract String getOntologyName()
The simple getOntologyName() of the ontology. Used for indexing purposes. (ie this will determine the getOntologyName() of the underlying index for searching the ontology)
-
getOntologyUrl
protected abstract String getOntologyUrl()
Defines the location of the ontology eg: MGED
-
loadModel
protected abstract com.hp.hpl.jena.ontology.OntModel loadModel()
Delegates the call as to load the model into memory or leave it on disk. Simply delegates to either OntologyLoader.loadMemoryModel( url ); OR OntologyLoader.loadPersistentModel( url, spec );
-
loadModelFromStream
protected abstract com.hp.hpl.jena.ontology.OntModel loadModelFromStream(InputStream stream)
Load a model from a given input stream.
-
getCacheName
@Nullable protected String getCacheName()
A name for caching this ontology, or null to disable caching.Note that if null is returned, the ontology will not have full-text search capabilities.
-
index
public void index(boolean force)
Description copied from interface:OntologyServiceIndex the ontology for performing full-text searches.- Specified by:
indexin interfaceOntologyService- Parameters:
force- if true, perform indexing even if an index already exists- See Also:
OntologyService.findIndividuals(String),OntologyService.findTerm(String),OntologyService.findResources(String)
-
loadTermsInNameSpace
public void loadTermsInNameSpace(InputStream is, boolean forceIndex)
Description copied from interface:OntologyServiceFor testing! Overrides normal way of loading the ontology. This does not index the ontology unless 'force' is true (if there is an existing index, it will be used)- Specified by:
loadTermsInNameSpacein interfaceOntologyService- Parameters:
is- input stream from which the ontology model is loadedforceIndex- initialize the index. Otherwise it will only be initialized if it doesn't exist.
-
-