use of opennlp.tools.postag.POSModel in project deeplearning4j by deeplearning4j.
the class PoStagger method initialize.
/**
* Initializes the current instance with the given context.
*
* Note: Do all initialization in this method, do not use the constructor.
*/
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
super.initialize(context);
this.context = context;
this.logger = context.getLogger();
if (this.logger.isLoggable(Level.INFO)) {
this.logger.log(Level.INFO, "Initializing the OpenNLP " + "Part of Speech annotator.");
}
POSModel model;
try {
POSModelResource modelResource = (POSModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER);
model = modelResource.getModel();
} catch (ResourceAccessException e) {
throw new ResourceInitializationException(e);
}
Integer beamSize = AnnotatorUtil.getOptionalIntegerParameter(context, UimaUtil.BEAM_SIZE_PARAMETER);
if (beamSize == null)
beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;
this.posTagger = new POSTaggerME(model, beamSize, 0);
}
use of opennlp.tools.postag.POSModel in project textdb by TextDB.
the class POSTagexample method main.
public static void main(String[] args) throws IOException {
POSModel model = new POSModelLoader().load(new File("./src/main/java/edu/uci/ics/textdb/sandbox/OpenNLPexample/en-pos-maxent.bin"));
PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
POSTaggerME tagger = new POSTaggerME(model);
String dataFile = "./src/main/resources/abstract_100.txt";
Scanner scan = new Scanner(new File(dataFile));
int counter = 0;
perfMon.start();
while (scan.hasNextLine()) {
String input = scan.nextLine();
String[] sentence = Tokenize(input);
String[] tags = tagger.tag(sentence);
perfMon.incrementCounter();
for (int i = 0; i < sentence.length; i++) {
String word = sentence[i];
String pos = tags[i];
//filter out useless results
if (!word.equals(pos) && !pos.equals("``") && !pos.equals("''")) {
counter++;
System.out.println("word: " + sentence[i] + " pos: " + tags[i]);
}
}
}
System.out.println("Total Number of Results: " + counter);
perfMon.stopAndPrintFinalResult();
scan.close();
}
use of opennlp.tools.postag.POSModel in project stanbol by apache.
the class OpenNLPTest method testLoadEnPOS.
@Test
public void testLoadEnPOS() throws IOException {
POSModel model = openNLP.getPartOfSpeechModel("en");
Assert.assertNotNull(model);
POSTagger posTagger = openNLP.getPartOfSpeechTagger("en");
Assert.assertNotNull(posTagger);
}
use of opennlp.tools.postag.POSModel in project stanbol by apache.
the class OpenNLPTest method testLoadModelByName.
@Test
public void testLoadModelByName() throws IOException {
TokenizerModel tokenModel = openNLP.getModel(TokenizerModel.class, "en-token.bin", null);
Assert.assertNotNull(tokenModel);
SentenceModel sentModel = openNLP.getModel(SentenceModel.class, "en-sent.bin", null);
Assert.assertNotNull(sentModel);
POSModel posModel = openNLP.getModel(POSModel.class, "en-pos-maxent.bin", null);
Assert.assertNotNull(posModel);
ChunkerModel chunkModel = openNLP.getModel(ChunkerModel.class, "en-chunker.bin", null);
Assert.assertNotNull(chunkModel);
TokenNameFinderModel nerModel = openNLP.getModel(TokenNameFinderModel.class, "en-ner-person.bin", null);
Assert.assertNotNull(nerModel);
// unavailable model
tokenModel = openNLP.getModel(TokenizerModel.class, "ru-token.bin", null);
Assert.assertNull(tokenModel);
}
use of opennlp.tools.postag.POSModel in project stanbol by apache.
the class OpenNlpPosTaggingEngine method getPOSTagger.
private POSTagger getPOSTagger(String language) {
String modelName = languageConfig.getParameter(language, MODEL_NAME_PARAM);
try {
POSModel model;
if (modelName == null) {
// use the default
model = openNLP.getPartOfSpeechModel(language);
} else {
model = openNLP.getModel(POSModel.class, modelName, null);
}
if (model != null) {
log.debug("POS Tagger Model {} for lanugage '{}' version: {}", new Object[] { model.getClass().getSimpleName(), model.getLanguage(), model.getVersion() != null ? model.getVersion() : "undefined" });
return new POSTaggerME(model);
}
} catch (Exception e) {
log.warn("Unable to load POS model for language '" + language + "'!", e);
}
log.debug("POS tagging Model for Language '{}' not available.", language);
return null;
}
Aggregations