tuffy.mln
Class Clause

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

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

A first-order logic clause, namely a disjunct of literals.


Field Summary
 double cost
          The cost ascribed to this clause.
static java.util.HashMap<java.lang.Integer,java.lang.String> mappingFromID2Const
          Map from Constant ID to Constant Name.
static java.util.HashMap<java.lang.String,java.lang.String> mappingFromID2Desc
          Map from clause ID to its description.
 java.lang.String sqlFromList
          The From sub-clause of SQL for grounding.
 java.lang.String sqlPivotAttrsList
          The list of attributes that are NOT existential variables.
 java.lang.String sqlWhereBindings
          The Where sub-clause of SQL for grounding.
 java.util.ArrayList<GClause> violatedGClauses
          Violated ground clauses.
 double violations
          The number of violations on this clause.
 
Constructor Summary
Clause()
          Construct an empty clause.
 
Method Summary
 void absorb(Clause c)
          "Absorb" another clause of the same pattern into this clause.
 void addConstraint(Expression e)
          Add a constraint that must hold.
 boolean addExistentialVariable(java.lang.String v)
          Existentially quantify a variable.
 void addLiteral(Literal lit)
          Add a literal to this clause.
 void addSpecText(java.lang.String s)
           
 void addUserProvidedName(java.lang.String nm)
          Add user provided names to this clause.
 void checkVariableSafety()
          Check for unsafe variables in the clause, and mark the corresponding Predicates.
 Clause clone()
           
 void generateSQL()
          Generate the SQL command for grounding this clause.
 java.util.ArrayList<Expression> getConstraints()
           
 int getId()
          Get clause ID.
 java.util.ArrayList<Literal> getLiteralsOfPredicate(Predicate pred)
          Return the member literals of a particular predicate.
 java.lang.String getName()
          Return the assigned name of this clause.
 java.util.Set<Predicate> getReferencedPredicates()
          Return the set of predicates referenced by this clause.
 java.util.ArrayList<Literal> getRegLiterals()
          Return the list of non-built-in literals (i.e., regular literals).
 java.lang.String getSignature()
          Return the "signature" of this clause.
 java.util.ArrayList<java.lang.String> getSpecText()
           
 java.lang.String getVarWeight()
          Get the variable in this clause that is used as clause weights
 double getWeight()
          Return the weight of this clause.
 java.lang.String getWeightExp()
          Return the expression of clause weights to be used in SQL.
 boolean hasEmbeddedWeight()
          Check if the weight of this clause comes from a variable in the clause
 boolean hasExistentialQuantifiers()
          Check if any variable in this clause is existentially quantified.
 boolean isHardClause()
          Return whether this clause is a hard rule.
 boolean isPositiveClause()
          Check if the weight is positive.
 boolean isTemplate()
          Return true iff this clause contains constant.
 Clause normalize()
          Return a normalized version of this clause.
 void prepareForDB(RDB db)
          Initialize database objects for this clause.
 void setHardWeight()
          Specify this clause as a hard rule.
 void setId(int id)
          Set clause ID.
 void setName(java.lang.String aname)
          Assign a name for this clause.
 void setVarWeight(java.lang.String vw)
           
 void setWeight(double wt)
          Set the weight of this clause.
 java.lang.String toString()
          Return the definition of this clause.
 java.lang.String toString(int ni)
          Return the definition of clause instance.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cost

public double cost
The cost ascribed to this clause. For auditing purposes.

See Also:
MRF.auditClauseViolations()

mappingFromID2Const

public static java.util.HashMap<java.lang.Integer,java.lang.String> mappingFromID2Const
Map from Constant ID to Constant Name. This map is filled in MarkovLogicNetwork.getSymbolID(String, Type). This variable is materialized in Infer.setUp(CommandOptions).


mappingFromID2Desc

public static java.util.HashMap<java.lang.String,java.lang.String> mappingFromID2Desc
Map from clause ID to its description. This is used in learning part to dump out the answers. Here by id it means a string like .. This variable is materialized in Infer.setUp(CommandOptions).


sqlFromList

public java.lang.String sqlFromList
The From sub-clause of SQL for grounding.


sqlPivotAttrsList

public java.lang.String sqlPivotAttrsList
The list of attributes that are NOT existential variables.


sqlWhereBindings

public java.lang.String sqlWhereBindings
The Where sub-clause of SQL for grounding.


violatedGClauses

public java.util.ArrayList<GClause> violatedGClauses
Violated ground clauses.

See Also:
MRF.auditClauseViolations()

violations

public double violations
The number of violations on this clause. For auditing purposes.

See Also:
MRF.auditClauseViolations()
Constructor Detail

Clause

public Clause()
Construct an empty clause. Initial weight = 0.

Method Detail

absorb

