That is the model you need:
http://opennlp.sourceforge.net/models-1.5/en-chunker.bin
Jörn
On 11/16/11 1:03 AM, Jörn Kottmann wrote:
Hello,
the error message is really unclear about the actual problem.
You are trying to load the parser model into the chunker, please
get the model for the chunker from the model download page.
I think it is called en-chunk.bin, you can also get the CONLL2000
data in case you would like to train it yourself.
We fixed this strange error message already in the 1.5.2 version,
which we are currently trying to get released.
In case you would like to try it you can find it here:
http://people.apache.org/~joern/releases/opennlp-1.5.2-incubating/rc6/
The documentation in it also contains a sample on how to use the
Chunker API.
Hope this helps,
Jörn
On 11/16/11 12:53 AM, Ben Rhelp wrote:
Hi all,
I am trying to find out how to use the Java API for the chunker.
Below is the console output of my failed attempt (My test program is
further down in the body of this email).
Any idea on what I am doing wrong?
thanks in advance,
Ben
Console output:
------------------------------------
Token Part-Of-Speech
Most JJS
large JJ
cities NNS
in IN
the DT
US NNP
had VBD
morning NN
and CC
afternoon NN
newspapers NNS
. .
opennlp.tools.util.InvalidFormatException: Unkown artifact format:
postagger
at opennlp.tools.util.model.BaseModel.<init>(BaseModel.java:132)
at opennlp.tools.chunker.ChunkerModel.<init>(ChunkerModel.java:60)
at ChunkerTest.main(ChunkerTest.java:55)
Exception in thread "main" java.lang.NullPointerException
at opennlp.tools.chunker.ChunkerME.<init>(ChunkerME.java:77)
at opennlp.tools.chunker.ChunkerME.<init>(ChunkerME.java:93)
at opennlp.tools.chunker.ChunkerME.<init>(ChunkerME.java:106)
at opennlp.tools.chunker.ChunkerME.<init>(ChunkerME.java:116)
at ChunkerTest.main(ChunkerTest.java:71)
My test program:
import opennlp.tools.postag.POSModel;
import opennlp.tools.postag.POSTaggerME;
import opennlp.tools.chunker.ChunkerModel;
import opennlp.tools.chunker.ChunkerME;
import java.io.*;
public class ChunkerTest {
private static final String POSTAGGER =
"C:\\Users\\Ben\\Desktop\\BenSave\\NPLmodels\\en-pos-maxent.bin";
private static final String CHUNKER =
"C:\\Users\\Ben\\Desktop\\BenSave\\NPLmodels\\en-parser-chunking.bin";
public static void main(String[] args) throws IOException {
InputStream modelIn4 = null;
POSModel modelPostTagger = null;
try {
modelIn4 = new FileInputStream(POSTAGGER);
modelPostTagger = new POSModel(modelIn4);
}
catch (IOException e) {
// Model loading failed, handle the error
e.printStackTrace();
}
finally {
if (modelIn4 != null) {
try {
modelIn4.close();
}
catch (IOException e) {
}
}
}
POSTaggerME myTagger = new POSTaggerME(modelPostTagger);
String sent[] = new String[]{"Most", "large", "cities",
"in", "the", "US", "had",
"morning", "and", "afternoon", "newspapers",
"."}; String tags1[] = myTagger.tag(sent);
System.out.println("------------------------------------");
System.out.println("Token\tPart-Of-Speech");
for (int i=0; i< tags1.length;i++) {
System.out.println(sent[i]+"\t"+tags1[i]);
}
/*---------------------------------------------------------*/
InputStream modelIn5 = new FileInputStream(CHUNKER);
ChunkerModel modelChunker = null;
try {
modelChunker = new ChunkerModel(modelIn5);
}
catch (IOException e) {
// Model loading failed, handle the error
e.printStackTrace();
}
finally {
if (modelIn5 != null) {
try {
modelIn5.close();
}
catch (IOException e) {
}
}
}
ChunkerME chunker = new ChunkerME(modelChunker);
String tags2[] = chunker.chunk(sent, tags1);
System.out.println("------------------------------------");
System.out.println("Token\tPart-Of-Speech\tChunks");
for (int i=0; i< tags2.length;i++) {
System.out.println(sent[i]+"\t"+tags1[i]+"\t"+tags2[i]);
}
System.out.println("------------------------------------");
}
}