weka.core.expressionlanguage.weka

## Class InstancesHelper

- java.lang.Object
- - weka.core.expressionlanguage.weka.InstancesHelper

- All Implemented Interfaces:
    java.io.Serializable, Macro, MacroDeclarations, VariableDeclarations

      public class InstancesHelper
      extends java.lang.Object
      implements VariableDeclarations, Macro, MacroDeclarations

  A helper class to expose instance values and macros for instance values to a program Exposes instance values of the current instance (see `setInstance(Instance)` and `setInstance(int)` methods) as a1, A1 or ATT1 etc where the number is the attribute index (starting with 1). Furthermore exposes the class value as CLASS. Exposes the '`ismissing`' macro which can only be applied to instance values and returns whether the value is set as missing in the current instance.
  Version:
    $Revision: 1000 $
  Author:
    Benjamin Weber ( benweber at student dot ethz dot ch )
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `InstancesHelper(Instances dataset)` Constructs an `InstancesHelper` for the given dataset

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Node` | `evaluate(Node... params)` Evaluates the 'ismissing' macro
    `Macro` | `getMacro(java.lang.String name)` Tries to fetch a macro
    `Node` | `getVariable(java.lang.String name)` Tries to fetch a variable of an instance value
    `boolean` | `hasMacro(java.lang.String name)` Whether the given macro is declared
    `boolean` | `hasVariable(java.lang.String name)` Returns whether the variable is declared
    `boolean` | `missingAccessed()` Whether a missing value has been evaluated during computation.
    `void` | `setInstance(Instance instance)` Sets the current instance to be the supplied instance
    `void` | `setInstance(int i)` Sets the instance at index i of the supplied dataset to be the current instance

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### InstancesHelper

          public InstancesHelper(Instances dataset)

      Constructs an `InstancesHelper` for the given dataset
      Parameters:
        `dataset` - the dataset whose instance values should be exposed

  - ### Method Detail

    - #### hasMacro

          public boolean hasMacro(java.lang.String name)

      Whether the given macro is declared
      Specified by:
        `hasMacro` in interface `MacroDeclarations`
      Parameters:
        `name` - name of the macro
      Returns:
        whether the given macro is declared

    - #### getMacro

          public Macro getMacro(java.lang.String name)

      Tries to fetch a macro The same invariant of `MacroDeclarations` applies here too.
      Specified by:
        `getMacro` in interface `MacroDeclarations`
      Parameters:
        `name` - of the macro
      Returns:
        the macro

    - #### evaluate

          public Node evaluate(Node... params)
                        throws SemanticException

      Evaluates the 'ismissing' macro
      Specified by:
        `evaluate` in interface `Macro`
      Parameters:
        `params` - the arguments for the macro
      Returns:
        an AST node representing the ismissing function
      Throws:
        `SemanticException`

    - #### setInstance

          public void setInstance(int i)

      Sets the instance at index i of the supplied dataset to be the current instance
      Parameters:
        `i` - the index of the instance to be set

    - #### setInstance

          public void setInstance(Instance instance)

      Sets the current instance to be the supplied instance
      Parameters:
        `instance` - instance to be set as the current instance

    - #### missingAccessed

          public boolean missingAccessed()

      Whether a missing value has been evaluated during computation. Will be reset when the `setInstance(int)` or `setInstance(Instance)` method is called.
      Returns:
        whether a missing value has been evaluated during computation

    - #### hasVariable

          public boolean hasVariable(java.lang.String name)

      Returns whether the variable is declared
      Specified by:
        `hasVariable` in interface `VariableDeclarations`
      Parameters:
        `name` - name of the variable
      Returns:
        whether it has been declared

    - #### getVariable

          public Node getVariable(java.lang.String name)

      Tries to fetch a variable of an instance value The same invariant of `VariableDeclarations` applies here too.
      Specified by:
        `getVariable` in interface `VariableDeclarations`
      Parameters:
        `name` - name of the variable
      Returns:
        node representing the instance value