blog
Class SymbolTerm

java.lang.Object
  extended by blog.ArgSpec
      extended by blog.Term
          extended by blog.SymbolTerm

public class SymbolTerm
extends Term

A term consisting of a single symbol. This may be either a zero-ary function application or a use of a logical variable. SymbolTerms occur in the abstract syntax tree for a model only before checkTypesAndScope is called on the expressions in the model. After that point, a SymbolTerm is replaced with a LogicalVar if its symbol is the name of a logical variable in the current scope; otherwise it's replaced with a zero-argument FuncAppTerm.

If you're creating a term or formula programmatically, you should not use SymbolTerm; you should use either LogicalVar or FuncAppTerm.


Field Summary
 
Fields inherited from class blog.ArgSpec
location
 
Constructor Summary
SymbolTerm(java.lang.String symbol)
          Creates a new SymbolTerm with the given symbol.
 
Method Summary
 boolean checkTypesAndScope(Model model, java.util.Map scope)
          Returns true if, within the given scope, all the variables used in this ArgSpec are in scope and all type constraints are satisfied.
 int compile(java.util.LinkedHashSet callStack)
          Does compilation steps that can only be done correctly once the model is complete.
 boolean containsRandomSymbol()
          Returns true if this ArgSpec contains any random function symbols or any type symbols (any type might have a number statement, and thus could be random).
 boolean equals(java.lang.Object o)
           
 java.lang.Object evaluate(EvalContext context)
          Returns the value of this argument specification in the given context.
 Term getCanonicalVersion()
          Returns a version of this term that uses canonical terms as much as possible.
 java.util.Set getFreeVars()
          Returns the logical variables that occur free in this expression.
 Function getFunc()
          Returns the zero-ary function used in this SymbolTerm, or null if this is an occurrence of a logical variable.
 LogicalVar getLogicalVar()
          Returns the logical variable used in this SymbolTerm, or null if this is a zero-ary function application.
 ArgSpec getSubstResult(Substitution subst, java.util.Set<LogicalVar> boundVars)
          Returns the result of applying the substitution subst to this expression, excluding the logical variables in boundVars.
 Term getTermInScope(Model model, java.util.Map scope)
          Returns an object representing this term in the given scope.
 Type getType()
          Returns the type of this term.
 BayesNetVar getVariable()
          Returns the random variable that this term corresponds to.
 int hashCode()
           
 boolean isConstantNull()
          Returns true if this term is the constant term that always denotes Model.NULL.
 boolean isLogicalVar()
          Returns true if this SymbolTerm is an occurrence of a logical variable.
 boolean makeOverlapSubst(Term t, Substitution theta)
          Function for computing a substitution that will make the two terms overlap.
 java.lang.String toString()
           
 
Methods inherited from class blog.Term
containsTerm, getGenFuncsApplied, isNumeric, makeOverlapSubst
 
Methods inherited from class blog.ArgSpec
evaluate, evaluate, getLocation, getSubExprs, getSubstResult, getValueIfNonRandom, isDetermined, setLocation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SymbolTerm

public SymbolTerm(java.lang.String symbol)
Creates a new SymbolTerm with the given symbol. The checkTypesAndScope method will determine if this is a zero-ary function or a logical variable.

Method Detail

isLogicalVar

public boolean isLogicalVar()
Returns true if this SymbolTerm is an occurrence of a logical variable.


getLogicalVar

public LogicalVar getLogicalVar()
Returns the logical variable used in this SymbolTerm, or null if this is a zero-ary function application.


getFunc

public Function getFunc()
Returns the zero-ary function used in this SymbolTerm, or null if this is an occurrence of a logical variable.


checkTypesAndScope

public boolean checkTypesAndScope(Model model,
                                  java.util.Map scope)
Description copied from class: ArgSpec
Returns true if, within the given scope, all the variables used in this ArgSpec are in scope and all type constraints are satisfied. If there is a type or scope error, prints an appropriate message to standard error and returns false.

Specified by:
checkTypesAndScope in class ArgSpec
scope - a Map from variable names (Strings) to LogicalVar objects

