Package net.sf.tweety.lp.asp.syntax
Class ASPRule
- java.lang.Object
-
- net.sf.tweety.lp.asp.syntax.ASPElement
-
- net.sf.tweety.lp.asp.syntax.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 Summary
Constructors Constructor Description ASPRule()Empty constructorASPRule(List<ASPBodyElement> body)Creates a constraint with the given body.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.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.ASPRule(ASPHead head)Creates a fact with the given ASPHead.ASPRule(ASPHead head, List<ASPBodyElement> body)Creates a rule with the given head and body.ASPRule(ASPLiteral literal)Creates a fact with the given literal.ASPRule(ASPLiteral head, List<ASPBodyElement> body)Creates a rule with the given head and body.ASPRule(ASPLiteral head, ASPBodyElement b)Creates a rule with the given head and a single-element body.ASPRule(ASPRule other)Copy-Constructor
-
Method Summary
Modifier and Type Method Description voidaddPremise(ASPBodyElement premise)voidaddPremises(Collection<? extends ASPBodyElement> premises)voidaddToHead(ASPLiteral h)ASPRuleclone()intcompareTo(ASPRule arg0)booleanequals(Object other)ASPRuleexchange(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v, net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t)Set<ASPAtom>getAtoms()List<ASPBodyElement>getBody()ASPHeadgetConclusion()List<net.sf.tweety.logics.commons.syntax.interfaces.Term<?>>getConstraintTerms()ASPHeadgetHead()net.sf.tweety.logics.commons.syntax.interfaces.Term<?>getLevel()Collection<? extends ASPLiteral>getLiterals()Set<net.sf.tweety.logics.commons.syntax.Predicate>getPredicates()List<ASPBodyElement>getPremise()net.sf.tweety.logics.fol.syntax.FolSignaturegetSignature()Set<net.sf.tweety.logics.commons.syntax.interfaces.Term<?>>getTerms()<C extends net.sf.tweety.logics.commons.syntax.interfaces.Term<?>>
Set<C>getTerms(Class<C> cls)net.sf.tweety.logics.commons.syntax.interfaces.Term<?>getWeight()inthashCode()booleanisConstraint()booleanisEmpty()booleanisFact()booleanisGround()booleanisLiteral()BooleanisSafe()This methods tests a rule for safety.voidsetBody(List<ASPBodyElement> body)voidsetConclusion(ASPHead conclusion)voidsetConclusion(ASPLiteral head)voidsetHead(ASPHead head)voidsetLevel(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> level)voidsetWeight(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> weight)ASPRulesubstitute(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v, net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t)StringtoString()-
Methods inherited from class net.sf.tweety.lp.asp.syntax.ASPElement
containsTermsOfType, getPredicateCls, isWellFormed, substitute
-
-
-
-
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 ASPHeadbody- 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 ASPLiteralb- a body element
-
ASPRule
public ASPRule(ASPLiteral head, List<ASPBodyElement> body)
Creates a rule with the given head and body.- Parameters:
head- an ASPLiteralbody- 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 literalsweight- some weightterms- 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 ASPBodyElementweight- a termlevel- a termterms- 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:
isFactin interfacenet.sf.tweety.commons.util.rules.Rule<ASPHead,ASPBodyElement>
-
isConstraint
public boolean isConstraint()
- Specified by:
isConstraintin interfacenet.sf.tweety.commons.util.rules.Rule<ASPHead,ASPBodyElement>
-
addPremises
public void addPremises(Collection<? extends ASPBodyElement> premises)
- Specified by:
addPremisesin interfacenet.sf.tweety.commons.util.rules.Rule<ASPHead,ASPBodyElement>
-
getSignature
public net.sf.tweety.logics.fol.syntax.FolSignature getSignature()
- Specified by:
getSignaturein interfacenet.sf.tweety.commons.Formula- Specified by:
getSignaturein interfacenet.sf.tweety.commons.util.rules.Rule<ASPHead,ASPBodyElement>- Specified by:
getSignaturein classASPElement
-
setConclusion
public void setConclusion(ASPHead conclusion)
- Specified by:
setConclusionin interfacenet.sf.tweety.commons.util.rules.Rule<ASPHead,ASPBodyElement>
-
setConclusion
public void setConclusion(ASPLiteral head)
-
addPremise
public void addPremise(ASPBodyElement premise)
- Specified by:
addPremisein interfacenet.sf.tweety.commons.util.rules.Rule<ASPHead,ASPBodyElement>
-
getPremise
public List<ASPBodyElement> getPremise()
- Specified by:
getPremisein interfacenet.sf.tweety.commons.util.rules.Rule<ASPHead,ASPBodyElement>
-
getConclusion
public ASPHead getConclusion()
- Specified by:
getConclusionin interfacenet.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)
-
getBody
public List<ASPBodyElement> getBody()
-
setBody
public void setBody(List<ASPBodyElement> body)
-
getConstraintTerms
public List<net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> getConstraintTerms()
-
isGround
public boolean isGround()
- Specified by:
isGroundin interfacenet.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula- Overrides:
isGroundin classASPElement
-
compareTo
public int compareTo(ASPRule arg0)
- Specified by:
compareToin interfaceComparable<ASPRule>
-
getLiterals
public Collection<? extends ASPLiteral> getLiterals()
-
substitute
public ASPRule substitute(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v, net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t)
- Specified by:
substitutein interfacenet.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula- Specified by:
substitutein classASPElement
-
exchange
public ASPRule exchange(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v, net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t)
- Specified by:
exchangein interfacenet.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula- Overrides:
exchangein classASPElement
-
isLiteral
public boolean isLiteral()
- Specified by:
isLiteralin interfacenet.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
-
getTerms
public Set<net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> getTerms()
- Specified by:
getTermsin interfacenet.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:
getTermsin interfacenet.sf.tweety.logics.commons.syntax.interfaces.LogicStructure
-
getPredicates
public Set<net.sf.tweety.logics.commons.syntax.Predicate> getPredicates()
- Specified by:
getPredicatesin interfacenet.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula- Specified by:
getPredicatesin classASPElement
-
getAtoms
public Set<ASPAtom> getAtoms()
- Specified by:
getAtomsin interfacenet.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula- Specified by:
getAtomsin classASPElement
-
clone
public ASPRule clone()
- Specified by:
clonein interfacenet.sf.tweety.logics.commons.syntax.interfaces.ComplexLogicalFormula- Specified by:
clonein interfacenet.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula- Specified by:
clonein classASPElement
-
equals
public boolean equals(Object other)
-
hashCode
public int hashCode()
-
isEmpty
public boolean isEmpty()
- Returns:
- true if the rule's head and body are both empty, false otherwise.
-
-