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
ConstructorDescriptionEmpty 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 TypeMethodDescriptionvoid
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, Collection<? extends ASPLiteral> c) boolean
addAll
(Collection<? extends ASPLiteral> c) void
clear()
clone()
Creates a deep copy of this formulaboolean
boolean
containsAll
(Collection<?> c) <C extends Term<?>>
booleancontainsTermsOfType
(Class<C> cls) Checks if this logical structure contains at least one term of type C.boolean
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.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.int
hashCode()
int
boolean
isEmpty()
Return true if the head is empty, false otherwiseboolean
isGround()
Checks whether this formula is ground, i.e.boolean
boolean
Checks if this formula is well formed in the logical langauge.iterator()
int
listIterator
(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) boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) set
(int index, ASPLiteral element) int
size()
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, toArray
Methods 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: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
- 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
- Specified by:
getTerms
in interfaceLogicStructure
- Returns:
- a set containing all terms of this logical structure
-
getTerms
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
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
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
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
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
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
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
- Specified by:
add
in interfaceCollection<ASPLiteral>
- Specified by:
add
in interfaceList<ASPLiteral>
-
add
- Specified by:
add
in interfaceList<ASPLiteral>
-
addAll
- Specified by:
addAll
in interfaceCollection<ASPLiteral>
- Specified by:
addAll
in interfaceList<ASPLiteral>
-
addAll
- Specified by:
addAll
in 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:
clear
in interfaceCollection<ASPLiteral>
- Specified by:
clear
in interfaceList<ASPLiteral>
-
contains
- Specified by:
contains
in interfaceCollection<ASPLiteral>
- Specified by:
contains
in interfaceList<ASPLiteral>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<ASPLiteral>
- Specified by:
containsAll
in interfaceList<ASPLiteral>
-
get
- Specified by:
get
in interfaceList<ASPLiteral>
-
indexOf
- Specified by:
indexOf
in interfaceList<ASPLiteral>
-
isEmpty
public boolean isEmpty()Description copied from class:ASPHead
Return true if the head is empty, false otherwise- Specified by:
isEmpty
in interfaceCollection<ASPLiteral>
- Specified by:
isEmpty
in interfaceList<ASPLiteral>
- Specified by:
isEmpty
in classASPHead
- Returns:
- true if the head is empty, false otherwise
-
iterator
- Specified by:
iterator
in interfaceCollection<ASPLiteral>
- Specified by:
iterator
in interfaceIterable<ASPLiteral>
- Specified by:
iterator
in interfaceList<ASPLiteral>
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<ASPLiteral>
-
listIterator
- Specified by:
listIterator
in interfaceList<ASPLiteral>
-
listIterator
- Specified by:
listIterator
in interfaceList<ASPLiteral>
-
remove
- Specified by:
remove
in interfaceCollection<ASPLiteral>
- Specified by:
remove
in interfaceList<ASPLiteral>
-
remove
- Specified by:
remove
in interfaceList<ASPLiteral>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<ASPLiteral>
- Specified by:
removeAll
in interfaceList<ASPLiteral>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<ASPLiteral>
- Specified by:
retainAll
in interfaceList<ASPLiteral>
-
set
- Specified by:
set
in interfaceList<ASPLiteral>
-
size
public int size()- Specified by:
size
in interfaceCollection<ASPLiteral>
- Specified by:
size
in interfaceList<ASPLiteral>
-
subList
- Specified by:
subList
in interfaceList<ASPLiteral>
-
toArray
- Specified by:
toArray
in interfaceCollection<ASPLiteral>
- Specified by:
toArray
in interfaceList<ASPLiteral>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<ASPLiteral>
- Specified by:
toArray
in interfaceList<ASPLiteral>
-
getFormulas
- Specified by:
getFormulas
in interfaceAssociativeFormula<ASPLiteral>
- Returns:
- all the formulas saved as childs in the associative formula
-
getFormulas
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
- Specified by:
createEmptyFormula
in interfaceAssociativeFormulaSupport.AssociativeSupportBridge
- Returns:
- an empty version of the AssociativeFormula
-
createEmptySignature
- Specified by:
createEmptySignature
in interfaceAssociativeFormulaSupport.AssociativeSupportBridge
- Returns:
- An empty signature of the language of the AssociativeFormula implementation
-
getOperatorSymbol
- Specified by:
getOperatorSymbol
in interfaceAssociativeFormulaSupport.AssociativeSupportBridge
- Returns:
- A String representing the operator which connects two items of the associative formula.
-
getEmptySymbol
- Specified by:
getEmptySymbol
in interfaceAssociativeFormulaSupport.AssociativeSupportBridge
- Returns:
- A String representing an empty version of the Associative Formula implementation
-
combineWithOr
- 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.
-
substitute
public ClassicalHead substitute(Map<? extends Term<?>, ? extends Term<?>> map) throws IllegalArgumentExceptionDescription 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:
IllegalArgumentException
- if any term and its mapping are of different sorts
-
exchange
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:
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:
getLiterals
in classASPHead
- Returns:
- all the literals used in the rule element
-
equals
- Specified by:
equals
in interfaceCollection<ASPLiteral>
- Specified by:
equals
in interfaceList<ASPLiteral>
- Specified by:
equals
in interfaceSimpleLogicalFormula
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<ASPLiteral>
- Specified by:
hashCode
in interfaceList<ASPLiteral>
- Specified by:
hashCode
in interfaceSimpleLogicalFormula
- Overrides:
hashCode
in classObject
-
toString
-
printToClingo
Description copied from class:ASPElement
Returns a representation of this ASP element in clingo (potassco) syntax. See https://potassco.org/ for more information.- Overrides:
printToClingo
in classASPElement
- Returns:
- String representation in clingo syntax
-
printToDLV
Description copied from class:ASPElement
Returns a representation of this ASP element in DLV syntax. See http://www.dlvsystem.com/html/DLV_User_Manual.html for more information.- Overrides:
printToDLV
in classASPElement
- Returns:
- String representation in DLV syntax
-