use of opennlp.tools.postag.POSTaggerME 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.POSTaggerME 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.POSTaggerME 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;
}
use of opennlp.tools.postag.POSTaggerME in project stanbol by apache.
the class TextAnalyzer method getPosTagger.
protected final POSTaggerME getPosTagger() {
if (!config.enablePosTagger) {
return null;
}
if (posTagger == null && !posTaggerNotAvailable) {
try {
POSModel posModel = openNLP.getPartOfSpeechModel(language);
if (posModel != null) {
posTagger = new POSTaggerME(posModel);
} else {
log.debug("No POS Model for language '{}'", language);
posTaggerNotAvailable = true;
}
} catch (IOException e) {
log.info("Unable to load POS Model for language '" + language + "'", e);
posTaggerNotAvailable = true;
}
}
return posTagger;
}
Aggregations