Class Script

java.lang.Object
org.apache.sysds.api.mlcontext.Script

public class Script extends Object
A Script object encapsulates a DML or PYDML script.
  • Constructor Details

    • Script

      public Script()
      Script constructor, which by default creates a DML script.
    • Script

      public Script(String scriptString)
      Script constructor, specifying the script content. By default, the script type is DML.
      Parameters:
      scriptString - the script content as a string
  • Method Details

    • getScriptString

      public String getScriptString()
      Obtain the script string.
      Returns:
      the script string
    • setScriptString

      public Script setScriptString(String scriptString)
      Set the script string.
      Parameters:
      scriptString - the script string
      Returns:
      this Script object to allow chaining of methods
    • getInputVariables

      public Set<String> getInputVariables()
      Obtain the input variable names as an unmodifiable set of strings.
      Returns:
      the input variable names
    • getOutputVariables

      public Set<String> getOutputVariables()
      Obtain the output variable names as an unmodifiable set of strings.
      Returns:
      the output variable names
    • getSymbolTable

      public LocalVariableMap getSymbolTable()
      Obtain the symbol table, which is essentially a HashMap<String, Data> representing variables and their values.
      Returns:
      the symbol table
    • getInputs

      public Map<String,Object> getInputs()
      Obtain an unmodifiable map of all inputs (parameters ($) and variables).
      Returns:
      all inputs to the script
    • getInputMetadata

      public Map<String,Metadata> getInputMetadata()
      Obtain an unmodifiable map of input matrix/frame metadata.
      Returns:
      input matrix/frame metadata
    • in

      public Script in(Map<String,Object> inputs)
      Pass a map of inputs to the script.
      Parameters:
      inputs - map of inputs (parameters ($) and variables).
      Returns:
      this Script object to allow chaining of methods
    • in

      public Script in(scala.collection.Map<String,?> inputs)
      Pass a Scala Map of inputs to the script.

      Note that the Map value type is not explicitly specified on this method because [String, Any] can't be recognized on the Java side since Any doesn't have an equivalent in the Java class hierarchy (scala.Any is a superclass of scala.AnyRef, which is equivalent to java.lang.Object). Therefore, specifying scala.collection.Map<String, Object> as an input parameter to this Java method is not encompassing enough and would require types such as a scala.Double to be cast using asInstanceOf[AnyRef].

      Parameters:
      inputs - Scala Map of inputs (parameters ($) and variables).
      Returns:
      this Script object to allow chaining of methods
    • in

      public Script in(scala.collection.Seq<Object> inputs)
      Pass a Scala Seq of inputs to the script. The inputs are either two-value or three-value tuples, where the first value is the variable name, the second value is the variable value, and the third optional value is the metadata.
      Parameters:
      inputs - Scala Seq of inputs (parameters ($) and variables).
      Returns:
      this Script object to allow chaining of methods
    • getInputParameters

      public Map<String,Object> getInputParameters()
      Obtain an unmodifiable map of all input parameters ($).
      Returns:
      input parameters ($)
    • in

      public Script in(String name, Object value)
      Register an input (parameter ($) or variable).
      Parameters:
      name - name of the input
      value - value of the input
      Returns:
      this Script object to allow chaining of methods
    • in

      public Script in(String name, Object value, Metadata metadata)
      Register an input (parameter ($) or variable) with optional matrix metadata.
      Parameters:
      name - name of the input
      value - value of the input
      metadata - optional matrix/frame metadata
      Returns:
      this Script object to allow chaining of methods
    • out

      public Script out(String outputName)
      Register an output variable.
      Parameters:
      outputName - name of the output variable
      Returns:
      this Script object to allow chaining of methods
    • out

      public Script out(String... outputNames)
      Register output variables.
      Parameters:
      outputNames - names of the output variables
      Returns:
      this Script object to allow chaining of methods
    • out

      public Script out(scala.collection.Seq<String> outputNames)
      Register output variables.
      Parameters:
      outputNames - names of the output variables
      Returns:
      this Script object to allow chaining of methods
    • out

      public Script out(List<String> outputNames)
      Register output variables.
      Parameters:
      outputNames - names of the output variables
      Returns:
      this Script object to allow chaining of methods
    • clearIOS

      public void clearIOS()
      Clear the inputs, outputs, and symbol table.
    • clearIO

      public void clearIO()
      Clear the inputs and outputs, but not the symbol table.
    • clearAll

      public void clearAll()
      Clear the script string, inputs, outputs, and symbol table.
    • clearInputs

      public void clearInputs()
      Clear the inputs.
    • clearOutputs

      public void clearOutputs()
      Clear the outputs.
    • clearSymbolTable

      public void clearSymbolTable()
      Clear the symbol table.
    • results

      public MLResults results()
      Obtain the results of the script execution.
      Returns:
      the results of the script execution.
    • getResults

      public MLResults getResults()
      Obtain the results of the script execution.
      Returns:
      the results of the script execution.
    • setResults

      public void setResults(MLResults results)
      Set the results of the script execution.
      Parameters:
      results - the results of the script execution.
    • getScriptExecutor

      public ScriptExecutor getScriptExecutor()
      Obtain the script executor used by this Script.
      Returns:
      the ScriptExecutor used by this Script.
    • setScriptExecutor

      public void setScriptExecutor(ScriptExecutor scriptExecutor)
      Set the ScriptExecutor used by this Script.
      Parameters:
      scriptExecutor - the script executor
    • getScriptExecutionString

      public String getScriptExecutionString()
      Generate the script execution string, which adds read/load/write/save statements to the beginning and end of the script to execute.
      Returns:
      the script execution string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • info

      public String info()
      Display information about the script as a String. This consists of the script type, inputs, outputs, input parameters, input variables, output variables, the symbol table, the script string, and the script execution string.
      Returns:
      information about this script as a String
    • displayInputs

      public String displayInputs()
      Display the script inputs.
      Returns:
      the script inputs
    • displayOutputs

      public String displayOutputs()
      Display the script outputs.
      Returns:
      the script outputs as a String
    • displayInputParameters

      public String displayInputParameters()
      Display the script input parameters.
      Returns:
      the script input parameters as a String
    • displayInputVariables

      public String displayInputVariables()
      Display the script input variables.
      Returns:
      the script input variables as a String
    • displayOutputVariables

      public String displayOutputVariables()
      Display the script output variables.
      Returns:
      the script output variables as a String
    • displaySymbolTable

      public String displaySymbolTable()
      Display the script symbol table.
      Returns:
      the script symbol table as a String
    • getName

      public String getName()
      Obtain the script name.
      Returns:
      the script name
    • setName

      public Script setName(String name)
      Set the script name.
      Parameters:
      name - the script name
      Returns:
      this Script object to allow chaining of methods
    • execute

      public MLResults execute()
      Execute the script and return the results as an MLResults object.
      Returns:
      results as an MLResults object