Package net.sf.tweety.lp.asp.syntax
Class ASPHead
- java.lang.Object
-
- net.sf.tweety.lp.asp.syntax.ASPElement
-
- net.sf.tweety.lp.asp.syntax.ASPHead
-
- All Implemented Interfaces:
java.lang.Iterable<ASPLiteral>,java.util.Collection<ASPLiteral>,java.util.List<ASPLiteral>,Formula,AssociativeFormulaSupport.AssociativeSupportBridge,AssociativeFormula<ASPLiteral>,ComplexLogicalFormula,Disjunctable,LogicStructure,SimpleLogicalFormula
public class ASPHead extends ASPElement implements AssociativeFormula<ASPLiteral>, Disjunctable, AssociativeFormulaSupport.AssociativeSupportBridge
This formula represents the head of an disjunctive rule which is a disjunction of literals.- Author:
- Tim Janus, Anna Gessler
-
-
Field Summary
Fields Modifier and Type Field Description private AssociativeFormulaSupport<ASPLiteral>assocSupport
-
Constructor Summary
Constructors Constructor Description ASPHead()Empty Constructor.ASPHead(java.util.List<ASPLiteral> head_elements)Creates a new head with the given elements.ASPHead(ASPHead other)Copy-ConstructorASPHead(ASPLiteral head)Creates a new head with a single element.
-
Method Summary
Modifier and Type Method Description voidadd(int index, ASPLiteral element)booleanadd(ASPLiteral e)booleanaddAll(int index, java.util.Collection<? extends ASPLiteral> c)booleanaddAll(java.util.Collection<? extends ASPLiteral> c)voidclear()ASPHeadclone()Creates a deep copy of this formulaSimpleLogicalFormulacombineWithOr(Disjunctable f)booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)<C extends Term<?>>
booleancontainsTermsOfType(java.lang.Class<C> cls)Checks if this logical structure contains at least one term of type C.ASPHeadcreateEmptyFormula()FolSignaturecreateEmptySignature()booleanequals(java.lang.Object other)ASPHeadexchange(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.ASPLiteralget(int index)java.util.Set<ASPAtom>getAtoms()Processes the set of all atoms which appear in this formulajava.lang.StringgetEmptySymbol()java.util.List<ASPLiteral>getFormulas()<C extends SimpleLogicalFormula>
java.util.Set<C>getFormulas(java.lang.Class<C> cls)Process the formulas of type C that are children of this associative formulajava.util.SortedSet<ASPLiteral>getLiterals()Returns all literals in this element in form of a SortedSet.java.lang.StringgetOperatorSymbol()java.lang.Class<? extends Predicate>getPredicateCls()java.util.Set<Predicate>getPredicates()Processes the set of all predicates which appear in this formulaFolSignaturegetSignature()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.inthashCode()intindexOf(java.lang.Object o)booleanisEmpty()booleanisGround()Checks whether this formula is ground, i.e.booleanisLiteral()booleanisWellFormed()Checks if this formula is well formed in the logical langauge.java.util.Iterator<ASPLiteral>iterator()intlastIndexOf(java.lang.Object o)java.util.ListIterator<ASPLiteral>listIterator()java.util.ListIterator<ASPLiteral>listIterator(int index)ASPLiteralremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)ASPLiteralset(int index, ASPLiteral element)intsize()java.util.List<ASPLiteral>subList(int fromIndex, int toIndex)ASPHeadsubstitute(java.util.Map<? extends Term<?>,? extends Term<?>> map)Substitutes all occurrences of all terms "v" in map.keyset() in this formula by map.get(v) and returns the new formula.ASPHeadsubstitute(Term<?> t, Term<?> v)Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()
-
-
-
Field Detail
-
assocSupport
private AssociativeFormulaSupport<ASPLiteral> assocSupport
-
-
Constructor Detail
-
ASPHead
public ASPHead()
Empty Constructor.
-
ASPHead
public ASPHead(java.util.List<ASPLiteral> head_elements)
Creates a new head with the given elements.- Parameters:
head_elements- list of literals
-
ASPHead
public ASPHead(ASPLiteral head)
Creates a new head with a single element.- Parameters:
head- an ASP literal
-
ASPHead
public ASPHead(ASPHead other)
Copy-Constructor- Parameters:
other- another ASPHead
-
-
Method Detail
-
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.
-
isWellFormed
public boolean isWellFormed()
Description copied from interface:ComplexLogicalFormulaChecks if this formula is well formed in the logical langauge. What well- formed means is highly language dependent and the documentation of implementing sub classes shall describe the well formed term for the language they model.- Specified by:
isWellFormedin interfaceComplexLogicalFormula- Overrides:
isWellFormedin classASPElement- Returns:
- true if the formula is well-formed, false otherwise
-
getPredicateCls
public java.lang.Class<? extends Predicate> getPredicateCls()
- Specified by:
getPredicateClsin interfaceSimpleLogicalFormula- Overrides:
getPredicateClsin classASPElement- Returns:
- The class description of the predicate used by this formula.
-
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
-
containsTermsOfType
public <C extends Term<?>> boolean containsTermsOfType(java.lang.Class<C> cls)
Description copied from interface:LogicStructureChecks if this logical structure contains at least one term of type C. This method is a shortcut for !getTerms(TermImplementation.class).isEmpty().- Specified by:
containsTermsOfTypein interfaceLogicStructure- Overrides:
containsTermsOfTypein classASPElement- Type Parameters:
C- the type of terms- Parameters:
cls- The class structure representing the type C of the term.- Returns:
- True if this logical structure contains at least one term of type C or false otherwise.
-
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
-
substitute
public ASPHead substitute(Term<?> t, Term<?> v)
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:
t- the term to be substituted.v- the term to substitute.- Returns:
- a formula where every occurrence of "v" is replaced by "t".
-
getSignature
public FolSignature getSignature()
Description copied from interface:FormulaReturns the signature of the language of this formula.- Specified by:
getSignaturein interfaceFormula- Specified by:
getSignaturein classASPElement- Returns:
- the signature of the language of this formula.
-
clone
public ASPHead 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
-
add
public boolean add(ASPLiteral e)
- Specified by:
addin interfacejava.util.Collection<ASPLiteral>- Specified by:
addin interfacejava.util.List<ASPLiteral>
-
add
public void add(int index, ASPLiteral element)- Specified by:
addin interfacejava.util.List<ASPLiteral>
-
addAll
public boolean addAll(java.util.Collection<? extends ASPLiteral> c)
- Specified by:
addAllin interfacejava.util.Collection<ASPLiteral>- Specified by:
addAllin interfacejava.util.List<ASPLiteral>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends ASPLiteral> c)- Specified by:
addAllin interfacejava.util.List<ASPLiteral>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<ASPLiteral>- Specified by:
clearin interfacejava.util.List<ASPLiteral>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<ASPLiteral>- Specified by:
containsin interfacejava.util.List<ASPLiteral>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<ASPLiteral>- Specified by:
containsAllin interfacejava.util.List<ASPLiteral>
-
get
public ASPLiteral get(int index)
- Specified by:
getin interfacejava.util.List<ASPLiteral>
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfacejava.util.List<ASPLiteral>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<ASPLiteral>- Specified by:
isEmptyin interfacejava.util.List<ASPLiteral>
-
iterator
public java.util.Iterator<ASPLiteral> iterator()
- Specified by:
iteratorin interfacejava.util.Collection<ASPLiteral>- Specified by:
iteratorin interfacejava.lang.Iterable<ASPLiteral>- Specified by:
iteratorin interfacejava.util.List<ASPLiteral>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfacejava.util.List<ASPLiteral>
-
listIterator
public java.util.ListIterator<ASPLiteral> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<ASPLiteral>
-
listIterator
public java.util.ListIterator<ASPLiteral> listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List<ASPLiteral>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<ASPLiteral>- Specified by:
removein interfacejava.util.List<ASPLiteral>
-
remove
public ASPLiteral remove(int index)
- Specified by:
removein interfacejava.util.List<ASPLiteral>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<ASPLiteral>- Specified by:
removeAllin interfacejava.util.List<ASPLiteral>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<ASPLiteral>- Specified by:
retainAllin interfacejava.util.List<ASPLiteral>
-
set
public ASPLiteral set(int index, ASPLiteral element)
- Specified by:
setin interfacejava.util.List<ASPLiteral>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<ASPLiteral>- Specified by:
sizein interfacejava.util.List<ASPLiteral>
-
subList
public java.util.List<ASPLiteral> subList(int fromIndex, int toIndex)
- Specified by:
subListin interfacejava.util.List<ASPLiteral>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<ASPLiteral>- Specified by:
toArrayin interfacejava.util.List<ASPLiteral>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<ASPLiteral>- Specified by:
toArrayin interfacejava.util.List<ASPLiteral>
-
getFormulas
public java.util.List<ASPLiteral> getFormulas()
- Specified by:
getFormulasin interfaceAssociativeFormula<ASPLiteral>- Returns:
- all the formulas saved as childs in the associative formula
-
getFormulas
public <C extends SimpleLogicalFormula> java.util.Set<C> getFormulas(java.lang.Class<C> cls)
Description copied from interface:AssociativeFormulaProcess the formulas of type C that are children of this associative formula- Specified by:
getFormulasin interfaceAssociativeFormula<ASPLiteral>- Type Parameters:
C- the type of formulas- Parameters:
cls- the class structure defining the type of formulas which are searched.- Returns:
- A set of formulas of type C which are members of the associative formula
-
createEmptyFormula
public ASPHead createEmptyFormula()
- Specified by:
createEmptyFormulain interfaceAssociativeFormulaSupport.AssociativeSupportBridge- Returns:
- an empty version of the AssociativeFormula
-
createEmptySignature
public FolSignature createEmptySignature()
- Specified by:
createEmptySignaturein interfaceAssociativeFormulaSupport.AssociativeSupportBridge- Returns:
- An empty signature of the language of the AssociativeFormula implementation
-
getOperatorSymbol
public java.lang.String getOperatorSymbol()
- Specified by:
getOperatorSymbolin interfaceAssociativeFormulaSupport.AssociativeSupportBridge- Returns:
- A String representing the operator which connects two items of the associative formula.
-
getEmptySymbol
public java.lang.String getEmptySymbol()
- Specified by:
getEmptySymbolin interfaceAssociativeFormulaSupport.AssociativeSupportBridge- Returns:
- A String representing an empty version of the Associative Formula implementation
-
combineWithOr
public SimpleLogicalFormula combineWithOr(Disjunctable f)
- Specified by:
combineWithOrin interfaceDisjunctable- Parameters:
f- a formula to be combined with OR and this.- Returns:
- a disjunction of this and the given formula.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
substitute
public ASPHead substitute(java.util.Map<? extends Term<?>,? extends Term<?>> map) throws java.lang.IllegalArgumentException
Description copied from interface:ComplexLogicalFormulaSubstitutes all occurrences of all terms "v" in map.keyset() in this formula by map.get(v) and returns the new formula.- Specified by:
substitutein interfaceComplexLogicalFormula- Overrides:
substitutein classASPElement- Parameters:
map- a mapping defining which terms to be substituted.- Returns:
- a formula where every term in map.keyset() has been replaced by map.get(v).
- Throws:
java.lang.IllegalArgumentException- if any term and its mapping are of different sorts
-
exchange
public ASPHead exchange(Term<?> v, Term<?> t) throws java.lang.IllegalArgumentException
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.
- Throws:
java.lang.IllegalArgumentException- if "v" and "t" are of different sorts
-
getLiterals
public java.util.SortedSet<ASPLiteral> getLiterals()
Returns all literals in this element in form of a SortedSet. Literals are atoms or strict negations of atoms.- Returns:
- all the literals used in the rule element
-
equals
public boolean equals(java.lang.Object other)
- Specified by:
equalsin interfacejava.util.Collection<ASPLiteral>- Specified by:
equalsin interfacejava.util.List<ASPLiteral>- Specified by:
equalsin interfaceSimpleLogicalFormula- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<ASPLiteral>- Specified by:
hashCodein interfacejava.util.List<ASPLiteral>- Specified by:
hashCodein interfaceSimpleLogicalFormula- Overrides:
hashCodein classjava.lang.Object
-
-