Package org.tweetyproject.lp.asp.syntax
Class ClassicalHead
java.lang.Object
org.tweetyproject.lp.asp.syntax.ASPElement
org.tweetyproject.lp.asp.syntax.ASPHead
org.tweetyproject.lp.asp.syntax.ClassicalHead
- All Implemented Interfaces:
Iterable<ASPLiteral>,Collection<ASPLiteral>,List<ASPLiteral>,SequencedCollection<ASPLiteral>,Formula,AssociativeFormulaSupport.AssociativeSupportBridge,AssociativeFormula<ASPLiteral>,ComplexLogicalFormula,Disjunctable,LogicStructure,SimpleLogicalFormula
public class ClassicalHead
extends ASPHead
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
ConstructorsConstructorDescriptionEmpty Constructor.ClassicalHead(List<ASPLiteral> headElements) Creates a new head with the given elements.ClassicalHead(ASPLiteral head) Creates a new head with a single element.ClassicalHead(ClassicalHead other) Copy-Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int index, ASPLiteral element) booleanadd(ASPLiteral e) booleanadd(ASPLiteral... formulas) Adds the specified elements to the end of this collection (optional operation).booleanaddAll(int index, Collection<? extends ASPLiteral> c) booleanaddAll(Collection<? extends ASPLiteral> c) voidclear()clone()Creates a deep copy of this formulabooleanbooleancontainsAll(Collection<?> c) <C extends Term<?>>
booleancontainsTermsOfType(Class<C> cls) Checks if this logical structure contains at least one term of type C.booleanSubstitutes 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.get(int index) getAtoms()Processes the set of all atoms which appear in this formula<C extends SimpleLogicalFormula>
Set<C> getFormulas(Class<C> cls) Process the formulas of type C that are children of this associative formulaReturns all literals in this element in form of a SortedSet.Processes the set of all predicates which appear in this formulaReturns the signature of the language of this formula.getTerms()Processes the set containing all terms of type C.inthashCode()intbooleanisEmpty()Return true if the head is empty, false otherwisebooleanisGround()Checks whether this formula is ground, i.e.booleanbooleanChecks if this formula is well formed in the logical langauge.iterator()intlistIterator(int index) Returns a representation of this ASP element in clingo (potassco) syntax.Returns a representation of this ASP element in DLV syntax.remove(int index) booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) set(int index, ASPLiteral element) intsize()subList(int fromIndex, int toIndex) substitute(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.substitute(Term<?> t, Term<?> v) Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.Object[]toArray()<T> T[]toArray(T[] a) toString()Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, replaceAll, reversed, sort, spliterator
-
Constructor Details
-
ClassicalHead
public ClassicalHead()Empty Constructor. -
ClassicalHead
Creates a new head with the given elements.- Parameters:
headElements- list of literals
-
ClassicalHead
Creates a new head with a single element.- Parameters:
head- an ASP literal
-
ClassicalHead
-
-
Method Details
-
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
- 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
- Specified by:
getTermsin interfaceLogicStructure- Returns:
- a set containing all terms of this logical structure
-
getTerms
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
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
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
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
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
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
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
- Specified by:
addin interfaceCollection<ASPLiteral>- Specified by:
addin interfaceList<ASPLiteral>
-
add
- Specified by:
addin interfaceList<ASPLiteral>
-
addAll
- Specified by:
addAllin interfaceCollection<ASPLiteral>- Specified by:
addAllin interfaceList<ASPLiteral>
-
addAll
- Specified by:
addAllin interfaceList<ASPLiteral>
-
add
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:
clearin interfaceCollection<ASPLiteral>- Specified by:
clearin interfaceList<ASPLiteral>
-
contains
- Specified by:
containsin interfaceCollection<ASPLiteral>- Specified by:
containsin interfaceList<ASPLiteral>
-
containsAll
- Specified by:
containsAllin interfaceCollection<ASPLiteral>- Specified by:
containsAllin interfaceList<ASPLiteral>
-
get
- Specified by:
getin interfaceList<ASPLiteral>
-
indexOf
- Specified by:
indexOfin interfaceList<ASPLiteral>
-
isEmpty
public boolean isEmpty()Description copied from class:ASPHeadReturn true if the head is empty, false otherwise- Specified by:
isEmptyin interfaceCollection<ASPLiteral>- Specified by:
isEmptyin interfaceList<ASPLiteral>- Specified by:
isEmptyin classASPHead- Returns:
- true if the head is empty, false otherwise
-
iterator
- Specified by:
iteratorin interfaceCollection<ASPLiteral>- Specified by:
iteratorin interfaceIterable<ASPLiteral>- Specified by:
iteratorin interfaceList<ASPLiteral>
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<ASPLiteral>
-
listIterator
- Specified by:
listIteratorin interfaceList<ASPLiteral>
-
listIterator
- Specified by:
listIteratorin interfaceList<ASPLiteral>
-
remove
- Specified by:
removein interfaceCollection<ASPLiteral>- Specified by:
removein interfaceList<ASPLiteral>
-
remove
- Specified by:
removein interfaceList<ASPLiteral>
-
removeAll
- Specified by:
removeAllin interfaceCollection<ASPLiteral>- Specified by:
removeAllin interfaceList<ASPLiteral>
-
retainAll
- Specified by:
retainAllin interfaceCollection<ASPLiteral>- Specified by:
retainAllin interfaceList<ASPLiteral>
-
set
- Specified by:
setin interfaceList<ASPLiteral>
-
size
public int size()- Specified by:
sizein interfaceCollection<ASPLiteral>- Specified by:
sizein interfaceList<ASPLiteral>
-
subList
- Specified by:
subListin interfaceList<ASPLiteral>
-
toArray
- Specified by:
toArrayin interfaceCollection<ASPLiteral>- Specified by:
toArrayin interfaceList<ASPLiteral>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<ASPLiteral>- Specified by:
toArrayin interfaceList<ASPLiteral>
-
getFormulas
- Specified by:
getFormulasin interfaceAssociativeFormula<ASPLiteral>- Returns:
- all the formulas saved as childs in the associative formula
-
getFormulas
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
- Specified by:
createEmptyFormulain interfaceAssociativeFormulaSupport.AssociativeSupportBridge- Returns:
- an empty version of the AssociativeFormula
-
createEmptySignature
- Specified by:
createEmptySignaturein interfaceAssociativeFormulaSupport.AssociativeSupportBridge- Returns:
- An empty signature of the language of the AssociativeFormula implementation
-
getOperatorSymbol
- Specified by:
getOperatorSymbolin interfaceAssociativeFormulaSupport.AssociativeSupportBridge- Returns:
- A String representing the operator which connects two items of the associative formula.
-
getEmptySymbol
- Specified by:
getEmptySymbolin interfaceAssociativeFormulaSupport.AssociativeSupportBridge- Returns:
- A String representing an empty version of the Associative Formula implementation
-
combineWithOr
- Specified by:
combineWithOrin interfaceDisjunctable- Parameters:
f- a formula to be combined with OR and this.- Returns:
- a disjunction of this and the given formula.
-
substitute
public ClassicalHead substitute(Map<? extends Term<?>, ? extends Term<?>> map) throws IllegalArgumentExceptionDescription 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:
IllegalArgumentException- if any term and its mapping are of different sorts
-
exchange
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:
IllegalArgumentException- if "v" and "t" are of different sorts
-
getLiterals
Returns all literals in this element in form of a SortedSet. Literals are atoms or strict negations of atoms.- Specified by:
getLiteralsin classASPHead- Returns:
- all the literals used in the rule element
-
equals
- Specified by:
equalsin interfaceCollection<ASPLiteral>- Specified by:
equalsin interfaceList<ASPLiteral>- Specified by:
equalsin interfaceSimpleLogicalFormula- Overrides:
equalsin classObject
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<ASPLiteral>- Specified by:
hashCodein interfaceList<ASPLiteral>- Specified by:
hashCodein interfaceSimpleLogicalFormula- Overrides:
hashCodein classObject
-
toString
-
printToClingo
Description copied from class:ASPElementReturns a representation of this ASP element in clingo (potassco) syntax. See https://potassco.org/ for more information.- Overrides:
printToClingoin classASPElement- Returns:
- String representation in clingo syntax
-
printToDLV
Description copied from class:ASPElementReturns a representation of this ASP element in DLV syntax. See http://www.dlvsystem.com/html/DLV_User_Manual.html for more information.- Overrides:
printToDLVin classASPElement- Returns:
- String representation in DLV syntax
-