Search in sources :

Example 1 with POSTagger

use of edu.illinois.cs.cogcomp.pos.lbjava.POSTagger in project cogcomp-nlp by CogComp.

the class POSTag method main.

/**
     * Implements the program described above.
     *
     * @param args The command line parameters.
     **/
public static void main(String[] args) {
    // Parse the command line
    if (!(args.length == 1 && !args[0].startsWith("-") || args.length == 2 && (args[0].equals("-q") || args[0].equals("--quiet")) && !args[1].startsWith("-"))) {
        System.err.println("usage: java edu.illinois.cs.cogcomp.lbj.pos.POSTag [-q] <testing set>\n" + "       If -q is specified, the only output is timing and accuracy\n" + "       information.  Otherwise, the testing set is output with\n" + "       extra tags indicating whether each prediction was correct.");
        System.exit(1);
    }
    boolean quiet = args.length == 2;
    testingFile = args[args.length - 1];
    POSTagger tagger = new POSTagger();
    BufferedReader in = open();
    int correct = 0, incorrect = 0;
    for (String line = readLine(in); line != null; line = readLine(in)) {
        LinkedVector sentence = POSBracketToVector.parsePOSBracketForm(line);
        for (Word word = (Word) sentence.get(0); word != null; word = (Word) word.next) {
            String label = word.partOfSpeech;
            word.partOfSpeech = null;
            String prediction = tagger.discreteValue(word);
            if (prediction.equals(label)) {
                ++correct;
                if (!quiet)
                    System.out.print("+");
            } else {
                ++incorrect;
                if (!quiet)
                    System.out.print("-[" + label + "]");
            }
            if (!quiet)
                System.out.print(word + " ");
        }
        if (!quiet)
            System.out.print("");
    }
    System.out.println("Accuracy: " + (100 * correct / (double) (correct + incorrect)) + "%");
}
Also used : Word(edu.illinois.cs.cogcomp.lbjava.nlp.Word) LinkedVector(edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector) BufferedReader(java.io.BufferedReader) POSTagger(edu.illinois.cs.cogcomp.pos.lbjava.POSTagger)

Example 2 with POSTagger

use of edu.illinois.cs.cogcomp.pos.lbjava.POSTagger in project cogcomp-nlp by CogComp.

the class TestDiff method testDiff.

@Test
public void testDiff() {
    POSTagger tagger = new POSTagger();
    Parser parser = new PlainToTokenParser(new WordSplitter(new SentenceSplitter(testFile)));
    String sentence = "";
    int sentenceCounter = 0;
    int tokenCounter = 0;
    int correctCounter = 0;
    for (Token word = (Token) parser.next(); word != null; word = (Token) parser.next()) {
        String tag = tagger.discreteValue(word);
        if (refTags.get(tokenCounter).equals(tag)) {
            correctCounter++;
        }
        tokenCounter++;
    }
    double result = ((double) correctCounter) / tokenCounter;
    if (result < thresholdAcc) {
        fail("Tagger performance is insufficient: " + "\nProduced: " + result + "\nExpected: " + thresholdAcc);
    }
}
Also used : SentenceSplitter(edu.illinois.cs.cogcomp.lbjava.nlp.SentenceSplitter) PlainToTokenParser(edu.illinois.cs.cogcomp.lbjava.nlp.seg.PlainToTokenParser) Token(edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token) WordSplitter(edu.illinois.cs.cogcomp.lbjava.nlp.WordSplitter) POSTagger(edu.illinois.cs.cogcomp.pos.lbjava.POSTagger) Parser(edu.illinois.cs.cogcomp.lbjava.parse.Parser) PlainToTokenParser(edu.illinois.cs.cogcomp.lbjava.nlp.seg.PlainToTokenParser) Test(org.junit.Test)

Aggregations

POSTagger (edu.illinois.cs.cogcomp.pos.lbjava.POSTagger)2 SentenceSplitter (edu.illinois.cs.cogcomp.lbjava.nlp.SentenceSplitter)1 Word (edu.illinois.cs.cogcomp.lbjava.nlp.Word)1 WordSplitter (edu.illinois.cs.cogcomp.lbjava.nlp.WordSplitter)1 PlainToTokenParser (edu.illinois.cs.cogcomp.lbjava.nlp.seg.PlainToTokenParser)1 Token (edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token)1 LinkedVector (edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector)1 Parser (edu.illinois.cs.cogcomp.lbjava.parse.Parser)1 BufferedReader (java.io.BufferedReader)1 Test (org.junit.Test)1