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
  • Constructor Details

    • SimpleComparableOntology

      Creates a new instance of SimpleComparableOntology with the given, immutable, non-nullable name.
      Parameters:
      name - the name of the ontology.
    • SimpleComparableOntology

  • Method Details

    • compareTo

      public int compareTo(Object o)
      Ontologies are compared only by name.
      Specified by:
      compareTo in interface Comparable
    • equals

      public boolean equals(Object obj)
      Ontologies are equal if their names are equal.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Form: "name"
      Overrides:
      toString in class Object
    • containsTerm

      public boolean containsTerm(String name)
      Determines if this ontology currently contains a term named name
      Specified by:
      containsTerm in interface Ontology
      Parameters:
      name -
      Returns:
      true is contained
    • getTerm

      Fetch the term with the specified name.
      Specified by:
      getTerm in interface Ontology
      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 interface ComparableOntology
      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 interface ComparableOntology
      Parameters:
      subject - the subject of the triple eg apple
      object - the object of the triple eg fruit
      predicate - 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 interface ComparableOntology
      Parameters:
      term - the term to look for.
      Returns:
      the ComparableTerm representing that term in this ontology.
    • createTerm

      Create a new term in this ontology.
      Specified by:
      createTerm in interface Ontology
      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 exists
      ChangeVetoException
      IllegalArgumentException - if either name or description is null, or violates some other constraint of this implementation.
    • importTerm

      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 interface Ontology
      Parameters:
      t - the Term to import
      localName - 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 interface Ontology
      Parameters:
      subject - the subject Term
      object - the object Term
      predicate - the predicate Term
      name - the name of the triple, or null
      description - 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 description
      ChangeVetoException
      See Also:
    • 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 interface Ontology
      Parameters:
      t -
      Throws:
      ChangeVetoException
      See Also:
    • 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 are null, 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 interface Ontology
      Parameters:
      subject - The subject to search for, or null
      object - The object to search for, or null
      predicate - The relationship to search for, or null.
      Returns:
      a Set of triples
      See Also:
    • 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 interface ComparableOntology
      Parameters:
      triples - the set of ComparableTriple objects this ontology should have.
      Throws:
      ChangeVetoException - if any of them are unacceptable.
      See Also:
    • 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 interface ComparableOntology
      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 interface Ontology
      Returns:
      a Set of all Terms of the ontology.
      See Also:
    • 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 interface ComparableOntology
      Parameters:
      terms - a set of Term objects this ontology should have.
      Throws:
      ChangeVetoException - if any of them are unacceptable.
      See Also:
    • 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 interface ComparableOntology
      Returns:
      a set of ComparableTerm objects.
      See Also:
    • 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 interface Ontology
      Parameters:
      subject -
      object -
      predicate -
      Returns:
      true if contained
      See Also:
    • createTerm

      Create a new term in this ontology.
      Specified by:
      createTerm in interface Ontology
      Parameters:
      name - The name of the term (must be unique))
      Returns:
      The newly created term.
      Throws:
      AlreadyExistsException - if a term of this name already exists
      ChangeVetoException
      IllegalArgumentException - if either name or description is null, or violates some other constraint of this implementation.
    • createTerm

      Create a new term in this ontology.
      Specified by:
      createTerm in interface Ontology
      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 exists
      ChangeVetoException
      IllegalArgumentException - if either name or description is null, or violates some other constraint of this implementation.
    • createVariable

      Create a new term in this ontology that is used as a variable. NOT IMPLEMENTED
      Specified by:
      createVariable in interface Ontology
      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 exists
      ChangeVetoException
      IllegalArgumentException - if either name or description is null, or violates some other constraint of this implementation.
    • getDescription

      Return a human-readable description of this ontology.
      Specified by:
      getDescription in interface ComparableOntology
      Specified by:
      getDescription in interface Ontology
      Returns:
      the description.
    • setDescription

      public void setDescription(String description) throws ChangeVetoException
      Sets a human-readable description of this ontology.
      Specified by:
      setDescription in interface ComparableOntology
      Specified by:
      setDescription in interface Ontology
      Parameters:
      description - the description.
      Throws:
      ChangeVetoException - in case of problems.
    • getName

      public String getName()
      Return the name of this ontology
      Specified by:
      getName in interface Ontology
      Returns:
      the name of the ontology
    • setName

      public void setName(String name)
      Description copied from interface: Ontology
      Set the name for this ontology
      Specified by:
      setName in interface Ontology
      Parameters:
      name - - the name
    • 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.
      Specified by:
      getOps in interface Ontology
      Returns:
      the OntologyOps instance associated with this instance.
    • getId

      public Integer getId()
      Gets the Hibernate ID. Should be used with caution.
      Returns:
      the Hibernate ID, if using Hibernate.
    • setId

      public void setId(Integer id)
      Sets the Hibernate ID. Should be used with caution.
      Parameters:
      id - the Hibernate ID, if using Hibernate.