getTermInScope

public Term getTermInScope(Model model,
                           java.util.Map scope)
Description copied from class: Term
Returns an object representing this term in the given scope. This method exists to handle cases where a term's class depends on the scope where it occurs, such as when a term consists of a single symbol that may be either a logical variable or a function symbol. If calling checkTypesAndScope on this term would return false, then this method returns null.

The default implementation simply returns this object if checkTypesAndScope returns true, and null otherwise.

Overrides:
getTermInScope in class Term
Parameters:
model - a BLOG model
scope - a map from String to LogicalVar

compile

public int compile(java.util.LinkedHashSet callStack)
Description copied from class: ArgSpec
Does compilation steps that can only be done correctly once the model is complete. Prints messages to standard error if any errors are encountered. Returns the number of errors encountered.

This default implementation just returns 0.

Overrides:
compile in class ArgSpec
Parameters:
callStack - Set of objects whose compile methods are parents of this method invocation. Ordered by invocation order. Used to detect cycles.

getType

public Type getType()
Description copied from class: Term
Returns the type of this term. Throws an IllegalStateException if this term has not been compiled successfully (e.g., if this term is a variable that is not in scope).

Specified by:
getType in class Term

evaluate

public java.lang.Object evaluate(EvalContext context)
Description copied from class: ArgSpec
Returns the value of this argument specification in the given context. Returns null if the partial world in this context is not complete enough to evaluate this ArgSpec, or if this ArgSpec contains a free variable that is not assigned a value in the given context.

Specified by:
evaluate in class ArgSpec

getVariable

public BayesNetVar getVariable()
Returns the random variable that this term corresponds to. If this SymbolTerm is a random function, then the variable returned is a BasicVar. Otherwise, it's a DerivedVar.

Overrides:
getVariable in class ArgSpec

containsRandomSymbol

public boolean containsRandomSymbol()
Description copied from class: ArgSpec
Returns true if this ArgSpec contains any random function symbols or any type symbols (any type might have a number statement, and thus could be random).

Specified by:
containsRandomSymbol in class ArgSpec

getFreeVars

public java.util.Set getFreeVars()
Description copied from class: ArgSpec
Returns the logical variables that occur free in this expression. If this expression was loaded from a file, then this method should be called only after checkTypesAndScope, which converts SymbolTerms to LogicalVars.

The default implementation returns the union of the sets of free variables in this expression's sub-expressions.

Overrides:
getFreeVars in class ArgSpec
Returns:
unmodifiable Set of LogicalVar

getSubstResult

public ArgSpec getSubstResult(Substitution subst,
                              java.util.Set<LogicalVar> boundVars)
Description copied from class: ArgSpec
Returns the result of applying the substitution subst to this expression, excluding the logical variables in boundVars. This method is used for recursive calls. The set boundVars should contain those variables that are bound in the syntax tree between this sub-expression and the top-level expression to which the substitution is being applied.

Specified by:
getSubstResult in class ArgSpec

isConstantNull

public boolean isConstantNull()
Description copied from class: Term
Returns true if this term is the constant term that always denotes Model.NULL. The default implementation returns false.

Overrides:
isConstantNull in class Term

makeOverlapSubst

public boolean makeOverlapSubst(Term t,
                                Substitution theta)
Description copied from class: Term
Function for computing a substitution that will make the two terms overlap. The necessary mappings are added to the given substitution theta. If there is no extension of theta that makes this term and t overlap, this method returns false.

Specified by:
makeOverlapSubst in class Term

getCanonicalVersion

public Term getCanonicalVersion()
Description copied from class: Term
Returns a version of this term that uses canonical terms as much as possible. The canonical term for a guaranteed object obj of type type is returned by type.getCanonicalTerm(obj). A term can be converted to canonical form only if it is non-random and has no free variables (note that if the term is non-random, its value must be a guaranteed object). This method returns a canonical version of this term if possible; otherwise, it returns a version where the subterms have been converted to canonical form as much as possible.

Specified by:
getCanonicalVersion in class Term

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object