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)) + "%");
}
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);
}
}
Aggregations