use of edu.illinois.cs.cogcomp.lbjava.nlp.SentenceSplitter 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;
}
}
use of edu.illinois.cs.cogcomp.lbjava.nlp.SentenceSplitter in project cogcomp-nlp by CogComp.
the class SegmentTagPlain method main.
public static void main(String[] args) {
String taggerName = null;
String inputFile = null;
String parserName = null;
try {
taggerName = args[0];
inputFile = args[1];
if (args.length > 2) {
parserName = args[2];
if (args.length > 3)
throw new Exception();
}
} catch (Exception e) {
System.err.println("usage: java edu.illinois.cs.cogcomp.lbjava.edu.illinois.cs.cogcomp.lbjava.nlp.seg.SegmentTagPlain <word classifier> " + "<input file> \\\n" + " [<parser>]");
System.exit(1);
}
Classifier tagger = ClassUtils.getClassifier(taggerName);
Parser parser;
if (parserName == null)
parser = new PlainToTokenParser(new WordSplitter(new SentenceSplitter(inputFile)));
else
parser = ClassUtils.getParser(parserName, new Class[] { Parser.class }, new Parser[] { new WordSplitter(new SentenceSplitter(inputFile)) });
String previous = "";
for (Word w = (Word) parser.next(); w != null; w = (Word) parser.next()) {
String prediction = tagger.discreteValue(w);
if (prediction.startsWith("B-") || prediction.startsWith("I-") && !previous.endsWith(prediction.substring(2)))
System.out.print("[" + prediction.substring(2) + " ");
System.out.print(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))))
System.out.print("] ");
if (w.next == null)
System.out.println();
previous = prediction;
}
}
Aggregations