General scripts provide a way for you to utilize the Python programming language to create scripts that can receive data from inputs, make calculations, and then return one or more outputs. General scripts can be as simple or as complex as you need them to be, depending on the data that you want the script to calculate.
General scripts can be used in a Cognitive Analytics cognition with a Script node. The parameters that you define in the script determine how the Script node in Cognitive Analytics will behave. Each single-value parameter that you specify as an input appears as a field on the Properties window for the Script node. You can then use standard cognition options to provide values to the parameters in the script. The output of a Script node is determined by the general script, which can produce an output to use as the value and an Output to use as the score of a predicted value, or a single-value output as calculated by the general script. The output of the general script determines what values subsequent nodes in the cognition can use for additional calculations or actions.
General Script Basic Principles
Note: This documentation assumes that you are familiar with developing Python code, and general scripts are limited to the Python libraries that are currently supported in GE Digital APM.
When working with general scripts within GE Digital APM, you must understand the basic principles described in this section.
Script Structure
A script used in GE Digital APM must have the following structure:
The script must import any Python libraries. The following Python libraries are supported in GE Digital APM:
def main():
function.The following images show basic examples of the expected structure of a Python script.
Example 1
Example 2
Inputs
A script can have multiple inputs, which must be included in the def main():
function in the script definition. You can define single-value inputs, a list of inputs, or both.
When determining the best way to define the inputs to your script, consider these points:
If you use a list of inputs, consider the following options to control the number of items in the input:
You can configure a script to use a set number of list inputs. If you do this, you must always select that many columns in the input data.
You can use a text cleanup library in your script. If you do this, the whole list will be concatenated and will return one string of values that you can use.
Tip: The following script excerpt shows how you could call a text cleanup library in your script:
from meridium.classifier.pipeline import TextCleanupPipeline
textCleanupPipeline = TextCleanupPipeline()
def main(data):
out = textCleanupPipeline.Clean(data[0])
return {'out': out}
You can write the logic in the script that checks the number of inputs.
Only single-value inputs appear on the Properties window for the Script node in Cognitive Analytics.
If you include both a list of inputs and single-value inputs, you must include the list of inputs before the single-value inputs in the def main ():
definition.
The following images show examples of the types of inputs you can define.
Single-Value Input
List Input
Both List and Single-Value Input
Outputs
A general script in GE Digital APM can have only two outputs:
The output in the script must be returned as a dictionary in the format {‘id’:key, ‘id2’:key2 }
, where each key corresponds to the parameter ID. For example: Return {‘output’:output, ‘score’: random.randrange(0, 100, 1)/100}
Copyright © 2018 General Electric Company. All rights reserved.