public void absorb(Clause c)
"Absorb" another clause of the same pattern into this clause. If this clause is a template, then adding instances into the instance list. Otherwise, add its weight to current clause.

Parameters:
c - the clause to be absorbed
See Also:
normalize()

addConstraint

public void addConstraint(Expression e)
Add a constraint that must hold.

Parameters:
e - A bool expression that must be TRUE.

addExistentialVariable

public boolean addExistentialVariable(java.lang.String v)
Existentially quantify a variable.

Parameters:
v - the variable to be existentially quantified

addLiteral

public void addLiteral(Literal lit)
Add a literal to this clause.


addSpecText

public void addSpecText(java.lang.String s)

addUserProvidedName

public void addUserProvidedName(java.lang.String nm)
Add user provided names to this clause.

Parameters:
nm - user provided name

checkVariableSafety

public void checkVariableSafety()
Check for unsafe variables in the clause, and mark the corresponding Predicates. A variable is unsafe if it appears only in a positive literal; i.e., if it does not appear in the body in the Datalog form.


clone

public Clause clone()
Overrides:
clone in class java.lang.Object

generateSQL

public void generateSQL()
Generate the SQL command for grounding this clause. For each meta-variable, bind them to the clause instance (in FROM and WHERE clause) For each regular-predicate's variable that is not meta-variable, use their grounded atom table to bind the clause (in FROM CLAUSE), with inter-predicate constraints introduced in the clause (in WHERE CLAUSE / JOIN CONDITION IN FROM CLAUSE). For each built-in predicate, write its semantic into SQL conditions directly. The sqlPivotAttrsList contains a list of variables that are not existential variables in the form of $table_name.$column_name. Here $table_name is consistent to other SQL sub-clauses generated by this function.


getConstraints

public java.util.ArrayList<Expression> getConstraints()

getId

public int getId()
Get clause ID.


getLiteralsOfPredicate

public java.util.ArrayList<Literal> getLiteralsOfPredicate(Predicate pred)
Return the member literals of a particular predicate.


getName

public java.lang.String getName()
Return the assigned name of this clause.


getReferencedPredicates

public java.util.Set<Predicate> getReferencedPredicates()
Return the set of predicates referenced by this clause.


getRegLiterals

public java.util.ArrayList<Literal> getRegLiterals()
Return the list of non-built-in literals (i.e., regular literals).


getSignature

public java.lang.String getSignature()
Return the "signature" of this clause.

See Also:
normalize()

getSpecText

public java.util.ArrayList<java.lang.String> getSpecText()

getVarWeight

public java.lang.String getVarWeight()
Get the variable in this clause that is used as clause weights


getWeight

public double getWeight()
Return the weight of this clause. If this clause contains multiple instances, the returned value only indicates the signum.


getWeightExp

public java.lang.String getWeightExp()
Return the expression of clause weights to be used in SQL. For template clauses, it's the name of a table attribute; for non-template clauses, it's a floating number.


hasEmbeddedWeight

public boolean hasEmbeddedWeight()
Check if the weight of this clause comes from a variable in the clause


hasExistentialQuantifiers

public boolean hasExistentialQuantifiers()
Check if any variable in this clause is existentially quantified.


isHardClause

public boolean isHardClause()
Return whether this clause is a hard rule.


isPositiveClause

public boolean isPositiveClause()
Check if the weight is positive.


isTemplate

public boolean isTemplate()
Return true iff this clause contains constant. Note that the result of this function is meaningful iff this clause is a normalized clause.


normalize

public Clause normalize()
Return a normalized version of this clause. The variables and constants are replaced standardized variable names, yielding a signature that can be used to identify clauses of the same pattern. If there are constants in the original clause, the resulting clause is called a template. Clauses of the same pattern will be consolidated under the same template. For example, clauses "!likes(x, Candy) v has(x, Diabetes)" and "!likes(x, WeightLifting) v has(x, Muscles)" would be consolidated into the template "!likes(v1, c1) v has(v1, c2)". Zero-weight clauses will be ignored.

See Also:
MarkovLogicNetwork.registerClause(Clause)

prepareForDB

public void prepareForDB(RDB db)
Initialize database objects for this clause.


setHardWeight

public void setHardWeight()
Specify this clause as a hard rule. Currently hard rules are treated as soft rules with a very large weight.

See Also:
Config.hard_weight

setId

public void setId(int id)
Set clause ID.

Parameters:
id -

setName

public void setName(java.lang.String aname)
Assign a name for this clause.


setVarWeight

public void setVarWeight(java.lang.String vw)

setWeight

public void setWeight(double wt)
Set the weight of this clause.


toString

public java.lang.String toString()
Return the definition of this clause.

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int ni)
Return the definition of clause instance.

Parameters:
ni - The ID of instance.