Search in sources :

Example 1 with POSModelLoader

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();
}
Also used : Scanner(java.util.Scanner) POSModel(opennlp.tools.postag.POSModel) POSTaggerME(opennlp.tools.postag.POSTaggerME) PerformanceMonitor(opennlp.tools.cmdline.PerformanceMonitor) POSModelLoader(opennlp.tools.cmdline.postag.POSModelLoader) File(java.io.File)

Example 2 with POSModelLoader

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();
}
Also used : Scanner(java.util.Scanner) POSModel(opennlp.tools.postag.POSModel) POSTaggerME(opennlp.tools.postag.POSTaggerME) PerformanceMonitor(opennlp.tools.cmdline.PerformanceMonitor) POSModelLoader(opennlp.tools.cmdline.postag.POSModelLoader) File(java.io.File)

Aggregations

File (java.io.File)2 Scanner (java.util.Scanner)2 PerformanceMonitor (opennlp.tools.cmdline.PerformanceMonitor)2 POSModelLoader (opennlp.tools.cmdline.postag.POSModelLoader)2 POSModel (opennlp.tools.postag.POSModel)2 POSTaggerME (opennlp.tools.postag.POSTaggerME)2