In addition to running JET stand-alone, you can use
it as part of another application. In this case jet-version.jar or
jet-all.jar
must be included among the libraries when compiling and running your application.
Here is a small sample program which uses Jet:
1 import Jet.*;
2 import Jet.Tipster.*;
3 import java.util.Vector;
4 import java.io.IOException;
5
6 class UseJet {
7
8 public static void main(String args[]) throws IOException {
9 System.out.println("Starting UseJet...");
10 JetTest.initializeFromConfig("chunk.jet");
11 String txt = "<TEXT>My first sentence to be analyzed for class.</TEXT>";
12 Document doc = new Document(txt);
13 Control.processDocument (doc, null, true, 1);
14 Vector v = doc.annotationsOfType("constit");
15 for (int i=0; i<v.size(); i++) {
16 Annotation a = (Annotation) v.get(i);
17 System.out.println ("Constit " + a.get("cat") + " over " + doc.text(a));
18 }
19 }
20 }
and a brief explanation of this program:
- 10
- initializeFromConfig loads a JET properties file and all
the associated resources (grammars, lexicons, patterns, HMMs, etc.). The
properties file should be the same as for a stand-alone run.
- 11-12
- sets up the document to be analyzed. By default, only text
inside <TEXT> ... </TEXT> is analyzed.
- 13
- processes the document. The parameters to processDocument are
- the document itself
- if non-null, a BufferedWriter
into which output from WriteSGML is written
- true to pop up a window showing the processed document
- an integer used to label the pop-up window ("Jet Document i")
- 14-17
- retrieve annotations of type constit from the document and print
out, one per line, the cat feature of the annotation and the
text spanned by the annotation
This program will load a Jet properties file named chunk.jet from the
local directory. A simple chunk.jet file to run the patterns
for noun and verb chunks is
# JET properties file
Jet.dataPath = data
Tags.fileName = pos_hmm.txt
Pattern.fileName1 = chunkPatterns.txt
processSentence = tokenize, tagJet, pat(chunks)
If the shell variable JET_HOME has been set to the directory where Jet
has been installed, UseJet could be compiled with
javac -cp $JET_HOME/jet-all.jar UseJet.java
and executed with
java -cp .:$JET_HOME/jet-all.jar -DjetHome=$JET_HOME UseJet