Package org.biojavax.ontology
Class SimpleComparableOntology
- java.lang.Object
-
- org.biojava.utils.AbstractChangeable
-
- org.biojavax.ontology.SimpleComparableOntology
-
- All Implemented Interfaces:
Comparable
,Ontology
,Changeable
,ComparableOntology
public class SimpleComparableOntology extends AbstractChangeable implements 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
Constructors Modifier Constructor Description protected
SimpleComparableOntology()
SimpleComparableOntology(String name)
Creates a new instance of SimpleComparableOntology with the given, immutable, non-nullable name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Object o)
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 ontologyTerm
createTerm(String name)
Create a new term in this ontology.Term
createTerm(String name, String description)
Create a new term in this ontology.Term
createTerm(String name, String description, Object[] synonyms)
Create a new term in this ontology.Triple
createTriple(Term subject, Term object, Term predicate, String name, String description)
Creates a new Triple.Variable
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
equals(Object obj)
Ontologies are equal if their names are equal.String
getDescription()
Return a human-readable description of this ontology.Integer
getId()
Gets the Hibernate ID.String
getName()
Return the name of this ontologyOntologyOps
getOps()
Return the associated OntologyOps.ComparableTerm
getOrCreateTerm(String name)
Looks for a term with the given name and returns it.ComparableTriple
getOrCreateTriple(Term subject, Term object, Term predicate)
Looks for a triple with the given subject object and predicate and returns it.ComparableTerm
getOrImportTerm(Term term)
Looks for a term with the same name as the given term and returns it.Term
getTerm(String s)
Fetch the term with the specified name.Set
getTerms()
Return all the terms in this ontologySet
getTermSet()
Returns the set of terms in this ontology.Set
getTriples(Term subject, Term object, Term predicate)
Return all triples from this ontology which match the supplied pattern.Set
getTripleSet()
Returns the set of triples in this ontology.int
hashCode()
Term
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
setId(Integer id)
Sets the Hibernate ID.void
setName(String name)
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.String
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 Detail
-
SimpleComparableOntology
public SimpleComparableOntology(String name)
Creates a new instance of SimpleComparableOntology with the given, immutable, non-nullable name.- Parameters:
name
- the name of the ontology.
-
SimpleComparableOntology
protected SimpleComparableOntology()
-
-
Method Detail
-
compareTo
public int compareTo(Object o)
Ontologies are compared only by name.- Specified by:
compareTo
in interfaceComparable
-
containsTerm
public boolean containsTerm(String name)
Determines if this ontology currently contains a term namedname
- Specified by:
containsTerm
in interfaceOntology
- Returns:
- true is contained
-
getTerm
public Term getTerm(String s) throws NoSuchElementException
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
public ComparableTerm getOrCreateTerm(String name)
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
public ComparableTriple getOrCreateTriple(Term subject, Term object, Term predicate)
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
public ComparableTerm getOrImportTerm(Term term)
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:
ComparableTerm
-
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:
ComparableTerm
-
deleteTerm
public void deleteTerm(Term t) throws ChangeVetoException
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
- Throws:
ChangeVetoException
- See Also:
ComparableTerm
-
getTriples
public Set getTriples(Term subject, Term object, Term predicate)
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:
ComparableTerm
,ComparableTriple
-
setTripleSet
public void setTripleSet(Set triples) throws ChangeVetoException
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:
ComparableTriple
-
getTripleSet
public Set 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
public Set 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.- Specified by:
getTerms
in interfaceOntology
- Returns:
- a Set of all Terms of the ontology.
- See Also:
ComparableTerm
-
setTermSet
public void setTermSet(Set terms) throws ChangeVetoException
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:
ComparableTerm
-
getTermSet
public Set 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:
ComparableTerm
-
containsTriple
public boolean containsTriple(Term subject, Term object, Term predicate)
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
- Returns:
- true if contained
- See Also:
ComparableTerm
,ComparableTriple
-
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
public String getDescription()
Return a human-readable description of this ontology.- Specified by:
getDescription
in interfaceComparableOntology
- Specified by:
getDescription
in interfaceOntology
- Returns:
- the description.
-
setDescription
public void setDescription(String description) throws ChangeVetoException
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.
-
setName
public void setName(String name)
Description copied from interface:Ontology
Set the name for this ontology
-
getOps
public OntologyOps 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
public Integer getId()
Gets the Hibernate ID. Should be used with caution.- Returns:
- the Hibernate ID, if using Hibernate.
-
-