tuffy.mln
Class Literal

java.lang.Object
  extended by tuffy.mln.Literal
All Implemented Interfaces:
java.lang.Cloneable

public class Literal
extends java.lang.Object
implements java.lang.Cloneable

A literal in first-order logic.


Nested Class Summary
private  class Literal.VarClique
          Clique of variables.
 
Field Summary
private  boolean coversAllMaterializedTuples
           
private  int idx
          The index of this literal in its parent clause.
private  Predicate pred
          Predicate object associated with this literal.
private  boolean sense
          The positive/negative value of this literal.
private  java.util.ArrayList<Term> terms
          List of terms (variable/constant) contained in this literal.
private  Tuple tuple
          The tuple format of this literal.
private  java.util.HashSet<java.lang.String> vars
          The name set of all variables in this literal.
 
Constructor Summary
Literal(Predicate predicate, boolean sense)
          Constructor of Literal.
 
Method Summary
 void appendTerm(Term t)
          Append a new term to this literal.
 java.lang.Object clone()
           
 boolean coversAllMaterializedTuples()
          Test whether we want this literal to cover all materialized tuples regardless of the sense of this literal.
 void flipSense()
          Flip the sense of this literal.
 int getIdx()
          Return the assigned index of this literal in its parent clause.
 Predicate getPred()
          Return the predicate of this literal.
 boolean getSense()
          Return true if this is a positive literal.
 java.util.ArrayList<Term> getTerms()
          Return the list of terms in this literal.
 java.util.HashSet<java.lang.String> getVars()
          Return the set of variable names in this literal.
 boolean isBuiltIn()
          Return whether the predicate of this literal is a built-in predicate.
 boolean isSameAs(Literal lit)
          Compare a given literal with this one.
 java.util.HashMap<java.lang.String,Term> mostGeneralUnification(Tuple atuple)
          Compute the most general unification (MGU) of two literals.
 void setCoversAllMaterializedTuples(boolean coversAllMaterializedTuples)
          Set whether we want this literal to cover all materialized tuples regardless of the sense of this literal.
 void setIdx(int i)
          Assign an unique (within its parent clause) index to this literal.
 void setSense(boolean asense)
          Set the sense of this literal.
 Literal substitute(java.util.HashMap<java.lang.String,Term> vmap)
          Apply a substitution to this literal.
 Atom toAtom(Atom.AtomType type)
          Convert this literal to an atom.
 java.lang.String toString()
          Return the human-friendly representation of this literal.
 Tuple toTuple()
          Convert this literal into a tuple.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pred

private Predicate pred
Predicate object associated with this literal.


idx

private int idx
The index of this literal in its parent clause.


terms

private java.util.ArrayList<Term> terms
List of terms (variable/constant) contained in this literal.


sense

private boolean sense
The positive/negative value of this literal. Here the positive/negative refers to that in Horn clause.


coversAllMaterializedTuples

private boolean coversAllMaterializedTuples

tuple

private Tuple tuple
The tuple format of this literal. Need call toTuple() to make this variable not null. This variable is not automatically maintained. To obtain the most update to date version, you need to call toTuple().


vars

private java.util.HashSet<java.lang.String> vars
The name set of all variables in this literal.

Constructor Detail

Literal

public Literal(Predicate predicate,
               boolean sense)
Constructor of Literal.

Parameters:
predicate - the predicate
sense - true for a positive literal; false for a negative one
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

isBuiltIn

public boolean isBuiltIn()
Return whether the predicate of this literal is a built-in predicate.


getVars

public java.util.HashSet<java.lang.String> getVars()
Return the set of variable names in this literal.


getPred

public Predicate getPred()
Return the predicate of this literal.


getTerms

public java.util.ArrayList<Term> getTerms()
Return the list of terms in this literal.


getIdx

public int getIdx()
Return the assigned index of this literal in its parent clause.


setIdx

public void setIdx(int i)
Assign an unique (within its parent clause) index to this literal.

Parameters:
i - the index
See Also:
Clause.addLiteral(Literal)

mostGeneralUnification

public java.util.HashMap<java.lang.String,Term> mostGeneralUnification(Tuple atuple)
Compute the most general unification (MGU) of two literals.

Parameters:
atuple - the literal (in the form of a tuple) to be unified
Returns:
the MGU in the form of a mapping from variables to variables/constants

toString

public java.lang.String toString()
Return the human-friendly representation of this literal.

Overrides:
toString in class java.lang.Object

appendTerm

public void appendTerm(Term t)
Append a new term to this literal.

Parameters:
t - the term to be appended

toTuple

public Tuple toTuple()
Convert this literal into a tuple. This will assign an internal ID for variables obeying the syntax of class Tuple from Strings.


isSameAs

public boolean isSameAs(Literal lit)
Compare a given literal with this one. By ``same'', it means 1) predicate is same; 2) sense is same; 3) corresponding constant is same; and 4) the name of corresponding variable is same. (Do not consider substitution).

Parameters:
lit - the literal needed to be compared.
Returns:
true if these two literals are the same, false otherwise.

substitute

public Literal substitute(java.util.HashMap<java.lang.String,Term> vmap)
Apply a substitution to this literal.

Parameters:
vmap - the substitution
Returns:
the new literal

toAtom

public Atom toAtom(Atom.AtomType type)
Convert this literal to an atom.

Parameters:
type - indicates if it's an evidence, a query, etc.

flipSense

public void flipSense()
Flip the sense of this literal.


getSense

public boolean getSense()
Return true if this is a positive literal. Here the positive/negative refers to that in Horn clause.


setSense

public void setSense(boolean asense)
Set the sense of this literal.

Parameters:
asense - true if this is intended to be a positive literal

setCoversAllMaterializedTuples

public void setCoversAllMaterializedTuples(boolean coversAllMaterializedTuples)
Set whether we want this literal to cover all materialized tuples regardless of the sense of this literal.

Parameters:
coversAllMaterializedTuples -

coversAllMaterializedTuples

public boolean coversAllMaterializedTuples()
Test whether we want this literal to cover all materialized tuples regardless of the sense of this literal.