Class SimpleComparableOntology

    • 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.
    • Method Detail

      • equals

        public boolean equals​(Object obj)
        Ontologies are equal if their names are equal.
        Overrides:
        equals 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
        Returns:
        true is contained
      • 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 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

        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 interface ComparableOntology
        Parameters:
        term - the term to look for.
        Returns:
        the ComparableTerm representing that term in this ontology.
      • 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 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:
        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 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:
        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 interface Ontology
        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 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:
        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 interface ComparableOntology
        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 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:
        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 interface ComparableOntology
        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 interface ComparableOntology
        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 interface Ontology
        Returns:
        true if contained
        See Also:
        ComparableTerm, ComparableTriple
      • 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.