Friday, March 4, 2011

How to Create a Standalone Application Using GATE Embedded

General Architecture for Text Engineering or GATE is a Java suite of tools originally developed at the University of Sheffield beginning in 1995 and now used worldwide by a wide community of scientists, companies, teachers and students for all sorts of natural language processing tasks, including information extraction in many languages.

For non-programmers, you can use GATE Developer for all of the NLP tasks. For programmers, you can use GATE Embedded to embed its language processing functionality in your applications. In this article, we will demontrate how to use GATE in a standalone application named GoldFish.

Gold Fish Example

Andrew Golightly has noticed a lot of programmers having problems running GATE outside of the GUI (i.e., wanting to run it as a standalone program).

So, he has written a sample program which essentially implements the "Goldfish" example in the User Guide for GATE (see

This program counts the number of times the word "Goldfish" appears in a sentence. It uses three Processing Resources (PRs) to achieve that:
  • DefaultTokeniser
  • SentenceSplitter
  • GoldFish
The first two PRs are provided in ANNIE plugin while the third is a new PR provided in this sample program. This sample program was created in 2003 and is a bit dated. This article tries to fill in the gaps and show what changes are needed from the original program provided by Andrew.

BootStrap Wizard

To create a new PR you need to:
  • Write a Java class (i.e., that implements GATE’s beans model
  • Compile the class, and any others that it uses, into a Java Archive (JAR) file
  • Write some XML configuration data (i.e., creole.xml) for the new resource
  • Tell GATE the URL of the new JAR and XML files.
GATE Developer helps you with this process by creating a set of directories and files that implement a basic resource, including a Java code file and a Makefile. This process is called ‘bootstrapping’. To bootstrap, you do:
  • Start up GATE Developer
  • Start up BootStrap Wizard (Tools > BootStrap Wizard)
  • Fill in the information as shown below

A new folder named GoldFish is created as follows:


+-- classes/

+-- src/
put all your Java sources in here.
+-- lib/

+-- resources/
any external files used by your plugin (e.g. configuration files,
JAPE grammars, gazetteer lists, etc.) go in here.
+-- build.xml
Ant build file for building your plugin.
property definitions that control the build process go in here,
in particular, make sure that gate.home points to your copy of GATE.
+-- creole.xml
plugin configuration file for GATE - edit this to add parameters, etc.,
for your resources.

For my environment, I need to update gate.home property in to point to my new GATE installation location:


Next we use Eclipse IDE for our project development. You can proceed as follows:

  • Start up Eclipse
  • Bring up New Project Dialog (File > New > Project)
  • Select "Java Project from Existing Ant Buildfile" wizard
  • Specify GoldFish as your project name
  • Select GoldFish/build.xml as your Ant buildfile
  • Click Finish

A new project named GoldFish is created as below:
Under src folder, there is a file named in a package named sheffield.creole.example, which is created by BootStrap Wizard. Now, let's copy two files:

from GATE example code repository and put them in src/sheffield/creole/example . Note that you need to fix up package name (i.e., from andrewgolightly.nlp.gate to sheffield.creole.example) and class name (from Goldfish to GoldFish). So, your src/sheffield/creole/example folder looks like this:

+-- example/

Before we proceed, we need to add two statements below Gate.init() in

// need resource data for GlodFish
new File(System.getProperty("user.dir")).toURL());
// need ANNIE plugin for the Defaulttokeniser and SentenceSplitter
new File(Gate.getPluginsHome(), ANNIEConstants.PLUGIN_DIR).toURL()

Without these fixes, you'll see the following ResourceInstantiationException exception:

gate.creole.ResourceInstantiationException: Couldn't get ...

Next, you need to edit the Run/Debug Settings of project properties to add a single argument:


This is our input document to be processed by the GATE pipeline. You can copy it from here.

Now we need to compile the class and package it into a JAR file. The bootstrap wizard creates an Ant build file that makes this very easy – so long as you have Ant set up properly, you can simply run
ant jar

from command line. This will compile the Java source code and package the resulting classes into GoldFish.jar.

Finally, you can run TotalGoldfishCount by right selecting it from Package Explorer( > Run As > Java Application). If everything was set up appropriately, you should see the following output from the console:

1) testFile.txt -- success
* Loading gate.creole.tokeniser.DefaultTokeniser ... done
* Loading gate.creole.splitter.SentenceSplitter ... done
* Loading sheffield.creole.example.GoldFish ... done
Creating corpus from documents obtained...done
Running processing resources over corpus...done
The features of document "/D:/Gate/GoldFishExample/GoldFish/testFile.txt" are:
*) Number of tokens --> 56
*) Total "Goldfish" count --> 9
*) Number of words --> 46
*) Number of characters --> 322
*) Number of sentences --> 7

Demo done... :)


rajinimaski said...

super blog :) It helped me a lot :)

yajur said...

interesting blog. It would be great if you can provide more details about it. Thanks you

Property for Sale in Sheffield

Mohammad Waqar said...

i got stuck in a place.the error shows

Problem setting the classpath of the project from the javac classpath:
D:\Gate\lib not found

m new in all these fields can anyone please help me in this.

Mohammad Waqar said...


M stuck in between
the error is

Problem Setting the classpath of the project from the javac classpath:
D:\Gate\lib not found

m new to all these..please anyone out thr help me out in this issue.

Thanks in advance!

kusaram yadhavan said...

My cousin recommended this blog and she was totally right keep up the fantastic work!

Embedded System Projects

Huifen said...

Thanks for the help! But I'm stuck at the Run/Debug Settings for configuration. It keeps telling me that my Main type is not specified. Can you give more details on how you add the line of argument?

Alex McLintock said...

Can you explain this line a bit more? I am having trouble getting GATE to load my GoldFish resource - even though it is compiled into a class - and loads the generic ANNIE resources.


Rudi said...

two changes that made it working for me

ANNIE directory has to be registered first, so use this order

// need ANNIE plugin for the Defaulttokeniser and SentenceSplitter
Gate.getCreoleRegister().registerDirectories(new File(Gate.getPluginsHome(), ANNIEConstants.PLUGIN_DIR).toURL());
Gate.getCreoleRegister().registerDirectories(new File(System.getProperty("user.dir")).toURL());

somehow the JAR SCAN seems to be insufficient in creole.xml. So I had to add the GoldFish-Class within a RESSOURCE-tag as described here:

jan.p said...

the lacks the @CreoleResource annotations thats why the SCAN is insufficient