Package openllet.core

Class KnowledgeBaseImpl

    • Field Detail

      • _logger

        public static final java.util.logging.Logger _logger
      • _timers

        public final Timers _timers
        Timers used in various different parts of KB. There may be many different _timers created here depending on the level of debugging or application requirements. However, there are three major timers that are guaranteed to exist.
        • main - This is the main timer that exists in any Timers objects. All the other _timers defined in here will have this timer as its dependant so setting a timeout on this timer will put a limit on every operation done inside KB.
        • preprocessing - This is the operation where TBox creation, absorbtion and normalization is done. It also includes computing hierarchy of properties in RBox and merging the _individuals in ABox if there are explicit sameAs assertions.
        • consistency - This is the timer for ABox consistency check. Putting a timeout will mean that any single consistency check should be completed in a certain amount of time.
    • Constructor Detail

      • KnowledgeBaseImpl

        public KnowledgeBaseImpl()
    • Method Detail

      • getAnnotations

        public java.util.Map<openllet.aterm.ATermAppl,​java.util.Map<openllet.aterm.ATermAppl,​java.util.Set<openllet.aterm.ATermAppl>>> getAnnotations()
        Specified by:
        getAnnotations in interface Base
      • getInstances

        public java.util.Map<openllet.aterm.ATermAppl,​java.util.Set<openllet.aterm.ATermAppl>> getInstances()
        Specified by:
        getInstances in interface Base
      • getLogger

        public java.util.logging.Logger getLogger()
        Specified by:
        getLogger in interface openllet.shared.tools.Logging
      • copy

        public KnowledgeBase copy​(boolean emptyABox)
        Create a copy of this KB. Depending on the value of emptyABox either a completely new copy of ABox will be created or the new KB will have an empty ABox. If emptyABox parameter is true but the original KB contains nominals in its RBox or TBox the new KB will have the definition of those _individuals (but not ) In either case, the new KB will point to the same RBox and TBox so changing one KB's RBox or TBox will affect other.
        Specified by:
        copy in interface KnowledgeBase
        Parameters:
        emptyABox - If true ABox is not copied to the new KB
        Returns:
        A copy of this KB
      • addClass

        public void addClass​(openllet.aterm.ATermAppl c)
        Specified by:
        addClass in interface KnowledgeBase
      • addSubClass

        public void addSubClass​(openllet.aterm.ATermAppl sub,
                                openllet.aterm.ATermAppl sup)
        Specified by:
        addSubClass in interface KnowledgeBase
      • addEquivalentClass

        public void addEquivalentClass​(openllet.aterm.ATermAppl c1,
                                       openllet.aterm.ATermAppl c2)
        Specified by:
        addEquivalentClass in interface KnowledgeBase
      • addKey

        public void addKey​(openllet.aterm.ATermAppl c,
                           java.util.Set<openllet.aterm.ATermAppl> properties)
        Specified by:
        addKey in interface KnowledgeBase
      • addDisjointClasses

        public void addDisjointClasses​(java.util.List<openllet.aterm.ATermAppl> classes)
        Specified by:
        addDisjointClasses in interface KnowledgeBase
      • addDisjointClass

        public void addDisjointClass​(openllet.aterm.ATermAppl c1,
                                     openllet.aterm.ATermAppl c2)
        Specified by:
        addDisjointClass in interface KnowledgeBase
      • addComplementClass

        public void addComplementClass​(openllet.aterm.ATermAppl c1,
                                       openllet.aterm.ATermAppl c2)
        Specified by:
        addComplementClass in interface KnowledgeBase
      • addType

        public void addType​(openllet.aterm.ATermAppl i,
                            openllet.aterm.ATermAppl c)
        Specified by:
        addType in interface KnowledgeBase
      • addSame

        public void addSame​(openllet.aterm.ATermAppl i1,
                            openllet.aterm.ATermAppl i2)
        Specified by:
        addSame in interface KnowledgeBase
      • addAllDifferent

        public void addAllDifferent​(openllet.aterm.ATermList list)
        Specified by:
        addAllDifferent in interface KnowledgeBase
      • addDifferent

        public void addDifferent​(openllet.aterm.ATermAppl i1,
                                 openllet.aterm.ATermAppl i2)
        Specified by:
        addDifferent in interface KnowledgeBase
      • addObjectPropertyValue

        @Deprecated
        public void addObjectPropertyValue​(openllet.aterm.ATermAppl p,
                                           openllet.aterm.ATermAppl s,
                                           openllet.aterm.ATermAppl o)
        Deprecated.
        2.5.1 Use addPropertyValue instead
        Parameters:
        p -
        s -
        o -
      • addPropertyValue

        public boolean addPropertyValue​(openllet.aterm.ATermAppl p,
                                        openllet.aterm.ATermAppl s,
                                        openllet.aterm.ATermAppl o)
        Specified by:
        addPropertyValue in interface KnowledgeBase
      • addNegatedPropertyValue

        public boolean addNegatedPropertyValue​(openllet.aterm.ATermAppl p,
                                               openllet.aterm.ATermAppl s,
                                               openllet.aterm.ATermAppl o)
        Specified by:
        addNegatedPropertyValue in interface KnowledgeBase
      • addProperty

        public void addProperty​(openllet.aterm.ATermAppl p)
        Specified by:
        addProperty in interface KnowledgeBase
      • addObjectProperty

        public boolean addObjectProperty​(openllet.aterm.ATerm p)
        Add a new object property. If property was earlier defined to be a datatype property then this function will simply return without changing the KB.
        Specified by:
        addObjectProperty in interface KnowledgeBase
        Parameters:
        p - Name of the property
        Returns:
        True if property is added, false if not
      • addDatatypeProperty

        public boolean addDatatypeProperty​(openllet.aterm.ATerm p)
        Add a new object property. If property was earlier defined to be a datatype property then this function will simply return without changing the KB.
        Specified by:
        addDatatypeProperty in interface KnowledgeBase
        Parameters:
        p -
        Returns:
        True if property is added, false if not
      • addOntologyProperty

        @Deprecated
        public void addOntologyProperty​(openllet.aterm.ATermAppl p)
        Deprecated.
      • addAnnotation

        public boolean addAnnotation​(openllet.aterm.ATermAppl s,
                                     openllet.aterm.ATermAppl p,
                                     openllet.aterm.ATermAppl o)
        Specified by:
        addAnnotation in interface KnowledgeBase
      • isAnnotation

        public boolean isAnnotation​(openllet.aterm.ATermAppl s,
                                    openllet.aterm.ATermAppl p,
                                    openllet.aterm.ATermAppl o)
        Specified by:
        isAnnotation in interface KnowledgeBase
      • addDomain

        public void addDomain​(openllet.aterm.ATerm p,
                              openllet.aterm.ATermAppl c)
        Specified by:
        addDomain in interface KnowledgeBase
      • addDomain

        public void addDomain​(openllet.aterm.ATerm p,
                              openllet.aterm.ATermAppl c,
                              java.util.Set<openllet.aterm.ATermAppl> explain)
        For internal use when domain axioms come from TBox absorption
        Specified by:
        addDomain in interface KnowledgeBase
      • addRange

        public void addRange​(openllet.aterm.ATerm p,
                             openllet.aterm.ATermAppl c)
        Specified by:
        addRange in interface KnowledgeBase
      • addRange

        public void addRange​(openllet.aterm.ATerm p,
                             openllet.aterm.ATermAppl c,
                             java.util.Set<openllet.aterm.ATermAppl> explain)
        For internal use when range axioms come from TBox absorption
        Specified by:
        addRange in interface KnowledgeBase
      • addDatatype

        public void addDatatype​(openllet.aterm.ATermAppl p)
        Specified by:
        addDatatype in interface KnowledgeBase
      • addDatatypeDefinition

        public boolean addDatatypeDefinition​(openllet.aterm.ATermAppl name,
                                             openllet.aterm.ATermAppl datarange)
        Adds a new datatype defined to be equivalent to the given data range expression.
        Specified by:
        addDatatypeDefinition in interface KnowledgeBase
        Parameters:
        name - name of the datatype
        datarange - a data range expression
        Returns:
        true if the add success
      • removeDomain

        public boolean removeDomain​(openllet.aterm.ATerm p,
                                    openllet.aterm.ATermAppl c)
        Removes (if possible) the given property domain axiom from the KB and return true if removal was successful. See also addDomain(ATerm, ATermAppl).
        Specified by:
        removeDomain in interface KnowledgeBase
        Parameters:
        p - Property in domain axiom
        c - Class in domain axiom
        Returns:
        true if axiom is removed, false if removal failed
      • removePropertyValue

        public boolean removePropertyValue​(openllet.aterm.ATermAppl p,
                                           openllet.aterm.ATermAppl i1,
                                           openllet.aterm.ATermAppl i2)
        Specified by:
        removePropertyValue in interface KnowledgeBase
      • removeRange

        public boolean removeRange​(openllet.aterm.ATerm p,
                                   openllet.aterm.ATermAppl c)
        Removes (if possible) the given property range axiom from the KB and return true if removal was successful. See also addRange(ATerm, ATermAppl).
        Specified by:
        removeRange in interface KnowledgeBase
        Parameters:
        p - Property in range axiom
        c - Class or datatype in range axiom
        Returns:
        true if axiom is removed, false if removal failed
      • removeType

        public boolean removeType​(openllet.aterm.ATermAppl ind,
                                  openllet.aterm.ATermAppl c)
        Specified by:
        removeType in interface KnowledgeBase
      • removeAxiom

        public boolean removeAxiom​(openllet.aterm.ATermAppl axiom)
        Removes (if possible) the given TBox axiom from the KB and return true if removal was successful.
        Specified by:
        removeAxiom in interface KnowledgeBase
        Parameters:
        axiom - TBox axiom to remove
        Returns:
        true if axiom is removed, false if removal failed
      • prepare

        public void prepare()
        Specified by:
        prepare in interface Base
      • updateExpressivity

        public void updateExpressivity​(openllet.aterm.ATermAppl i,
                                       openllet.aterm.ATermAppl c)
        This method is used for incremental reasoning. We do not want to recompute the expressivity from scratch.
        Parameters:
        i -
        c -
      • getInfo

        public java.lang.String getInfo()
      • isConsistencyDone

        public boolean isConsistencyDone()
        Returns true if the consistency check has been done and nothing in the KB has changed after that.
        Specified by:
        isConsistencyDone in interface KnowledgeBase
        Returns:
        true if the consistency check has been done and nothing in the KB has changed after that.
      • isClassified

        public boolean isClassified()
        Returns true if the classification check has been done and nothing in the KB has changed after that.
        Specified by:
        isClassified in interface Base
        Returns:
        true if the classification check has been done and nothing in the KB has changed after that.
      • isRealized

        public boolean isRealized()
        Specified by:
        isRealized in interface Base
      • isChanged

        public boolean isChanged()
      • isTBoxChanged

        public boolean isTBoxChanged()
      • isRBoxChanged

        public boolean isRBoxChanged()
      • isABoxChanged

        public boolean isABoxChanged()
      • getUnsatisfiableClasses

        public java.util.Set<openllet.aterm.ATermAppl> getUnsatisfiableClasses()
        Returns all unsatisfiable classes in the KB excluding the BOTTOM concept. The result may be empty if there is no user-defined concept in the KB that is unsatisfiable.
        Specified by:
        getUnsatisfiableClasses in interface KnowledgeBase
        Returns:
        all unsatisfiable classes in the KB excluding the BOTTOM concept
      • getAllUnsatisfiableClasses

        public java.util.Set<openllet.aterm.ATermAppl> getAllUnsatisfiableClasses()
        Returns all unsatisfiable classes in the KB including the BOTTOM concept. Since BOTTOM concept is built-in the result will always have at least one element.
        Specified by:
        getAllUnsatisfiableClasses in interface KnowledgeBase
        Returns:
        all unsatisfiable classes in the KB including the BOTTOM concept
      • getToldDisjoints

        public java.util.Map<openllet.aterm.ATermAppl,​java.util.Set<openllet.aterm.ATermAppl>> getToldDisjoints()
        Specified by:
        getToldDisjoints in interface KnowledgeBase
      • ensureConsistency

        public void ensureConsistency()
        Specified by:
        ensureConsistency in interface Base
      • classify

        public void classify()
        Specified by:
        classify in interface Base
      • realize

        public void realize()
        Specified by:
        realize in interface Base
      • currentIndividuals

        public java.util.Set<openllet.aterm.ATermAppl> currentIndividuals()
        Specified by:
        currentIndividuals in interface PropertiesBase
        Returns:
        the actual set individuals.
      • getIndividuals

        public java.util.Set<openllet.aterm.ATermAppl> getIndividuals()
        Specified by:
        getIndividuals in interface Base
        Returns:
        the set of all _individuals. Returned set is unmodifiable!
      • getIndividualsCount

        public int getIndividualsCount()
        Specified by:
        getIndividualsCount in interface KnowledgeBase
        Returns:
        the total number of individuals in kb.
      • individuals

        public java.util.stream.Stream<openllet.aterm.ATermAppl> individuals()
        Specified by:
        individuals in interface KnowledgeBase
        Returns:
        all individuals.
      • isSatisfiable

        public boolean isSatisfiable​(openllet.aterm.ATermAppl c)
        Specified by:
        isSatisfiable in interface Base
      • hasInstance

        public boolean hasInstance​(openllet.aterm.ATerm d)
        Specified by:
        hasInstance in interface KnowledgeBase
        Parameters:
        d -
        Returns:
        true if there is at least one named individual that belongs to the given class
      • isSameAs

        public boolean isSameAs​(openllet.aterm.ATermAppl t1,
                                openllet.aterm.ATermAppl t2)
        Specified by:
        isSameAs in interface KnowledgeBase
      • isDifferentFrom

        public boolean isDifferentFrom​(openllet.aterm.ATermAppl t1,
                                       openllet.aterm.ATermAppl t2)
        Specified by:
        isDifferentFrom in interface KnowledgeBase
      • getDifferents

        public java.util.Set<openllet.aterm.ATermAppl> getDifferents​(openllet.aterm.ATermAppl name)
        Specified by:
        getDifferents in interface KnowledgeBase
      • hasPropertyValue

        public boolean hasPropertyValue​(openllet.aterm.ATermAppl s,
                                        openllet.aterm.ATermAppl p,
                                        openllet.aterm.ATermAppl o)
        Specified by:
        hasPropertyValue in interface KnowledgeBase
      • hasKnownPropertyValue

        public Bool hasKnownPropertyValue​(openllet.aterm.ATermAppl s,
                                          openllet.aterm.ATermAppl p,
                                          openllet.aterm.ATermAppl o)
        Description copied from interface: KnowledgeBase
        Answers the hasPropertyValue question without doing any satisfiability check. It might return Boolean.TRUE, Boolean.FALSE, or null (unknown). If the null value is returned hasPropertyValue function needs to be called to get the answer.
        Specified by:
        hasKnownPropertyValue in interface KnowledgeBase
        Parameters:
        s - Subject
        p - Predicate
        o - Object (null can be used as wildcard)
        Returns:
        true if the hasPropertyValue question without doing any satisfiability check.
      • getDisjoints

        public java.util.Set<java.util.Set<openllet.aterm.ATermAppl>> getDisjoints​(openllet.aterm.ATermAppl c)
      • getDisjointProperties

        public java.util.Set<java.util.Set<openllet.aterm.ATermAppl>> getDisjointProperties​(openllet.aterm.ATermAppl p)
        Specified by:
        getDisjointProperties in interface KnowledgeBase
      • getDisjointProperties

        public java.util.Set<java.util.Set<openllet.aterm.ATermAppl>> getDisjointProperties​(openllet.aterm.ATermAppl p,
                                                                                            boolean direct)
      • getComplements

        public java.util.Set<openllet.aterm.ATermAppl> getComplements​(openllet.aterm.ATermAppl c)
        Specified by:
        getComplements in interface KnowledgeBase
      • getSames

        public java.util.Set<openllet.aterm.ATermAppl> getSames​(openllet.aterm.ATermAppl name)
        Specified by:
        getSames in interface KnowledgeBase
        Returns:
        all the individuals asserted to be equal to the given individual but not the the individual itself.
      • printClassTree

        public void printClassTree​(java.io.PrintWriter out)
      • setDoDependencyAxioms

        @Deprecated
        public void setDoDependencyAxioms​(boolean doDepAxioms)
        Deprecated.
        Use setDoExplanation instead
        Parameters:
        doDepAxioms -
      • getDoDependencyAxioms

        @Deprecated
        public boolean getDoDependencyAxioms()
        Deprecated.
        Use getExplanation instead
        Returns:
        DO NOT USE
      • chooseStrategy

        public CompletionStrategy chooseStrategy​(ABox abox,
                                                 Expressivity expressivity)
        Choose a completion strategy based on the expressivity of the KB. The _abox given is not necessarily the ABox that belongs to this KB but can be a derivative.
        Specified by:
        chooseStrategy in interface KnowledgeBase
        Returns:
        the completion strategy choosen
      • setTimeout

        public void setTimeout​(long timeout)
        Set a timeout for the main timer. Used to stop an automated test after a reasonable amount of time has passed.
        Specified by:
        setTimeout in interface KnowledgeBase
        Parameters:
        timeout -
      • getTaxonomy

        public Taxonomy<openllet.aterm.ATermAppl> getTaxonomy()
        Get the classification results.
        Specified by:
        getTaxonomy in interface KnowledgeBase
        Returns:
        the classification results.
      • addRule

        public boolean addRule​(Rule rule)
        Add a rule to the KB.
        Specified by:
        addRule in interface KnowledgeBase
        Returns:
        true if the add success
      • getRules

        public java.util.Set<Rule> getRules()
        Return all the asserted rules.
        Specified by:
        getRules in interface KnowledgeBase
        Returns:
        all the asserted rules.
      • getNormalizedRules

        public java.util.Map<Rule,​Rule> getNormalizedRules()
        Return the asserted rules with their normalized form. A normalized rule is a rule where any class expression occurring in the rules is in normalized form.
        Specified by:
        getNormalizedRules in interface KnowledgeBase
        Returns:
        set of rules where
      • ensureIncConsistency

        public void ensureIncConsistency​(boolean aboxDeletion)
      • getSyntacticAssertions

        public java.util.Set<openllet.aterm.ATermAppl> getSyntacticAssertions()
        Specified by:
        getSyntacticAssertions in interface KnowledgeBase
        Returns:
        syntactic assertions in the kb
      • getDeletedAssertions

        public java.util.Set<openllet.aterm.ATermAppl> getDeletedAssertions()
        Specified by:
        getDeletedAssertions in interface KnowledgeBase
        Returns:
        the deletedAssertions
      • isExplainOnlyInconsistency

        public boolean isExplainOnlyInconsistency()
        Returns _current value of explainOnlyInconsistency option.
        Returns:
        current value of explainOnlyInconsistency option
        See Also:
        setExplainOnlyInconsistency(boolean)
      • setExplainOnlyInconsistency

        public void setExplainOnlyInconsistency​(boolean explainOnlyInconsistency)
        Controls what kind of explanations can be generated using this KB. With this option enabled explanations for inconsistent ontologies will be returned. But if the ontology is _consistent, it will not be possible to retrieve explanations for inferences about _instances. This option is disabled by default. It should be turned on if explanations are only needed for inconsistencies but not other inferences. Turning this option on improves the performance of consistency checking for _consistent ontologies.
        Parameters:
        explainOnlyInconsistency - new value for _explainOnlyInconsistency option