Stream Scripts
Scripts can be used to customize operations within a particular stream, and they are saved with that stream. Stream scripts can be used to specify a particular execution order for the terminal nodes within a stream. You use the stream script dialog box to edit the script that is saved with the current stream.
To access the stream script tab in the Stream Properties dialog box:
- From the Tools menu, choose:
- Click the Execution tab to work with scripts for the current stream.
The toolbar icons at the top of the stream script dialog box let you perform the following operations:
- Import the contents of a preexisting standalone script into the window.
- Save a script as a text file.
- Print a script.
- Append default script.
- Edit a script (undo, cut, copy, paste, and other common edit functions).
- Execute the entire current script.
- Execute selected lines from a script.
- Stop a script during execution. (This icon is only enabled when a script is running.)
- Check the syntax of the script and, if any errors are found, display them for review in the lower panel of the dialog box.
From version 16.0 onwards, SPSS® Modeler uses the Python scripting language. All versions before this used a scripting language unique to SPSS Modeler, now referred to as Legacy scripting. Depending on the type of script you are working with, on the Execution tab select theDefault (optional script) execution mode and then select either Python or Legacy.
Additionally, you can specify whether this script should or should not be run when the stream is executed. You can select Run this script to run the script each time the stream is executed, respecting the execution order of the script. This setting provides automation at the stream level for quicker model building. However, the default setting is to ignore this script during stream execution. Even if you select the option Ignore this script, you can always run the script directly from this dialog box.
The script editor includes the following features that help with script authoring:
- Syntax highlighting; keywords, literal values (such as strings and numbers), and comments are highlighted.
- Line numbering.
- Block matching; when the cursor is placed by the start of a program block, the corresponding end block is also highlighted.
- Suggested auto-completion.
The colors and text styles used by the syntax highlighter can be customized using the IBM® SPSS Modeler display preferences. You can access the display preferences by choosing and clicking the Syntax tab.
A list of suggested syntax completions can be accessed by selecting Auto-Suggest from the context menu, or pressing Ctrl + Space. Use the cursor keys to move up and down the list, then press Enter to insert the selected text. Press Esc to exit from auto-suggest mode without modifying the existing text.
The Debug tab displays debugging messages and can be used to evaluate script state once the script has been executed. The Debug tab consists of a read-only text area and a single line input text field. The text area displays text that is sent to either standard output or standard error by the scripts, for example through error message text. The input text field takes input from the user. This input is then evaluated within the context of the script that was most recently executed within the dialog (known as the scripting context). The text area contains the command and resulting output so that the user can see a trace of commands. The input text field always contains the command prompt (--> for legacy scripting).
A new scripting context is created in the following circumstances:
- A script is executed using the “Run this script” button or the “Run selected lines” button.
- The scripting language is changed.
If a new scripting context is created, the text area is cleared.