mln
Class Clause

java.lang.Object
  extended by mln.Clause

public class Clause
extends java.lang.Object

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 relIntanceClauses
          The database table storing the clause instances.
 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.
 void addConstraintNegated(Expression e)
          Add a constraint that must NOT 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.
 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()
           
 double getWeight()
          Return weight of this clause.
 java.lang.String getWeightExp()
          Return the expression of clause weights to be used in SQL.
 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 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, RDB db)
          Return the definition of clause instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cost

public double cost
The cost ascribed to this clause. Used by 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).


relIntanceClauses

public java.lang.String relIntanceClauses
The database table storing the clause instances.


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. Used by 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.

addConstraintNegated

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

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

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.


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()

getWeight

public double getWeight()
Return weight of this clause.


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.


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 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.


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,
                                 RDB db)
Return the definition of clause instance.

Parameters:
ni - The ID of instance.