With the runGroovyScript command you can run Groovy scripts from within OntoBroker and perform any operations using the OntologyManager. The Groovy script must be located in the groovy subdirectory of the extensions directory.
Syntax
runGroovyScript "pathToScript",arg1,...
The runGroovyScript command takes at least one argument. The first argument is the path to the Groovy script, relative to the groovy subdirectory of the extensions directory, i.e. the Extensions.Directory property of the OntoConfig.prp. By default this is located at $ONTOBROKER_HOME/extensions/groovy.
Arguments
You can specify more comma-separated arguments. These are just forwarded to the script in the variable args as Term objects. args[0] is always the script name itself. Example:
runGroovyScript "myscript.groovy",1.0,2.0 .
Bindings
You can use the following predefined variable bindings in the Groovy script:
Variable name |
Description |
ontologyManager |
The instance of org.semanticweb.kaon2.api.OntologyManager |
log |
Log4j Logger logging into the category [DATAMODEL] |
args |
The command arguments as org.semanticweb.kaon2.api.logic.Term array (args[0] is the script name) |
command |
Closure to execute a command. It expects exactly one string argument containing the command in ObjectLogic syntax. Example: command("insert a[b->c]@m1.") |
query |
Closure to execute query Example: query("?- ?X::?Y@?M.").each { println it.X,it.Y,it.M } |