use of opennlp.tools.cmdline.postag.POSModelLoader 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.cmdline.postag.POSModelLoader 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/texera/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();
}
Aggregations