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
-
-
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 void
add(int index, ASPLiteral element)
boolean
add(ASPLiteral e)
boolean
add(ASPLiteral... formulas)
Adds the specified elements to the end of this collection (optional operation).boolean
addAll(int index, java.util.Collection<? extends ASPLiteral> c)
boolean
addAll(java.util.Collection<? extends ASPLiteral> c)
void
clear()
ASPHead
clone()
Creates a deep copy of this formulaSimpleLogicalFormula
combineWithOr(Disjunctable f)
boolean
contains(java.lang.Object o)
boolean
containsAll(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.ASPHead
createEmptyFormula()
FolSignature
createEmptySignature()
boolean
equals(java.lang.Object other)
ASPHead
exchange(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.ASPLiteral
get(int index)
java.util.Set<ASPAtom>
getAtoms()
Processes the set of all atoms which appear in this formulajava.lang.String
getEmptySymbol()
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.String
getOperatorSymbol()
java.lang.Class<? extends Predicate>
getPredicateCls()
java.util.Set<Predicate>
getPredicates()
Processes the set of all predicates which appear in this formulaFolSignature
getSignature()
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.int
hashCode()
int
indexOf(java.lang.Object o)
boolean
isEmpty()
boolean
isGround()
Checks whether this formula is ground, i.e.boolean
isLiteral()
boolean
isWellFormed()
Checks if this formula is well formed in the logical langauge.java.util.Iterator<ASPLiteral>
iterator()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<ASPLiteral>
listIterator()
java.util.ListIterator<ASPLiteral>
listIterator(int index)
ASPLiteral
remove(int index)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
retainAll(java.util.Collection<?> c)
ASPLiteral
set(int index, ASPLiteral element)
int
size()
java.util.List<ASPLiteral>
subList(int fromIndex, int toIndex)
ASPHead
substitute(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.ASPHead
substitute(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.String
toString()
-
-
-
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:ComplexLogicalFormula
Checks whether this formula is ground, i.e. whether there appears no variable in this formula.- Specified by:
isGround
in interfaceComplexLogicalFormula
- Overrides:
isGround
in classASPElement
- Returns:
- "true" if this formula is ground.
-
isWellFormed
public boolean isWellFormed()
Description copied from interface:ComplexLogicalFormula
Checks 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:
isWellFormed
in interfaceComplexLogicalFormula
- Overrides:
isWellFormed
in classASPElement
- Returns:
- true if the formula is well-formed, false otherwise
-
getPredicateCls
public java.lang.Class<? extends Predicate> getPredicateCls()
- Specified by:
getPredicateCls
in interfaceSimpleLogicalFormula
- Overrides:
getPredicateCls
in classASPElement
- Returns:
- The class description of the predicate used by this formula.
-
isLiteral
public boolean isLiteral()
- Specified by:
isLiteral
in interfaceSimpleLogicalFormula
- Returns:
- true if the formula represents a literal in the language or false otherwise
-
getTerms
public java.util.Set<Term<?>> getTerms()
- Specified by:
getTerms
in 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:LogicStructure
Processes 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:
getTerms
in 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:LogicStructure
Checks if this logical structure contains at least one term of type C. This method is a shortcut for !getTerms(TermImplementation.class).isEmpty().- Specified by:
containsTermsOfType
in interfaceLogicStructure
- Overrides:
containsTermsOfType
in 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:SimpleLogicalFormula
Processes the set of all predicates which appear in this formula- Specified by:
getPredicates
in interfaceSimpleLogicalFormula
- Specified by:
getPredicates
in classASPElement
- Returns:
- all predicates that appear in this formula
-
getAtoms
public java.util.Set<ASPAtom> getAtoms()
Description copied from interface:SimpleLogicalFormula
Processes the set of all atoms which appear in this formula- Specified by:
getAtoms
in interfaceSimpleLogicalFormula
- Specified by:
getAtoms
in classASPElement
- Returns:
- The set of all atoms
-
substitute
public ASPHead substitute(Term<?> t, Term<?> v)
Description copied from interface:ComplexLogicalFormula
Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.- Specified by:
substitute
in interfaceComplexLogicalFormula
- Specified by:
substitute
in 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:Formula
Returns the signature of the language of this formula.- Specified by:
getSignature
in interfaceFormula
- Specified by:
getSignature
in classASPElement
- Returns:
- the signature of the language of this formula.
-
clone
public ASPHead clone()
Description copied from interface:SimpleLogicalFormula
Creates a deep copy of this formula- Specified by:
clone
in interfaceComplexLogicalFormula
- Specified by:
clone
in interfaceSimpleLogicalFormula
- Specified by:
clone
in classASPElement
- Returns:
- the cloned formula
-
add
public boolean add(ASPLiteral e)
- Specified by:
add
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
add
in interfacejava.util.List<ASPLiteral>
-
add
public void add(int index, ASPLiteral element)
- Specified by:
add
in interfacejava.util.List<ASPLiteral>
-
addAll
public boolean addAll(java.util.Collection<? extends ASPLiteral> c)
- Specified by:
addAll
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
addAll
in interfacejava.util.List<ASPLiteral>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends ASPLiteral> c)
- Specified by:
addAll
in interfacejava.util.List<ASPLiteral>
-
add
public boolean add(ASPLiteral... formulas)
Adds the specified elements to the end of this collection (optional operation).- Parameters:
formulas
- to be appended to collection- Returns:
- true if all elements were added, false otherwise
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
clear
in interfacejava.util.List<ASPLiteral>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
contains
in interfacejava.util.List<ASPLiteral>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
containsAll
in interfacejava.util.List<ASPLiteral>
-
get
public ASPLiteral get(int index)
- Specified by:
get
in interfacejava.util.List<ASPLiteral>
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOf
in interfacejava.util.List<ASPLiteral>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
isEmpty
in interfacejava.util.List<ASPLiteral>
-
iterator
public java.util.Iterator<ASPLiteral> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
iterator
in interfacejava.lang.Iterable<ASPLiteral>
- Specified by:
iterator
in interfacejava.util.List<ASPLiteral>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<ASPLiteral>
-
listIterator
public java.util.ListIterator<ASPLiteral> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<ASPLiteral>
-
listIterator
public java.util.ListIterator<ASPLiteral> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<ASPLiteral>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
remove
in interfacejava.util.List<ASPLiteral>
-
remove
public ASPLiteral remove(int index)
- Specified by:
remove
in interfacejava.util.List<ASPLiteral>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAll
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
removeAll
in interfacejava.util.List<ASPLiteral>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAll
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
retainAll
in interfacejava.util.List<ASPLiteral>
-
set
public ASPLiteral set(int index, ASPLiteral element)
- Specified by:
set
in interfacejava.util.List<ASPLiteral>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
size
in interfacejava.util.List<ASPLiteral>
-
subList
public java.util.List<ASPLiteral> subList(int fromIndex, int toIndex)
- Specified by:
subList
in interfacejava.util.List<ASPLiteral>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
toArray
in interfacejava.util.List<ASPLiteral>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
toArray
in interfacejava.util.List<ASPLiteral>
-
getFormulas
public java.util.List<ASPLiteral> getFormulas()
- Specified by:
getFormulas
in 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:AssociativeFormula
Process the formulas of type C that are children of this associative formula- Specified by:
getFormulas
in 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:
createEmptyFormula
in interfaceAssociativeFormulaSupport.AssociativeSupportBridge
- Returns:
- an empty version of the AssociativeFormula
-
createEmptySignature
public FolSignature createEmptySignature()
- Specified by:
createEmptySignature
in interfaceAssociativeFormulaSupport.AssociativeSupportBridge
- Returns:
- An empty signature of the language of the AssociativeFormula implementation
-
getOperatorSymbol
public java.lang.String getOperatorSymbol()
- Specified by:
getOperatorSymbol
in interfaceAssociativeFormulaSupport.AssociativeSupportBridge
- Returns:
- A String representing the operator which connects two items of the associative formula.
-
getEmptySymbol
public java.lang.String getEmptySymbol()
- Specified by:
getEmptySymbol
in interfaceAssociativeFormulaSupport.AssociativeSupportBridge
- Returns:
- A String representing an empty version of the Associative Formula implementation
-
combineWithOr
public SimpleLogicalFormula combineWithOr(Disjunctable f)
- Specified by:
combineWithOr
in 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:
toString
in classjava.lang.Object
-
substitute
public ASPHead substitute(java.util.Map<? extends Term<?>,? extends Term<?>> map) throws java.lang.IllegalArgumentException
Description copied from interface:ComplexLogicalFormula
Substitutes all occurrences of all terms "v" in map.keyset() in this formula by map.get(v) and returns the new formula.- Specified by:
substitute
in interfaceComplexLogicalFormula
- Overrides:
substitute
in 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:ComplexLogicalFormula
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.- Specified by:
exchange
in interfaceComplexLogicalFormula
- Overrides:
exchange
in 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:
equals
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
equals
in interfacejava.util.List<ASPLiteral>
- Specified by:
equals
in interfaceSimpleLogicalFormula
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<ASPLiteral>
- Specified by:
hashCode
in interfacejava.util.List<ASPLiteral>
- Specified by:
hashCode
in interfaceSimpleLogicalFormula
- Overrides:
hashCode
in classjava.lang.Object
-
-