Class Literal

All Implemented Interfaces:
LogicalFormula, Term, ToDOM, ToJson, Serializable, Cloneable, Comparable<Term>
Direct Known Subclasses:
Atom

public abstract class Literal extends DefaultTerm implements LogicalFormula
This class represents an abstract literal (an Atom, Structure, Predicate, etc), it is mainly the interface of a literal. To create a new Literal, one of the following concrete classes may be used:
  • Atom -- the most simple literal, is composed by only a functor (no term, no annots);
  • Structure -- has functor and terms;
  • Pred -- has functor, terms, and annotations;
  • LiteralImpl -- Pred + negation.
The latter class supports all the operations of the Literal interface.

There are useful static methods in class ASSyntax to create Literals.

See Also:
  • Field Details

  • Constructor Details

    • Literal

      public Literal()
  • Method Details

    • parseLiteral

      public static Literal parseLiteral(String sLiteral)
      creates a new literal by parsing a string -- ASSyntax.parseLiteral or createLiteral are preferred.
    • copy

      public Literal copy()
    • getFunctor

      public abstract String getFunctor()
      returns the functor of this literal
    • newFunctor

      public Literal newFunctor(String f)
    • getNS

      public abstract Atom getNS()
      returns the name spaceof this literal
    • isLiteral

      public boolean isLiteral()
      Specified by:
      isLiteral in interface Term
      Overrides:
      isLiteral in class DefaultTerm
    • getPredicateIndicator

      public PredicateIndicator getPredicateIndicator()
      returns name space :: functor symbol / arity
    • getArity

      public int getArity()
      returns the number of terms of this literal
    • hasTerm

      public boolean hasTerm()
      returns true if this literal has some term
    • getTerms

      public List<Term> getTerms()
      returns all terms of this literal
    • getTermsArray

      public Term[] getTermsArray()
      returns all terms of this literal as an array
    • getSingletonVars

      public List<VarTerm> getSingletonVars()
      returns all singleton vars (that appears once) in this literal
    • makeTermsAnnon

      public void makeTermsAnnon()
      replaces all terms by unnamed variables (_).
    • makeVarsAnnon

      public Literal makeVarsAnnon()
      replaces all variables by unnamed variables (_).
    • makeVarsAnnon

      public Literal makeVarsAnnon(Unifier un)
      replaces all variables of the term for unnamed variables (_).
      Parameters:
      un - is the unifier that contains the map of replacements
    • getAnnots

      public ListTerm getAnnots()
      returns all annotations of the literal
    • hasAnnot

      public boolean hasAnnot(Term t)
      returns true if there is some annotation t in the literal
    • hasAnnot

      public boolean hasAnnot()
      returns true if the pred has at least one annot
    • hasSubsetAnnot

      public boolean hasSubsetAnnot(Literal p)
      returns true if all this predicate annots are in p's annots
    • hasSubsetAnnot

      public boolean hasSubsetAnnot(Literal p, Unifier u)
      Returns true if all this predicate's annots are in p's annots using the unifier u. if p annots has a Tail, p annots's Tail will receive this predicate's annots, e.g.: this[a,b,c] = p[x,y,b|T] unifies and T is [a,c] (this will be a subset if p has a and c in its annots). if this annots has a tail, the Tail will receive all necessary term to be a subset, e.g.: this[b|T] = p[x,y,b] unifies and T is [x,y] (this will be a subset if T is [x,y].
    • clearAnnots

      public Literal clearAnnots()
      removes all annotations and returns itself
    • getAnnots

      public ListTerm getAnnots(String functor)
      returns all annots with the specified functor e.g.: from annots [t(a), t(b), source(tom)] and functor "t", it returns [t(a),t(b)] in case that there is no such an annot, it returns an empty list.
    • getAnnot

      public Literal getAnnot(String functor)
      returns the first annotation (literal) that has the functor
    • getSources

      public ListTerm getSources()
      returns the sources of this literal as a new list. e.g.: from annots [source(a), source(b)], it returns [a,b]
    • hasSource

      public boolean hasSource()
      returns true if this literal has some source annotation
    • hasSource

      public boolean hasSource(Term agName)
      returns true if this literal has a "source(agName)"
    • canBeAddedInBB

      public boolean canBeAddedInBB()
      returns this if this literal can be added in the belief base (Atoms, for instance, can not be)
    • subjectToBUF

      public boolean subjectToBUF()
      returns this if this literal should be removed from BB while doing BUF
    • negated

      public boolean negated()
      returns whether this literal is negated or not, use Literal.LNeg and Literal.LPos to compare the returned value
    • equalsAsStructure

      public boolean equalsAsStructure(Object p)
    • addTerm

      public void addTerm(Term t)
    • delTerm

      public void delTerm(int index)
    • addTerms

      public Literal addTerms(Term... ts)
      adds some terms and return this
    • addTerms

      public Literal addTerms(List<Term> l)
      adds some terms and return this
    • getTerm

      public Term getTerm(int i)
      returns the i-th term (first term is 0)
    • setTerms

      public Literal setTerms(List<Term> l)
      set all terms of the literal and return this
    • setTerm

      public void setTerm(int i, Term t)
    • setAnnots

      public Literal setAnnots(ListTerm l)
    • addAnnot

      public boolean addAnnot(Term t)
    • addAnnots

      public Literal addAnnots(Term... terms)
      adds some annots and return this
    • addAnnots

      public Literal addAnnots(List<Term> l)
      adds some annots and return this
    • delAnnot

      public boolean delAnnot(Term t)
    • delAnnots

      public boolean delAnnots(List<Term> l)
      removes all annots in this pred that are in the list l.
      Returns:
      true if some annot was removed.
    • delAnnots

      public boolean delAnnots()
    • importAnnots

      public boolean importAnnots(Literal p)
      "import" annots from another predicate p. p will be changed to contain only the annots actually imported (for Event), for example: p = b[a,b] this = b[b,c] after import, p = b[a] It is used to generate event invalid input: '<'+b[a]>.
      Returns:
      true if some annot was imported.
    • addSource

      public Literal addSource(Term agName)
      adds the annotation source(agName)
    • delSource

      public boolean delSource(Term agName)
      deletes one source(agName) annotation, return true if deleted
    • delSources

      public void delSources()
      deletes all source annotations
    • noSource

      public Literal noSource()
    • setNegated

      public Literal setNegated(boolean b)
      changes the negation of the literal and return this
    • logicalConsequence

      public Iterator<Unifier> logicalConsequence(Agent ag, Unifier un)
      logicalConsequence checks whether one particular predicate is a logical consequence of the belief base. Returns an iterator for all unifiers that are logCons.
      Specified by:
      logicalConsequence in interface LogicalFormula
    • getAsListOfTerms

      public ListTerm getAsListOfTerms()
      returns this literal as a list with three elements: [namespace, functor, list of terms, list of annots]
    • newFromListOfTerms

      public static Literal newFromListOfTerms(ListTerm lt) throws JasonException
      creates a literal from a list with four elements: [namespace, functor, list of terms, list of annots] (namespace is optional)
      Throws:
      JasonException
    • forceFullLiteralImpl

      public Literal forceFullLiteralImpl()
      Transforms this into a full literal (which implements all methods of Literal), if it is an Atom; otherwise returns 'this'
    • addSourceInfoAsAnnots

      public Literal addSourceInfoAsAnnots(SourceInfo info)
    • getAsJson

      public javax.json.JsonValue getAsJson()
      Specified by:
      getAsJson in interface ToJson