java.lang.Object
edu.upc.fib.inlab.imp.kse.logics.logicschema.domain.Literal
edu.upc.fib.inlab.imp.kse.logics.logicschema.domain.OrdinaryLiteral

public class OrdinaryLiteral extends Literal
Implementation of a logic OrdinaryLiteral. E.g. "not(Emp(x))" Ordinary literals should not be reused among several normal clauses
  • Constructor Details

    • OrdinaryLiteral

      public OrdinaryLiteral(Atom atom, boolean isPositive)
    • OrdinaryLiteral

      public OrdinaryLiteral(Atom atom)
      Creates an ordinary literal with a positive sign
      Parameters:
      atom - non-null
  • Method Details

    • isPositive

      public boolean isPositive()
    • isNegative

      public boolean isNegative()
    • getAtom

      public Atom getAtom()
    • getPredicate

      public Predicate getPredicate()
    • getPredicateName

      public String getPredicateName()
    • getTerms

      public ImmutableTermList getTerms()
      Specified by:
      getTerms in class Literal
    • applySubstitution

      public OrdinaryLiteral applySubstitution(Substitution substitution)
      Specified by:
      applySubstitution in class Literal
      Parameters:
      substitution - not null
      Returns:
      a literal after applying the given substitution. The literal will be new if some term has changed, otherwise it will be the same
    • accept

      public <T> T accept(LogicSchemaVisitor<T> visitor)
      Specified by:
      accept in class Literal
    • buildNegatedLiteral

      public OrdinaryLiteral buildNegatedLiteral()
      Description copied from class: Literal
      This method builds a new literal that is the negation of this one. E.g.: given an ordinary literal "P(x)" it will return a new literal "not(P(x))", or given a built-in literal "x < y" it will return "x >= y"

      Not all built-in literals can be negated. Thus, this function might throw an Exception.

      Overrides:
      buildNegatedLiteral in class Literal
      Returns:
      a new literal that is the negation of this literal, if this is possible
    • isDerived

      public boolean isDerived()
    • isBase

      public boolean isBase()
    • unfold

      public List<ImmutableLiteralsList> unfold()

      Unfolding a positive ordinary literal returns a list of literals' list, one for each derivation rule of this ordinary literal. In particular, for each derivation rule, it returns a literalsList replacing the variables of the derivation rule's head for the terms appearing in this literal.

      For instance, if we have the ordinary literal "P(1)", with derivation rules "P(x) :- R(x), S(x)" and "P(y) :- T(y), U(y)", unfolding "P(1)" will return two literals' list: "R(1), S(1)" and "T(1), U(1)".

      This unfolding avoids clashing the variables inside the derivation rule's body with the variables appearing in this literal. For instance, if we have the ordinary literal "P(a, b)" with a derivation rule "P(x, y) :- R(x, y, a, b)" it will return "R(a, b, a', b')"

      If the ordinary literal is base, or it is negated, it returns the very same literal.

      Returns:
      a list of ImmutableLiteralsList representing the result of unfolding this literal
    • unfoldWithNegationExtension

      public List<ImmutableLiteralsList> unfoldWithNegationExtension()
      This is an extension of the unfold method that also applies an unfolding for negated literals whose derivation rules does not contain existential variables. E.g.: Suppose the literal "not(Derived(x))" with derivation rule "Derived(x) :- A(x), not(B(x))"

      Unfolding not(Derived()) will return two literals list: "not(A(x))" and "B(x)".

      Returns:
      a list of ImmutableLiteralsList representing the result of unfolding the index-th literal
    • unfold

      public List<ImmutableLiteralsList> unfold(boolean unfoldNegatedLiterals)
    • isRecursive

      public boolean isRecursive()
      Returns:
      whether the Atom of this literal is recursive, or not
    • unfold

      protected ImmutableLiteralsList unfold(int derivationRuleIndex)
      Parameters:
      derivationRuleIndex - derivation rule to use for the unfolding
      Returns:
      the corresponding derivation rule applying a substitution that unifies the rule head with this terms
    • toString

      public String toString()
      Overrides:
      toString in class Object