MaxentModel buildModel = null;
MaxentModel checkModel = null;
POSTagger posTagger = null;
Chunker chunker = null;
HeadRules headRules = null;
if (!d.isDirectory()) {
FileInputStream fis = new FileInputStream(d);
ParserModel model = new ParserModel(fis);
parser = new Parser(model, AbstractBottomUpParser.defaultBeamSize, AbstractBottomUpParser.defaultAdvancePercentage);
} else {
// This branch is for handling models built with OpenNLp 1.4
// Once the models are rebuilt using OpenNLP 1.5 this code should be removed
// @see TreebankParser.java in OpenNLP 1.4
{
File f = new File(d, "build.bin.gz"); // TODO consider moving these literals to an XML file or properties file
buildModel = new opennlp.maxent.io.SuffixSensitiveGISModelReader(f).getModel();
}
{
File f = new File(d, "check.bin.gz");
checkModel = new opennlp.maxent.io.SuffixSensitiveGISModelReader(f).getModel();
}
{
File f = new File(d, "pos.model.bin");
//File f = new File(d, "tag.bin.gz");
MaxentModel posModel = new opennlp.maxent.io.SuffixSensitiveGISModelReader(f).getModel();
if (useTagDictionary) {
File td = new File(d, "tagdict");
TagDictionary tagDictionary = new POSDictionary(td.getAbsolutePath()); //null;
posTagger = new POSTaggerME((AbstractModel) posModel, tagDictionary);
} else {
// f = new File(d, "dict.bin.gz");
Dictionary dictionary = null; // new Dictionary();
posTagger = new POSTaggerME((AbstractModel) posModel, dictionary);
}
}
{
File f = new File(d, "chunk.bin.gz");
MaxentModel chunkModel = new opennlp.maxent.io.SuffixSensitiveGISModelReader(f).getModel();
chunker = new ChunkerME(chunkModel);
}
{
FileReader fr = new FileReader(new File(d, "head_rules"));
headRules = new HeadRules(fr);
}
parser = new Parser(buildModel, checkModel, posTagger, chunker, headRules); //TreebankParser.getParser(modelFileOrDirname, useTagDictionary, useCaseSensitiveTagDictionary, AbstractBottomUpParser.defaultBeamSize, AbstractBottomUpParser.defaultAdvancePercentage);
}