use of edu.illinois.cs.cogcomp.lbjava.nlp.seg.PlainToTokenParser 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);
}
}
use of edu.illinois.cs.cogcomp.lbjava.nlp.seg.PlainToTokenParser in project cogcomp-nlp by CogComp.
the class TestDiff method testDiff.
@Test
public void testDiff() {
Chunker tagger = new Chunker();
Parser parser = new PlainToTokenParser(new WordSplitter(new SentenceSplitter(testFile)));
String previous = "";
String sentence = "";
int sentenceCounter = 0;
for (Token w = (Token) parser.next(); w != null; w = (Token) parser.next()) {
String prediction = tagger.discreteValue(w);
if (prediction.startsWith("B-") || prediction.startsWith("I-") && !previous.endsWith(prediction.substring(2)))
sentence += ("[" + prediction.substring(2) + " ");
sentence += ("(" + w.partOfSpeech + " " + w.form + ") ");
if (!prediction.equals("O") && (w.next == null || tagger.discreteValue(w.next).equals("O") || tagger.discreteValue(w.next).startsWith("B-") || !tagger.discreteValue(w.next).endsWith(prediction.substring(2))))
sentence += ("] ");
if (w.next == null) {
sentence = sentence.trim();
String refSentence = refSentences.get(sentenceCounter).trim();
if (!sentence.equals(refSentence))
fail("Produced output doesn't match reference: " + "\nProduced: " + sentence + "\nExpected: " + refSentence);
sentence = "";
sentenceCounter++;
}
previous = prediction;
}
}
use of edu.illinois.cs.cogcomp.lbjava.nlp.seg.PlainToTokenParser in project cogcomp-nlp by CogComp.
the class ChunksAndPOSTags method main.
public static void main(String[] args) {
String filename = null;
try {
filename = args[0];
if (args.length > 1)
throw new Exception();
} catch (Exception e) {
System.err.println("usage: java edu.illinois.cs.cogcomp.chunker.main.ChunksAndPOSTags <input file>");
System.exit(1);
}
Chunker chunker = new Chunker();
Parser parser = new PlainToTokenParser(new WordSplitter(new SentenceSplitter(filename)));
String previous = "";
for (Word w = (Word) parser.next(); w != null; w = (Word) parser.next()) {
String prediction = chunker.discreteValue(w);
if (prediction.startsWith("B-") || prediction.startsWith("I-") && !previous.endsWith(prediction.substring(2)))
logger.info("[" + prediction.substring(2) + " ");
logger.info("(" + w.partOfSpeech + " " + w.form + ") ");
if (!prediction.equals("O") && (w.next == null || chunker.discreteValue(w.next).equals("O") || chunker.discreteValue(w.next).startsWith("B-") || !chunker.discreteValue(w.next).endsWith(prediction.substring(2))))
logger.info("] ");
if (w.next == null)
logger.info("\n");
previous = prediction;
}
}
Aggregations