blog
Class ArgSpec

java.lang.Object
  extended by blog.ArgSpec
Direct Known Subclasses:
CardinalitySpec, ExplicitSetSpec, Formula, ImplicitSetSpec, Term, TupleSetSpec

public abstract class ArgSpec
extends java.lang.Object

Represents an abstract argument specification. In general, an argument can be:

Functions are only allowed to take Terms as arguments, whereas CPDs are are allowed to take all argument types.


Field Summary
protected  java.lang.Object location
           
 
Constructor Summary
ArgSpec()
           
 
Method Summary
abstract  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.
abstract  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).
abstract  java.lang.Object evaluate(EvalContext context)
          Returns the value of this argument specification in the given context.
static java.util.List evaluate(EvalContext context, java.util.List argSpecs)
          Returns a List consisting of the objects obtained by evaluating each element of argSpecs in the given context.
 java.lang.Object evaluate(PartialWorld w)
          Returns the value of this argument specification in the context.
 java.util.Set getFreeVars()
          Returns the logical variables that occur free in this expression.
 java.lang.Object getLocation()
          Returns the object specified by the last call to setLocation.
 java.util.Collection getSubExprs()
          Returns the proper sub-expressions of this ArgSpec.
 ArgSpec getSubstResult(Substitution subst)
          Returns the result of applying the given substitution to this expression.
abstract  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.
 java.lang.Object getValueIfNonRandom()
          Returns the value of this ArgSpec if it is non-random.
 BayesNetVar getVariable()
          Returns the (basic or derived) random variable that this argument specification corresponds to.
 boolean isDetermined(PartialWorld w)
          Returns true if the given partial world is complete enough to determine the value of this ArgSpec.
 boolean isNumeric()
          Returns true if the value of this ArgSpec is always an instance of Number (regardless of scope).
 void setLocation(java.lang.Object loc)
          Sets the location of this ArgSpec, for instance, the file name and line number where it appears.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

location

protected java.lang.Object location
Constructor Detail

ArgSpec

public ArgSpec()
Method Detail

evaluate

public static java.util.List evaluate(EvalContext context,
                                      java.util.List argSpecs)
Returns a List consisting of the objects obtained by evaluating each element of argSpecs in the given context.


evaluate

public java.lang.Object evaluate(PartialWorld w)
Returns the value of this argument specification in the context. This method raises a fatal error if the partial world in the given context is not complete enough to evaluate this ArgSpec.


evaluate

public abstract java.lang.Object evaluate(EvalContext context)
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.


containsRandomSymbol

public abstract 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).


isDetermined

public boolean isDetermined(PartialWorld w)
Returns true if the given partial world is complete enough to determine the value of this ArgSpec.


getValueIfNonRandom

public java.lang.Object getValueIfNonRandom()
Returns the value of this ArgSpec if it is non-random. Otherwise returns null.


getVariable

public BayesNetVar getVariable()
Returns the (basic or derived) random variable that this argument specification corresponds to. Assumes this argument specification contains no free variables. The default implementation just returns a DerivedVar with this ArgSpec. However, some argument specifications (such as function application terms and atomic formulas) may correspond to BasicVars.


checkTypesAndScope

public abstract 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. If there is a type or scope error, prints an appropriate message to standard error and returns false.

Parameters:
scope - a Map from variable names (Strings) to LogicalVar objects

compile

public int compile(java.util.LinkedHashSet callStack)
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.

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

isNumeric

public boolean isNumeric()
Returns true if the value of this ArgSpec is always an instance of Number (regardless of scope). The default implementation returns false.


setLocation

public void setLocation(java.lang.Object loc)
Sets the location of this ArgSpec, for instance, the file name and line number where it appears. The location can be any object whose toString method returns an identifying string that can be used in error messages.


getLocation

public java.lang.Object getLocation()
Returns the object specified by the last call to setLocation. If setLocation has not been called, returns the string "(no location)".


getSubExprs

public java.util.Collection getSubExprs()
Returns the proper sub-expressions of this ArgSpec. This is an empty collection if this ArgSpec has no proper sub-expressions.

This default implementation returns an empty collection.

Returns:
unmodifiable Collection of ArgSpec

getFreeVars

public java.util.Set getFreeVars()
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.

Returns:
unmodifiable Set of LogicalVar
Throws:
java.lang.IllegalStateException - if this expression contains a SymbolTerm

getSubstResult

public ArgSpec getSubstResult(Substitution subst)
Returns the result of applying the given substitution to this expression. In the result, every free occurrence of a logical variable x is replaced with subst.getReplacement(x) (which is just x itself if subst does not explicitly specify a replacement).


getSubstResult

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