Gython scripts can fully control Metadata Objects containing information and settings needed for running data mining processes. These operations are:
Constructing Data Mining Objects
Accessing and modifying the properties of Data Mining Objects
Loading and saving Data Mining Objects from and to the Metadata Repository.
Executing and synchronizing Data Mining Tasks.
Every Data Mining Object can be constructed in the following way:
obj = ClassName(constructor_args)
Where ClassName is the object's class name and constructor_args is a comma-separated list of constructor arguments. For example, the ClassificationSettings object can be created in the following way:
fs = ClassificationFunctionSettings()
The standard way of accessing object properties is with the period, i.e.:
fs.algorithmSettings
The majority of MetaModel objects can be created by using 0-parameter constructors. However, some objects can have constructing parameters. The parameter list is one-to-one mapped to arguments from the Factory.create method for a given MetaModel object. For example, ClassificationTestTask can be created in two ways, because ClassificationTestTaskFactory have two create methods as specified in the javadoc part of the AdvancedMiner Documentation:
create()
create(testDataName, modelName, testResultName)
Thus, the object can be created in two ways:
Example 14.18. Constructing and accessing objects:
# the first method
task = ClassificationTestTask()
task.testDataName = 'test_data_pd'
task.modelName = 'my_model'
task.testResultName = 'results'
# the second method (the end result is the same):
task = ClassificationTestTask( 'test_data_pd', 'my_model', 'results' )
print "Task created"
Output:
Task created
The save command saves a local object to the Metadata Repository. The saved object must have a unique name (chosen by the user) and an identifier (chosen automatically). If the name is the same as the name of an object already stored in the repository, the old object may be overwritten or an exception will be signaled. The replace parameter controls this behavior. Note that only some objects can be saved to the repository. The saved object must be an instance of PersistentObject.
Syntax:
save(name, object[, replace])name - the desired name of saved object. This string may be an object name or may have the form mralias.objectname
object - the object to be saved
replace - if true then any object with the name name already stored in the repository will be overwritten. The default value is true.
The load command loads an object from the Metadata Repository. All changes made to that object are visible only locally. The save function has to be used to store the changed object in the repository.
Syntax:
load(name)name - the name of an object stored in the repository. This string may be an object name or may have the form mralias.objectname.
The rename command changes the name of an object stored in the Metadata Repository.
Syntax:
rename(old_name, new_name)old_name - the current name of the object to be changed. This string may be an object name or may have the form mralias.objectname
new_name - the new name of the object. This string may be an object name or may have the form mralias.objectname
If the user specifies mralias, it should be the same for both object names. If an object with new_name already exists, an exception will be signalled.
The execute command executes tasks stored in the Metadata Repository. This command can work in the blocking (other script commands will wait until the task has been finished) or non-blocking mode. If more then one task is specified, they can be executed synchronously or asynchronously. If any exception occurs during task execution, it will always be displayed in the log window, and, in the case of blocking mode, it will also be visible in the output window. Moreover, if blocking mode is used, an exception will terminate the script.
Syntax:
execute(task, wait = 0 | 1)where:
task =
name | { sync | async : [ task1, task2, ... ] }
name - the name of a task stored in the repository. That string may be an object name or may have the form mralias.objectname
wait - if 1, the command will not exit until the task is finished. If 0, the command only sends a request for task execution. The default is 1.
sync - the tasks will be executed synchronously
async - the tasks will be executed asynchronously
The delete command deletes an object from the Metadata Repository. All local references to this object remain valid.
Syntax:
delete(name)name - the name of object to be deleted. This string may be an object name or may have the form mralias.objectname.
The exists function checks if an object with the specified name is already available in the Metadata Repository. It returns a non zero value if it is. If such object does not exists, the value 0 is returned.
Syntax:
exists(name)name - the name of qthe ueried object. This string may be an object name or may have the form mralias.objectname.
The terminate command terminates a task or transformation that is running on the server. This function does not wait for the task to terminate and does not guarantee immediate ending of the task. If a task is already terminated or was never run no exception will be thrown.
Syntax:
terminate(name)name - the name of the task to terminate. This string may be an object name or may have the form mralias.objectname.
The saveEnv function saves a part of the script environment to the Metadata Repository. The following types of object can be saved: float, int, complex, string, dict, list, tuple.
Syntax:
saveEnv(name[, [s1, s2, ...]], isGlobal, replace)name - the name of the object that will store the saved environment
s1, s2, ... - the names of variables in the script to be saved. If the second parameter is ommited, all objects of valid type will be saved.
isGlobal - if true, global variables will be saved. Otherwise, only local variables will be saved.
replace - if true, any object with the name name already stored in the repository will be overwritten. The default value is true.
The loadEnv command loads an object with the script variables from the Metadata Repository and sets the loaded variables variables in the current environment.
Syntax:
loadEnv(name)name - the name of the object stored in the repository. This string may be an object name or may have the form mralias.objectname.
The mrAlias command sets a new Matadata Repository alias. The alias is a binding between a symbolic name and the Metadata Repository. The alias is used by all functions operating on MR objects. The default alias is arbitrally set by the platform. To explicitly set the default mrAlias, use the mrRegistry command.
Syntax:
mrAlias(mrAliasName, server, repository, user, password)mrAliasName - the symbolic name of the metadata repository. Cannot be None.
server - the address and port of the main server
repository - the address and port of the Metadata Repository
user - user name
password - user password
The log command sends text with the level INFO to the log window.
Syntax:
log(text)text - the text to be displayed