Skip to content

Instantly share code, notes, and snippets.

@kowey
Created September 8, 2010 15:15
Show Gist options
  • Select an option

  • Save kowey/570271 to your computer and use it in GitHub Desktop.

Select an option

Save kowey/570271 to your computer and use it in GitHub Desktop.
// transliteration of http://gate.ac.uk/sale/tao/splitch12.html#sec:development:newpr
// note that I no longer remember how to program in Java
// and this is the first thing I've written in Scala after hello world
// so it may be very wrong
package example
import gate._
import gate.creole._
import gate.creole.metadata._
import java.net.URL
/**
* Processing Resource. The @CreoleResource annotation marks this
* class as a GATE Resource, and gives the information GATE needs
* to configure the resource appropriately.
*/
// EYK: You'll need Scala 2.8.0 or higher due to
// https://lampsvn.epfl.ch/trac/scala/ticket/1810
@CreoleResource(name = "Example PR",
isPrivate = false)
class NewPlugin extends AbstractLanguageAnalyser {
/*
* this method gets called whenever an object of this
* class is created either from GATE Developer GUI or if
* initiated using Factory.createResource() method.
*/
@throws(classOf[ResourceInstantiationException])
override def init():Resource = {
// here initialize all required variables, and may
// be throw an exception if the value for any of the
// mandatory parameters is not provided
if (this.rulesURL == null) {
throw new ResourceInstantiationException("rules URL null")
}
return this;
}
/*
* this method should provide the actual functionality of the PR
* (from where the main execution begins). This method
* gets called when user click on the ”RUN” button in the
* GATE Developer GUI’s application window.
*/
@throws(classOf[ExecutionException])
override def execute() {
// write code here
}
/* this method is called to reinitialize the resource */
override def reInit() {
// reinitialization code
}
/*
* There are two types of parameters
* 1. Init time parameters − values for these parameters need to be
* provided at the time of initializing a new resource and these
* values are not supposed to be changed.
* 2. Runtime parameters − values for these parameters are provided
* at the time of executing the PR. These are runtime parameters and
* can be changed before starting the execution
* (i.e. before you click on the ”RUN” button in GATE Developer)
* A parameter myParam is specified by a pair of methods getMyParam
* and setMyParam (with the first letter of the parameter name
* capitalized in the normal Java Beans style), with the setter
* annotated with a @CreoleParameter annotation.
*
* for example to set a value for outputAnnotationSetName
*/
// EYK: I assume we can't use @scala.reflect.BeanProperty
// here because we want to tell GATE some stuff about the
// setter via an annotation. Is this assumption true?
var outputAnnotationSetName : String = null;
def getOutputAnnotationSetName() {
return outputAnnotationSetName;
}
/* The setter method is annotated to tell GATE that it defines an
* optional runtime parameter.
*/
@Optional
@RunTime
@CreoleParameter(comment = "name of the annotationSet used for output")
def setOuputAnnotationSetName(setName:String) {
this.outputAnnotationSetName = setName
}
/** Init−time parameter */
// EYK - same desire to use @scala.reflect.BeanProperty
var rulesURL:URL = null
// getter and setter methods
def getRulesURL() { return rulesURL }
/* This parameter is not annotated @RunTime or @Optional, so it is a
* required init−time parameter.
*/
@CreoleParameter(
comment = "example of an inittime parameter",
defaultValue = "resources/morph/default.rul")
def setRulesURL(rulesURL:URL) {
this.rulesURL = rulesURL
}
}
// vim: set ts=4 sw=4 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment