use of opennlp.tools.cmdline.PerformanceMonitor 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.PerformanceMonitor in project textdb by TextDB.
the class NameFinderExample method main.
public static void main(String[] args) throws IOException {
String dataFile = "./src/main/resources/abstract_100.txt";
Scanner scan = new Scanner(new File(dataFile));
InputStream is = new FileInputStream("./src/main/java/edu/uci/ics/texera/sandbox/OpenNLPexample/en-ner-location.bin");
TokenNameFinderModel model = new TokenNameFinderModel(is);
is.close();
NameFinderME nameFinder = new NameFinderME(model);
int counter = 0;
PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
perfMon.start();
while (scan.hasNextLine()) {
String[] sentence = Tokenize(scan.nextLine());
Span[] spans = nameFinder.find(sentence);
perfMon.incrementCounter();
// Print out the tokens of the sentence
if (spans.length != 0) {
for (String s : sentence) {
System.out.print("[" + s + "] ");
}
System.out.println("/n");
}
// Print out the offset of each
for (Span s : spans) {
System.out.println(s.toString());
for (int i = s.getStart(); i < s.getEnd(); i++) {
System.out.println(sentence[i]);
counter++;
}
}
if (spans.length != 0)
System.out.println();
}
perfMon.stopAndPrintFinalResult();
System.out.println("Number of Results: " + counter);
scan.close();
}
use of opennlp.tools.cmdline.PerformanceMonitor in project textdb by TextDB.
the class NameFinderExample method main.
public static void main(String[] args) throws IOException {
String dataFile = "./src/main/resources/abstract_100.txt";
Scanner scan = new Scanner(new File(dataFile));
InputStream is = new FileInputStream("./src/main/java/edu/uci/ics/textdb/sandbox/OpenNLPexample/en-ner-location.bin");
TokenNameFinderModel model = new TokenNameFinderModel(is);
is.close();
NameFinderME nameFinder = new NameFinderME(model);
int counter = 0;
PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
perfMon.start();
while (scan.hasNextLine()) {
String[] sentence = Tokenize(scan.nextLine());
Span[] spans = nameFinder.find(sentence);
perfMon.incrementCounter();
//Print out the tokens of the sentence
if (spans.length != 0) {
for (String s : sentence) {
System.out.print("[" + s + "] ");
}
System.out.println("/n");
}
//Print out the offset of each
for (Span s : spans) {
System.out.println(s.toString());
for (int i = s.getStart(); i < s.getEnd(); i++) {
System.out.println(sentence[i]);
counter++;
}
}
if (spans.length != 0)
System.out.println();
}
perfMon.stopAndPrintFinalResult();
System.out.println("Number of Results: " + counter);
scan.close();
}
use of opennlp.tools.cmdline.PerformanceMonitor 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