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:
java.lang.Comparable<ASPRule>,Formula,Rule<ASPHead,ASPBodyElement>,ComplexLogicalFormula,LogicStructure,SimpleLogicalFormula
public class ASPRule extends ASPElement implements Rule<ASPHead,ASPBodyElement>, java.lang.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
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ASPBodyElement>bodyThe body (premise) of a rule.private java.util.List<Term<?>>constraint_termsprivate ASPHeadheadThe head (conclusion) of a rule.private Term<?>levelprivate Term<?>weightAdditional attributes that can be used for weak constraints (rules with empty heads).
-
Constructor Summary
Constructors Constructor Description ASPRule()Empty constructorASPRule(java.util.List<ASPBodyElement> body)Creates a constraint with the given body.ASPRule(java.util.List<ASPBodyElement> nafliterals, Term<?> weight, java.util.List<Term<?>> terms)Creates a constraint with the given weight and terms.ASPRule(java.util.List<ASPBodyElement> body, Term<?> weight, Term<?> level, java.util.List<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, java.util.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, java.util.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(java.util.Collection<? extends ASPBodyElement> premises)voidaddToHead(ASPLiteral h)ASPRuleclone()Creates a deep copy of this formulaintcompareTo(ASPRule arg0)booleanequals(java.lang.Object other)ASPRuleexchange(Term<?> v, Term<?> t)Substitutes all occurrences of term "v" in this formula by term "t" and at the same time replaces all occurrences of term "t" by term "v" and eventually returns the new formula.java.util.Set<ASPAtom>getAtoms()Processes the set of all atoms which appear in this formulajava.util.List<ASPBodyElement>getBody()ASPHeadgetConclusion()Returns the conclusion of this rule.java.util.List<Term<?>>getConstraintTerms()ASPHeadgetHead()Term<?>getLevel()java.util.Collection<? extends ASPLiteral>getLiterals()java.util.Set<Predicate>getPredicates()Processes the set of all predicates which appear in this formulajava.util.List<ASPBodyElement>getPremise()Returns the premise of this rule.FolSignaturegetSignature()Returns the signature of the language of this formula.java.util.Set<Term<?>>getTerms()<C extends Term<?>>
java.util.Set<C>getTerms(java.lang.Class<C> cls)Processes the set containing all terms of type C.Term<?>getWeight()inthashCode()booleanisConstraint()booleanisEmpty()booleanisFact()booleanisGround()Checks whether this formula is ground, i.e.booleanisLiteral()java.lang.BooleanisSafe()This methods tests a rule for safety.voidsetBody(java.util.List<ASPBodyElement> body)voidsetConclusion(ASPHead conclusion)voidsetConclusion(ASPLiteral head)voidsetHead(ASPHead head)voidsetLevel(Term<?> level)voidsetWeight(Term<?> weight)ASPRulesubstitute(Term<?> v, Term<?> t)Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.java.lang.StringtoString()-
Methods inherited from class net.sf.tweety.lp.asp.syntax.ASPElement
containsTermsOfType, getPredicateCls, isWellFormed, substitute
-
-
-
-
Field Detail
-
head
private ASPHead head
The head (conclusion) of a rule. Consists of a disjunction of atoms.
-
body
private java.util.List<ASPBodyElement> body
The body (premise) of a rule. Consists of literals.
-
weight
private Term<?> weight
Additional attributes that can be used for weak constraints (rules with empty heads).
-
level
private Term<?> level
-
constraint_terms
private java.util.List<Term<?>> constraint_terms
-
-
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, java.util.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, java.util.List<ASPBodyElement> body)
Creates a rule with the given head and body.- Parameters:
head- an ASPLiteralbody- a list of ASPBodyElement
-
ASPRule
public ASPRule(java.util.List<ASPBodyElement> body)
Creates a constraint with the given body.- Parameters:
body- a list of ASPBodyElement
-
ASPRule
public ASPRule(java.util.List<ASPBodyElement> nafliterals, Term<?> weight, java.util.List<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(java.util.List<ASPBodyElement> body, Term<?> weight, Term<?> level, java.util.List<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 java.lang.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 interfaceRule<ASPHead,ASPBodyElement>
-
isConstraint
public boolean isConstraint()
- Specified by:
isConstraintin interfaceRule<ASPHead,ASPBodyElement>
-
addPremises
public void addPremises(java.util.Collection<? extends ASPBodyElement> premises)
- Specified by:
addPremisesin interfaceRule<ASPHead,ASPBodyElement>
-
getSignature
public FolSignature getSignature()
Description copied from interface:FormulaReturns the signature of the language of this formula.- Specified by:
getSignaturein interfaceFormula- Specified by:
getSignaturein interfaceRule<ASPHead,ASPBodyElement>- Specified by:
getSignaturein classASPElement- Returns:
- the signature of the language of this formula.
-
setConclusion
public void setConclusion(ASPHead conclusion)
- Specified by:
setConclusionin interfaceRule<ASPHead,ASPBodyElement>
-
setConclusion
public void setConclusion(ASPLiteral head)
-
addPremise
public void addPremise(ASPBodyElement premise)
- Specified by:
addPremisein interfaceRule<ASPHead,ASPBodyElement>
-
getPremise
public java.util.List<ASPBodyElement> getPremise()
Description copied from interface:RuleReturns the premise of this rule.- Specified by:
getPremisein interfaceRule<ASPHead,ASPBodyElement>- Returns:
- the premise of this rule.
-
getConclusion
public ASPHead getConclusion()
Description copied from interface:RuleReturns the conclusion of this rule.- Specified by:
getConclusionin interfaceRule<ASPHead,ASPBodyElement>- Returns:
- the conclusion of this rule.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getWeight
public Term<?> getWeight()
-
setWeight
public void setWeight(Term<?> weight)
-
getLevel
public Term<?> getLevel()
-
setLevel
public void setLevel(Term<?> level)
-
getHead
public ASPHead getHead()
-
setHead
public void setHead(ASPHead head)
-
addToHead
public void addToHead(ASPLiteral h)
-
getBody
public java.util.List<ASPBodyElement> getBody()
-
setBody
public void setBody(java.util.List<ASPBodyElement> body)
-
getConstraintTerms
public java.util.List<Term<?>> getConstraintTerms()
-
isGround
public boolean isGround()
Description copied from interface:ComplexLogicalFormulaChecks whether this formula is ground, i.e. whether there appears no variable in this formula.- Specified by:
isGroundin interfaceComplexLogicalFormula- Overrides:
isGroundin classASPElement- Returns:
- "true" if this formula is ground.
-
compareTo
public int compareTo(ASPRule arg0)
- Specified by:
compareToin interfacejava.lang.Comparable<ASPRule>
-
getLiterals
public java.util.Collection<? extends ASPLiteral> getLiterals()
-
substitute
public ASPRule substitute(Term<?> v, Term<?> t)
Description copied from interface:ComplexLogicalFormulaSubstitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.- Specified by:
substitutein interfaceComplexLogicalFormula- Specified by:
substitutein classASPElement- Parameters:
v- the term to be substituted.t- the term to substitute.- Returns:
- a formula where every occurrence of "v" is replaced by "t".
-
exchange
public ASPRule exchange(Term<?> v, Term<?> t)
Description copied from interface:ComplexLogicalFormulaSubstitutes all occurrences of term "v" in this formula by term "t" and at the same time replaces all occurrences of term "t" by term "v" and eventually returns the new formula.- Specified by:
exchangein interfaceComplexLogicalFormula- Overrides:
exchangein classASPElement- Parameters:
v- a term.t- a term.- Returns:
- a new logical formula with both "v" and "t" exchanged.
-
isLiteral
public boolean isLiteral()
- Specified by:
isLiteralin interfaceSimpleLogicalFormula- Returns:
- true if the formula represents a literal in the language or false otherwise
-
getTerms
public java.util.Set<Term<?>> getTerms()
- Specified by:
getTermsin interfaceLogicStructure- Returns:
- a set containing all terms of this logical structure
-
getTerms
public <C extends Term<?>> java.util.Set<C> getTerms(java.lang.Class<C> cls)
Description copied from interface:LogicStructureProcesses the set containing all terms of type C. This method uses the equals method of the given Class and therefore does not add terms which are sub classes of type C to the set.- Specified by:
getTermsin interfaceLogicStructure- Type Parameters:
C- the type of terms- Parameters:
cls- The Class structure containing type information about the searched term- Returns:
- A set containing all terms of type C of this logical structure
-
getPredicates
public java.util.Set<Predicate> getPredicates()
Description copied from interface:SimpleLogicalFormulaProcesses the set of all predicates which appear in this formula- Specified by:
getPredicatesin interfaceSimpleLogicalFormula- Specified by:
getPredicatesin classASPElement- Returns:
- all predicates that appear in this formula
-
getAtoms
public java.util.Set<ASPAtom> getAtoms()
Description copied from interface:SimpleLogicalFormulaProcesses the set of all atoms which appear in this formula- Specified by:
getAtomsin interfaceSimpleLogicalFormula- Specified by:
getAtomsin classASPElement- Returns:
- The set of all atoms
-
clone
public ASPRule clone()
Description copied from interface:SimpleLogicalFormulaCreates a deep copy of this formula- Specified by:
clonein interfaceComplexLogicalFormula- Specified by:
clonein interfaceSimpleLogicalFormula- Specified by:
clonein classASPElement- Returns:
- the cloned formula
-
equals
public boolean equals(java.lang.Object other)
- Specified by:
equalsin interfaceSimpleLogicalFormula- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceSimpleLogicalFormula- Overrides:
hashCodein classjava.lang.Object
-
isEmpty
public boolean isEmpty()
- Returns:
- true if the rule's head and body are both empty, false otherwise.
-
-