Class AbstractOntologyService
- java.lang.Object
-
- ubic.basecode.ontology.jena.AbstractOntologyService
-
- All Implemented Interfaces:
OntologyService
- Direct Known Subclasses:
AbstractOntologyService
public abstract class AbstractOntologyService extends Object implements OntologyService
Base class for Jena-based ontology services.- Author:
- kelsey
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ubic.basecode.ontology.providers.OntologyService
OntologyService.InferenceMode, OntologyService.LanguageLevel
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
log
-
Constructor Summary
Constructors Constructor Description AbstractOntologyService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
cancelInitializationThread()
Cancel the initialization thread.Collection<OntologySearchResult<OntologyIndividual>>
findIndividuals(String search, int maxResults, boolean keepObsoletes)
Looks for any individuals that match the given search string.Collection<OntologySearchResult<OntologyResource>>
findResources(String searchString, int maxResults, boolean keepObsoletes)
Looks for any resources (terms or individuals) that match the given search stringCollection<OntologySearchResult<OntologyTerm>>
findTerm(String search, int maxResults, boolean keepObsoletes)
Looks for any terms that match the given search string.OntologyTerm
findUsingAlternativeId(String alternativeId)
Find a term using an alternative ID.Set<String>
getAdditionalPropertyUris()
Obtain the URIs used as additional properties when inferring parents and children.Set<String>
getAllURIs()
Obtain all the resource URIs in this ontology.protected abstract String
getCacheName()
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.String
getDescription()
Obtain a description of this ontology if available.Set<String>
getExcludedWordsFromStemming()
Obtain the words that should be excluded from stemming.OntologyService.InferenceMode
getInferenceMode()
Obtain the inference mode used for this ontology.OntologyService.LanguageLevel
getLanguageLevel()
Obtain the OWL language level supported by this ontology.String
getName()
Obtain the name of this ontology if available.protected abstract String
getOntologyName()
The simple getOntologyName() of the ontology.protected abstract String
getOntologyUrl()
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.boolean
getProcessImports()
Check if this ontology will process imports.OntologyResource
getResource(String uri)
Looks through both Terms and Individuals for a OntologyResource that has a uri matching the uri given.OntologyTerm
getTerm(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.void
index(boolean force)
Index the ontology for performing full-text searches.void
initialize(boolean forceLoad, boolean forceIndexing)
Initialize this ontology service.void
initialize(InputStream stream, boolean forceIndexing)
Initialize this ontology service from a stream.boolean
isEnabled()
Check if this ontology is enabled.boolean
isInitializationThreadAlive()
Check if the initialization thread is alive.boolean
isInitializationThreadCancelled()
Check if the initialization thread is cancelled.protected abstract boolean
isOntologyEnabled()
Indicate if this ontology is enabled.boolean
isOntologyLoaded()
Used for determining if the Ontology has finished loading into memory.boolean
isSearchEnabled()
Check if this ontology has full-text search enabled.protected OntologyModel
loadModel(boolean processImports, OntologyService.LanguageLevel languageLevel, OntologyService.InferenceMode inferenceMode)
Delegates the call as to load the model into memory or leave it on disk.protected OntologyModel
loadModelFromStream(InputStream is, boolean processImports, OntologyService.LanguageLevel languageLevel, OntologyService.InferenceMode inferenceMode)
Load a model from a given input stream.void
loadTermsInNameSpace(InputStream is, boolean forceIndex)
For testing! Overrides normal way of loading the ontology.void
setAdditionalPropertyUris(Set<String> additionalPropertyUris)
Set the URIs to be used as additional properties when inferring parents and children.void
setExcludedWordsFromStemming(Set<String> excludedWordsFromStemming)
Set words that should be excluded from stemming when searching.void
setInferenceMode(OntologyService.InferenceMode inferenceMode)
Set the inference mode used for this ontology.void
setLanguageLevel(OntologyService.LanguageLevel languageLevel)
Set the OWL language level supported by this ontology.void
setProcessImports(boolean processImports)
Allow of forbid this ontology to process imports.void
setSearchEnabled(boolean searchEnabled)
Enable or disable search for this ontology.void
startInitializationThread(boolean forceLoad, boolean forceIndexing)
Start the initialization thread.String
toString()
void
waitForInitializationThread()
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
-
getName
public String getName()
Description copied from interface:OntologyService
Obtain the name of this ontology if available.- Specified by:
getName
in interfaceOntologyService
-
getDescription
public String getDescription()
Description copied from interface:OntologyService
Obtain a description of this ontology if available.- Specified by:
getDescription
in interfaceOntologyService
-
getLanguageLevel
public OntologyService.LanguageLevel getLanguageLevel()
Description copied from interface:OntologyService
Obtain the OWL language level supported by this ontology.The default is to use
OntologyService.LanguageLevel.FULL
.- Specified by:
getLanguageLevel
in interfaceOntologyService
-
setLanguageLevel
public void setLanguageLevel(OntologyService.LanguageLevel languageLevel)
Description copied from interface:OntologyService
Set the OWL language level supported by this ontology.Changes are applicable only if the service is re-initialized.
- Specified by:
setLanguageLevel
in interfaceOntologyService
-
getInferenceMode
public OntologyService.InferenceMode getInferenceMode()
Description copied from interface:OntologyService
Obtain the inference mode used for this ontology.The default is
OntologyService.InferenceMode.TRANSITIVE
.- Specified by:
getInferenceMode
in interfaceOntologyService
-
setInferenceMode
public void setInferenceMode(OntologyService.InferenceMode inferenceMode)
Description copied from interface:OntologyService
Set the inference mode used for this ontology.Changes are applicable only if the service is re-initialized.
- Specified by:
setInferenceMode
in interfaceOntologyService
-
getProcessImports
public boolean getProcessImports()
Description copied from interface:OntologyService
Check if this ontology will process imports.If disabled, ontologies imported by this ontology will not be loaded.
- Specified by:
getProcessImports
in interfaceOntologyService
-
setProcessImports
public void setProcessImports(boolean processImports)
Description copied from interface:OntologyService
Allow of forbid this ontology to process imports.Changes are applicable only if the service is re-initialized.
- Specified by:
setProcessImports
in interfaceOntologyService
-
isSearchEnabled
public boolean isSearchEnabled()
Description copied from interface:OntologyService
Check if this ontology has full-text search enabled.This is necessary for finding term using full-text queries. If enabled, an index will be generated in during initialization by
OntologyService.initialize(boolean, boolean)
.Search is enabled by default.
-
setSearchEnabled
public void setSearchEnabled(boolean searchEnabled)
Description copied from interface:OntologyService
Enable or disable search for this ontology.Changes are only applicable if the service is re-initialized.
- Specified by:
setSearchEnabled
in interfaceOntologyService
-
getExcludedWordsFromStemming
public Set<String> getExcludedWordsFromStemming()
Description copied from interface:OntologyService
Obtain the words that should be excluded from stemming.By default, all words are subject to stemming. The exact implementation of stemming depends on the actual search implementation.
- Specified by:
getExcludedWordsFromStemming
in interfaceOntologyService
-
setExcludedWordsFromStemming
public void setExcludedWordsFromStemming(Set<String> excludedWordsFromStemming)
Description copied from interface:OntologyService
Set words that should be excluded from stemming when searching.- Specified by:
setExcludedWordsFromStemming
in interfaceOntologyService
-
getAdditionalPropertyUris
public Set<String> getAdditionalPropertyUris()
Description copied from interface:OntologyService
Obtain the URIs used as additional properties when inferring parents and children.The default is to use part of, proper part of and all of their sub-properties if inference is enabled.
-
setAdditionalPropertyUris
public void setAdditionalPropertyUris(Set<String> additionalPropertyUris)
Description copied from interface:OntologyService
Set the URIs to be used as additional properties when inferring parents and children.Changes are applicable only if the service is re-initialized.
- Specified by:
setAdditionalPropertyUris
in interfaceOntologyService
-
initialize
public void initialize(boolean forceLoad, boolean forceIndexing)
Description copied from interface:OntologyService
Initialize this ontology service.- Specified by:
initialize
in 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:OntologyService
Initialize 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:
initialize
in interfaceOntologyService
-
findIndividuals
public Collection<OntologySearchResult<OntologyIndividual>> findIndividuals(String search, int maxResults, boolean keepObsoletes) throws OntologySearchException
Description copied from interface:OntologyService
Looks for any individuals that match the given search string.- Specified by:
findIndividuals
in interfaceOntologyService
- Parameters:
search
- search querykeepObsoletes
- retain obsolete terms- Throws:
OntologySearchException
-
findResources
public Collection<OntologySearchResult<OntologyResource>> findResources(String searchString, int maxResults, boolean keepObsoletes) throws OntologySearchException
Description copied from interface:OntologyService
Looks for any resources (terms or individuals) that match the given search string- Specified by:
findResources
in interfaceOntologyService
- Parameters:
searchString
- search querykeepObsoletes
- retain obsolete terms- Throws:
OntologySearchException
-
findTerm
public Collection<OntologySearchResult<OntologyTerm>> findTerm(String search, int maxResults, boolean keepObsoletes) throws OntologySearchException
Description copied from interface:OntologyService
Looks for any terms that match the given search string.- Specified by:
findTerm
in interfaceOntologyService
- Parameters:
search
- search querykeepObsoletes
- retain obsolete terms- Throws:
OntologySearchException
-
findUsingAlternativeId
public OntologyTerm findUsingAlternativeId(String alternativeId)
Description copied from interface:OntologyService
Find a term using an alternative ID.- Specified by:
findUsingAlternativeId
in interfaceOntologyService
-
getAllURIs
public Set<String> getAllURIs()
Description copied from interface:OntologyService
Obtain all the resource URIs in this ontology.- Specified by:
getAllURIs
in interfaceOntologyService
-
getResource
public OntologyResource getResource(String uri)
Description copied from interface:OntologyService
Looks 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:
getResource
in interfaceOntologyService
-
getTerm
public OntologyTerm getTerm(String uri)
Description copied from interface:OntologyService
Looks for a OntologyTerm that has the match in URI given- Specified by:
getTerm
in interfaceOntologyService
-
getTermIndividuals
public Collection<OntologyIndividual> getTermIndividuals(String uri)
Description copied from interface:OntologyService
Obtain all the individuals for a given term URI.- Specified by:
getTermIndividuals
in interfaceOntologyService
-
getParents
public Set<OntologyTerm> getParents(Collection<OntologyTerm> terms, boolean direct, boolean includeAdditionalProperties, boolean keepObsoletes)
Description copied from interface:OntologyService
Obtain all the parents of a given set of terms.- Specified by:
getParents
in 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:OntologyService
Obtain all the children of a given set of terms.- Specified by:
getChildren
in 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:OntologyService
Check if this ontology is enabled.- Specified by:
isEnabled
in interfaceOntologyService
-
isOntologyLoaded
public boolean isOntologyLoaded()
Description copied from interface:OntologyService
Used 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:
isOntologyLoaded
in interfaceOntologyService
-
startInitializationThread
public void startInitializationThread(boolean forceLoad, boolean forceIndexing)
Description copied from interface:OntologyService
Start 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:
startInitializationThread
in 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:OntologyService
Check if the initialization thread is alive.- Specified by:
isInitializationThreadAlive
in interfaceOntologyService
-
isInitializationThreadCancelled
public boolean isInitializationThreadCancelled()
Description copied from interface:OntologyService
Check if the initialization thread is cancelled.- Specified by:
isInitializationThreadCancelled
in interfaceOntologyService
-
cancelInitializationThread
public void cancelInitializationThread()
Cancel the initialization thread.- Specified by:
cancelInitializationThread
in interfaceOntologyService
-
waitForInitializationThread
public void waitForInitializationThread() throws InterruptedException
Description copied from interface:OntologyService
Wait for the initialization thread to finish.- Specified by:
waitForInitializationThread
in 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
-
isOntologyEnabled
protected abstract boolean isOntologyEnabled()
Indicate if this ontology is enabled.
-
getCacheName
@Nullable protected abstract 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.
-
loadModel
protected OntologyModel loadModel(boolean processImports, OntologyService.LanguageLevel languageLevel, OntologyService.InferenceMode inferenceMode) throws IOException
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 );- Throws:
IOException
-
loadModelFromStream
protected OntologyModel loadModelFromStream(InputStream is, boolean processImports, OntologyService.LanguageLevel languageLevel, OntologyService.InferenceMode inferenceMode) throws IOException
Load a model from a given input stream.- Throws:
IOException
-
index
public void index(boolean force)
Description copied from interface:OntologyService
Index the ontology for performing full-text searches.- Specified by:
index
in interfaceOntologyService
- Parameters:
force
- if true, perform indexing even if an index already exists- See Also:
#findIndividuals(String)
,#findTerm(String)
,#findResources(String)
-
loadTermsInNameSpace
public void loadTermsInNameSpace(InputStream is, boolean forceIndex)
Description copied from interface:OntologyService
For 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:
loadTermsInNameSpace
in 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.
-
-