Package org.biojavax.ontology
Class SimpleComparableOntology
java.lang.Object
org.biojava.utils.AbstractChangeable
org.biojavax.ontology.SimpleComparableOntology
- All Implemented Interfaces:
Comparable
,Ontology
,Changeable
,ComparableOntology
Represents an ontology that can be compared to other ontologies.
- Since:
- 1.5
- Author:
- Richard Holland, Mark Schreiber
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.biojava.ontology.Ontology
Ontology.Impl
-
Field Summary
Fields inherited from interface org.biojavax.ontology.ComparableOntology
DESCRIPTION, TERM, TRIPLE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a new instance of SimpleComparableOntology with the given, immutable, non-nullable name. -
Method Summary
Modifier and TypeMethodDescriptionint
Ontologies are compared only by name.boolean
containsTerm
(String name) Determines if this ontology currently contains a term namedname
boolean
containsTriple
(Term subject, Term object, Term predicate) See if a triple exists in this ontologycreateTerm
(String name) Create a new term in this ontology.createTerm
(String name, String description) Create a new term in this ontology.createTerm
(String name, String description, Object[] synonyms) Create a new term in this ontology.Creates a new Triple.createVariable
(String name, String description) Create a new term in this ontology that is used as a variable.void
deleteTerm
(Term t) Remove a term from an ontology, together with all triples which refer to it.boolean
Ontologies are equal if their names are equal.Return a human-readable description of this ontology.getId()
Gets the Hibernate ID.getName()
Return the name of this ontologygetOps()
Return the associated OntologyOps.getOrCreateTerm
(String name) Looks for a term with the given name and returns it.getOrCreateTriple
(Term subject, Term object, Term predicate) Looks for a triple with the given subject object and predicate and returns it.getOrImportTerm
(Term term) Looks for a term with the same name as the given term and returns it.Fetch the term with the specified name.getTerms()
Return all the terms in this ontologyReturns the set of terms in this ontology.getTriples
(Term subject, Term object, Term predicate) Return all triples from this ontology which match the supplied pattern.Returns the set of triples in this ontology.int
hashCode()
importTerm
(Term t, String localName) Create a view of a term from another ontology.void
setDescription
(String description) Sets a human-readable description of this ontology.void
Sets the Hibernate ID.void
Set the name for this ontologyvoid
setTermSet
(Set terms) Clears out all the terms and populates the ontology with the contents of the set passed.void
setTripleSet
(Set triples) Clears out all the triples and populates the ontology with the contents of the set passed.toString()
Form: "name"Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
Constructor Details
-
SimpleComparableOntology
Creates a new instance of SimpleComparableOntology with the given, immutable, non-nullable name.- Parameters:
name
- the name of the ontology.
-
SimpleComparableOntology
protected SimpleComparableOntology()
-
-
Method Details
-
compareTo
Ontologies are compared only by name.- Specified by:
compareTo
in interfaceComparable
-
equals
Ontologies are equal if their names are equal. -
hashCode
-
toString
Form: "name" -
containsTerm
Determines if this ontology currently contains a term namedname
- Specified by:
containsTerm
in interfaceOntology
- Parameters:
name
-- Returns:
- true is contained
-
getTerm
Fetch the term with the specified name.- Specified by:
getTerm
in interfaceOntology
- Parameters:
s
- the name of the term- Returns:
- The term named
name
- Throws:
NoSuchElementException
- if no term exists with that name
-
getOrCreateTerm
Looks for a term with the given name and returns it. If it couldn't be found, then it creates it, adds it to the ontology, then returns it. If the term has to be created, it is added with the description "auto-generated by biojavax".- Specified by:
getOrCreateTerm
in interfaceComparableOntology
- Parameters:
name
- the name of the term to look for.- Returns:
- the ComparableTerm representing that name.
-
getOrCreateTriple
Looks for a triple with the given subject object and predicate and returns it. If it couldn't be found, then it creates it, adds it to the ontology, then returns it.- Specified by:
getOrCreateTriple
in interfaceComparableOntology
- Parameters:
subject
- the subject of the triple eg appleobject
- the object of the triple eg fruitpredicate
- the relationship of the triple eg is_a- Returns:
- the ComparableTriple representing the object subject and predicate.
-
getOrImportTerm
Looks for a term with the same name as the given term and returns it. If it couldn't be found, then it creates it, adds it to the ontology, then returns it.- Specified by:
getOrImportTerm
in interfaceComparableOntology
- Parameters:
term
- the term to look for.- Returns:
- the ComparableTerm representing that term in this ontology.
-
createTerm
public Term createTerm(String name, String description, Object[] synonyms) throws AlreadyExistsException, ChangeVetoException, IllegalArgumentException Create a new term in this ontology.- Specified by:
createTerm
in interfaceOntology
- Parameters:
name
- The name of the term (must be unique)description
- A human-readable description (may be empty)synonyms
- Some synonyms for this term.- Returns:
- The newly created term.
- Throws:
AlreadyExistsException
- if a term of this name already existsChangeVetoException
IllegalArgumentException
- if eithername
ordescription
isnull
, or violates some other constraint of this implementation.
-
importTerm
public Term importTerm(Term t, String localName) throws ChangeVetoException, IllegalArgumentException Create a view of a term from another ontology. If the requested term has already been imported under that name, this method returns the existing RemoteTerm object. If the term that is being imported is itself a RemoteTerm instance then first unwrap the term back to the orriginal term it represents and then produce a RemoteTerm from that. If the term being imported orriginated from this ontology, then return that term unaltered. This particular implementation merely copies the term into this ontology, and returns a pointer to the copied term. Thus the term becomes a part of this ontology instead of a pointer to another ontology.- Specified by:
importTerm
in interfaceOntology
- Parameters:
t
- the Term to importlocalName
- the local name to import it under, optionally null- Returns:
- a Term
- Throws:
ChangeVetoException
IllegalArgumentException
- See Also:
-
createTriple
public Triple createTriple(Term subject, Term object, Term predicate, String name, String description) throws AlreadyExistsException, ChangeVetoException Creates a new Triple. If you call this method with plain Terms instead of ComparableTerms, it will import them into the local ontology first. This is done BEFORE the check to see if the triple already exists, as obviously it can't check until it has the right terms to check with. So you may find the terms get imported but the triple does not. Moral of the story: use ComparableTerm objects!- Specified by:
createTriple
in interfaceOntology
- Parameters:
subject
- the subject Termobject
- the object Termpredicate
- the predicate Termname
- the name of the triple, or nulldescription
- the description of the triple, or null- Returns:
- a new Triple over these three terms
- Throws:
AlreadyExistsException
- if a triple already exists with the same subject, object and predicate, regardless of the name and descriptionChangeVetoException
- See Also:
-
deleteTerm
Remove a term from an ontology, together with all triples which refer to it. If you call this method with a plain Term instead of a ComparableTerm, it may not match any of the terms in the ontology as they are all stored as ComparableTerms. So, use ComparableTerm objects! This method also removes all triples that the term is involved in.- Specified by:
deleteTerm
in interfaceOntology
- Parameters:
t
-- Throws:
ChangeVetoException
- See Also:
-
getTriples
Return all triples from this ontology which match the supplied pattern. If any of the parameters of this method arenull
, they are treated as wildcards. If you call this method with plain Terms instead of ComparableTerms, it may not match any of the triples in the ontology as they are all stored as ComparableTerms. So, use ComparableTerm objects! The set returned is a set of ComparableTriple objects.- Specified by:
getTriples
in interfaceOntology
- Parameters:
subject
- The subject to search for, ornull
object
- The object to search for, ornull
predicate
- The relationship to search for, ornull
.- Returns:
- a Set of triples
- See Also:
-
setTripleSet
Clears out all the triples and populates the ontology with the contents of the set passed. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.- Specified by:
setTripleSet
in interfaceComparableOntology
- Parameters:
triples
- the set of ComparableTriple objects this ontology should have.- Throws:
ChangeVetoException
- if any of them are unacceptable.- See Also:
-
getTripleSet
Returns the set of triples in this ontology. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.- Specified by:
getTripleSet
in interfaceComparableOntology
- Returns:
- the set of ComparableTriple objects.
-
getTerms
Return all the terms in this ontology This will always return a set of ComparableTerm objects. It is not the original set so you are safe to modify it. -
setTermSet
Clears out all the terms and populates the ontology with the contents of the set passed. The terms should be ComparableTerms. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.- Specified by:
setTermSet
in interfaceComparableOntology
- Parameters:
terms
- a set of Term objects this ontology should have.- Throws:
ChangeVetoException
- if any of them are unacceptable.- See Also:
-
getTermSet
Returns the set of terms in this ontology. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.- Specified by:
getTermSet
in interfaceComparableOntology
- Returns:
- a set of ComparableTerm objects.
- See Also:
-
containsTriple
See if a triple exists in this ontology If you call this method with plain Terms instead of ComparableTerms, it may not match any of the triples in the ontology as they are all stored as ComparableTerms. So, use ComparableTerm objects! The set returned is a set of ComparableTriple objects.- Specified by:
containsTriple
in interfaceOntology
- Parameters:
subject
-object
-predicate
-- Returns:
- true if contained
- See Also:
-
createTerm
public Term createTerm(String name) throws AlreadyExistsException, ChangeVetoException, IllegalArgumentException Create a new term in this ontology.- Specified by:
createTerm
in interfaceOntology
- Parameters:
name
- The name of the term (must be unique))- Returns:
- The newly created term.
- Throws:
AlreadyExistsException
- if a term of this name already existsChangeVetoException
IllegalArgumentException
- if eithername
ordescription
isnull
, or violates some other constraint of this implementation.
-
createTerm
public Term createTerm(String name, String description) throws AlreadyExistsException, ChangeVetoException, IllegalArgumentException Create a new term in this ontology.- Specified by:
createTerm
in interfaceOntology
- Parameters:
name
- The name of the term (must be unique)description
- A human-readable description (may be empty)- Returns:
- The newly created term.
- Throws:
AlreadyExistsException
- if a term of this name already existsChangeVetoException
IllegalArgumentException
- if eithername
ordescription
isnull
, or violates some other constraint of this implementation.
-
createVariable
public Variable createVariable(String name, String description) throws AlreadyExistsException, ChangeVetoException, IllegalArgumentException Create a new term in this ontology that is used as a variable. NOT IMPLEMENTED- Specified by:
createVariable
in interfaceOntology
- Parameters:
name
- The name of the term (must be unique)description
- A human-readable description (may be empty)- Returns:
- The newly created term.
- Throws:
AlreadyExistsException
- if a term of this name already existsChangeVetoException
IllegalArgumentException
- if eithername
ordescription
isnull
, or violates some other constraint of this implementation.
-
getDescription
Return a human-readable description of this ontology.- Specified by:
getDescription
in interfaceComparableOntology
- Specified by:
getDescription
in interfaceOntology
- Returns:
- the description.
-
setDescription
Sets a human-readable description of this ontology.- Specified by:
setDescription
in interfaceComparableOntology
- Specified by:
setDescription
in interfaceOntology
- Parameters:
description
- the description.- Throws:
ChangeVetoException
- in case of problems.
-
getName
Return the name of this ontology -
setName
Description copied from interface:Ontology
Set the name for this ontology -
getOps
Return the associated OntologyOps. This method should be implemented by ontology implementors to allow OntoTools to get optimized access to some usefull ontology operations. It is not intended that users will ever invoke this. A sensible dumb implementation of this would return a per-ontology instance of DefaultOps. -
getId
Gets the Hibernate ID. Should be used with caution.- Returns:
- the Hibernate ID, if using Hibernate.
-
setId
Sets the Hibernate ID. Should be used with caution.- Parameters:
id
- the Hibernate ID, if using Hibernate.
-