Class ASPRule

  • All Implemented Interfaces:
    Comparable<ASPRule>, net.sf.tweety.commons.Formula, net.sf.tweety.commons.util.rules.Rule<ASPHead,​ASPBodyElement>, net.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula, net.sf.tweety.logics.commons.syntax.interfaces.LogicStructure, net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula

    public class ASPRule
    extends ASPElement
    implements net.sf.tweety.commons.util.rules.Rule<ASPHead,​ASPBodyElement>, Comparable<ASPRule>
    This class models a rule in ASP. A rule consists of a head and a body. The head contains n>=0 classical atoms and the body contains n>=0 literals. Rules with non-empty heads and empty bodies are called facts, rules with empty heads and non-empty bodies are called constraints.
    Author:
    Anna Gessler, Tim Janus, Thomas Vengels
    • Constructor Detail

      • ASPRule

        public ASPRule()
        Empty constructor
      • ASPRule

        public ASPRule​(ASPHead head)
        Creates a fact with the given ASPHead.
        Parameters:
        head - an ASPHead
      • ASPRule

        public ASPRule​(ASPLiteral literal)
        Creates a fact with the given literal.
        Parameters:
        literal - a literal
      • ASPRule

        public ASPRule​(ASPHead head,
                       List<ASPBodyElement> body)
        Creates a rule with the given head and body.
        Parameters:
        head - an ASPHead
        body - a list of ASPBodyElement
      • ASPRule

        public ASPRule​(ASPLiteral head,
                       ASPBodyElement b)
        Creates a rule with the given head and a single-element body.
        Parameters:
        head - an ASPLiteral
        b - a body element
      • ASPRule

        public ASPRule​(ASPLiteral head,
                       List<ASPBodyElement> body)
        Creates a rule with the given head and body.
        Parameters:
        head - an ASPLiteral
        body - a list of ASPBodyElement
      • ASPRule

        public ASPRule​(List<ASPBodyElement> body)
        Creates a constraint with the given body.
        Parameters:
        body - a list of ASPBodyElement
      • ASPRule

        public ASPRule​(List<ASPBodyElement> nafliterals,
                       net.sf.tweety.logics.commons.syntax.interfaces.Term<?> weight,
                       List<net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> terms)
        Creates a constraint with the given weight and terms.
        Parameters:
        nafliterals - the naf literals
        weight - some weight
        terms - a list of terms
      • ASPRule

        public ASPRule​(List<ASPBodyElement> body,
                       net.sf.tweety.logics.commons.syntax.interfaces.Term<?> weight,
                       net.sf.tweety.logics.commons.syntax.interfaces.Term<?> level,
                       List<net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> terms)
        Creates a constraint with the given weight, level and terms.
        Parameters:
        body - a list of ASPBodyElement
        weight - a term
        level - a term
        terms - a list of terms
      • ASPRule

        public ASPRule​(ASPRule other)
        Copy-Constructor
        Parameters:
        other - another ASPRule
    • Method Detail

      • isSafe

        public Boolean isSafe()
        This methods tests a rule for safety. Safety is defined as follows in the ASP-Core-2 standard: A rule, weak constraint or query is safe, if the set V of global variables
        Returns:
        true if the rule is safe, false otherwise
      • isFact

        public boolean isFact()
        Specified by:
        isFact in interface net.sf.tweety.commons.util.rules.Rule<ASPHead,​ASPBodyElement>
      • isConstraint

        public boolean isConstraint()
        Specified by:
        isConstraint in interface net.sf.tweety.commons.util.rules.Rule<ASPHead,​ASPBodyElement>
      • getSignature

        public net.sf.tweety.logics.fol.syntax.FolSignature getSignature()
        Specified by:
        getSignature in interface net.sf.tweety.commons.Formula
        Specified by:
        getSignature in interface net.sf.tweety.commons.util.rules.Rule<ASPHead,​ASPBodyElement>
        Specified by:
        getSignature in class ASPElement
      • setConclusion

        public void setConclusion​(ASPHead conclusion)
        Specified by:
        setConclusion in interface net.sf.tweety.commons.util.rules.Rule<ASPHead,​ASPBodyElement>
      • setConclusion

        public void setConclusion​(ASPLiteral head)
      • getConclusion

        public ASPHead getConclusion()
        Specified by:
        getConclusion in interface net.sf.tweety.commons.util.rules.Rule<ASPHead,​ASPBodyElement>
      • getWeight

        public net.sf.tweety.logics.commons.syntax.interfaces.Term<?> getWeight()
      • setWeight

        public void setWeight​(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> weight)
      • getLevel

        public net.sf.tweety.logics.commons.syntax.interfaces.Term<?> getLevel()
      • setLevel

        public void setLevel​(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> level)
      • getHead

        public ASPHead getHead()
      • setHead

        public void setHead​(ASPHead head)
      • addToHead

        public void addToHead​(ASPLiteral h)
      • getConstraintTerms

        public List<net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> getConstraintTerms()
      • isGround

        public boolean isGround()
        Specified by:
        isGround in interface net.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula
        Overrides:
        isGround in class ASPElement
      • substitute

        public ASPRule substitute​(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v,
                                  net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t)
        Specified by:
        substitute in interface net.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula
        Specified by:
        substitute in class ASPElement
      • exchange

        public ASPRule exchange​(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v,
                                net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t)
        Specified by:
        exchange in interface net.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula
        Overrides:
        exchange in class ASPElement
      • isLiteral

        public boolean isLiteral()
        Specified by:
        isLiteral in interface net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
      • getTerms

        public Set<net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> getTerms()
        Specified by:
        getTerms in interface net.sf.tweety.logics.commons.syntax.interfaces.LogicStructure
      • getTerms

        public <C extends net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> Set<C> getTerms​(Class<C> cls)
        Specified by:
        getTerms in interface net.sf.tweety.logics.commons.syntax.interfaces.LogicStructure
      • getPredicates

        public Set<net.sf.tweety.logics.commons.syntax.Predicate> getPredicates()
        Specified by:
        getPredicates in interface net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
        Specified by:
        getPredicates in class ASPElement
      • getAtoms

        public Set<ASPAtom> getAtoms()
        Specified by:
        getAtoms in interface net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
        Specified by:
        getAtoms in class ASPElement
      • clone

        public ASPRule clone()
        Specified by:
        clone in interface net.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula
        Specified by:
        clone in interface net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
        Specified by:
        clone in class ASPElement
      • equals

        public boolean equals​(Object other)
        Specified by:
        equals in interface net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
        Overrides:
        hashCode in class Object
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if the rule's head and body are both empty, false otherwise.