/** * Returns the next array of {@link Word}s. * * @return The next {@link LinkedVector} of {@link Word}s parsed, or * <code>null</code> if there are no more children in the stream. **/ public Object next() { return convert((String[]) parser.next()); }
/** * Returns {@link edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector}s of {@link Word} objects one at * a time. **/ public Object next() { Sentence sentence = (Sentence) parser.next(); if (sentence == null) return null; return sentence.wordSplit(); }
/** * Returns the next array of {@link Word}s. * * @return The next {@link LinkedVector} of {@link Word}s parsed, or * <code>null</code> if there are no more children in the stream. **/ public Object next() { return convert((String[]) parser.next()); }
/** * Returns {@link edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector}s of {@link Word} objects one at * a time. **/ public Object next() { Sentence sentence = (Sentence) parser.next(); if (sentence == null) return null; return sentence.wordSplit(); }
/** * Returns the next {@link LinkedVector} of {@link Token}s. * * @return The next {@link LinkedVector} of {@link Token}s parsed, or * <code>null</code> if there are no more children in the stream. **/ public Object next() { return convert((LinkedVector) parser.next()); }
/** * Returns the next {@link LinkedVector} of {@link Token}s. * * @return The next {@link LinkedVector} of {@link Token}s parsed, or * <code>null</code> if there are no more children in the stream. **/ public Object next() { return convert((LinkedVector) parser.next()); }
/** * Returns the next <code>LinkedChild</code> parsed. * * @return The next <code>LinkedChild</code> parsed, or <code>null</code> if there are no more * children in the stream. **/ public Object next() { while (next == null) { LinkedVector v = (LinkedVector) parser.next(); if (v == null) return null; next = v.get(0); } LinkedChild result = next; next = next.next; return result; }
/** * Tags the unlabeled data and compares the part-of-speech tags with the labeled data, keeping * track of and reporting total accuracy at the end. */ public void testAccuracy() { WordForm __wordForm = new WordForm(); Parser labeledParser = new POSBracketToToken(labeledTestFile); int numSeen = 0; int numEqual = 0; Token labeledWord = (Token) labeledParser.next(); for (; labeledWord != null; labeledWord = (Token) labeledParser.next()) { String labeledTag = labeledWord.label; String testTag = tagger.discreteValue(labeledWord); if (labeledTag.equals(testTag)) { numEqual++; } numSeen++; } System.out.println("Total accuracy over " + numSeen + " items: " + String.format("%.2f", 100.0 * (double) numEqual / (double) numSeen) + "%"); }
public void testAccuracy() { Parser parser = new ChildrenFromVectors(new CoNLL2000Parser(labeledData)); int numSeen = 0; int numEqual = 0; for (Token w = (Token) parser.next(); w != null; w = (Token) parser.next()) { String prediction = tagger.discreteValue(w); String raw = w.toString(); String actualChunk = raw.substring(raw.indexOf('(') + 1, raw.indexOf(' ')); if (prediction.equals(actualChunk)) { numEqual++; } numSeen++; } logger.info("Total accuracy over " + numSeen + " items: " + String.format("%.2f", 100.0 * (double) numEqual / (double) numSeen) + "%"); }
/** * Takes the names of the example and lexicon files as input on the command line and prints all * the examples to <code>STDOUT</code>. **/ public static void main(String[] args) { String exampleFile = null; String lexiconFile = null; try { exampleFile = args[0]; lexiconFile = args[1]; if (args.length > 2) throw new Exception(); } catch (Exception e) { System.err .println("usage: java edu.illinois.cs.cogcomp.lbjava.parse.FeatureVectorParser <example file> <lexicon file>"); System.exit(1); } Parser parser = new FeatureVectorParser(exampleFile, lexiconFile); for (FeatureVector v = (FeatureVector) parser.next(); v != null; v = (FeatureVector) parser.next()) { v.sort(); logger.info(v.toString()); } }
public void testAccuracy() { Parser parser = new ChildrenFromVectors(new CoNLL2000Parser(labeledData)); int numSeen = 0; int numEqual = 0; for (Token w = (Token) parser.next(); w != null; w = (Token) parser.next()) { String prediction = tagger.discreteValue(w); String raw = w.toString(); String actualChunk = raw.substring(raw.indexOf('(') + 1, raw.indexOf(' ')); if (prediction.equals(actualChunk)) { numEqual++; } numSeen++; } logger.info("Total accuracy over " + numSeen + " items: " + String.format("%.2f", 100.0 * (double) numEqual / (double) numSeen) + "%"); }
private static Vector<NEWord> splitWord(NEWord word) { String[] sentence = {word.form + " "}; Parser parser = new WordSplitter(new SentenceSplitter(sentence)); LinkedVector words = (LinkedVector) parser.next(); Vector<NEWord> res = new Vector<>(); if (words == null) { res.add(word); return res; } String label = word.neLabel; for (int i = 0; i < words.size(); i++) { if (label.contains("B-") && i > 0) label = "I-" + label.substring(2); NEWord w = new NEWord(new Word(((Word) words.get(i)).form), null, label); res.addElement(w); } return res; }
private static Vector<NEWord> splitWord(NEWord word) { String[] sentence = {word.form + " "}; Parser parser = new WordSplitter(new SentenceSplitter(sentence)); LinkedVector words = (LinkedVector) parser.next(); Vector<NEWord> res = new Vector<>(); if (words == null) { res.add(word); return res; } String label = word.neLabel; for (int i = 0; i < words.size(); i++) { if (label.contains("B-") && i > 0) label = "I-" + label.substring(2); NEWord w = new NEWord(new Word(((Word) words.get(i)).form), null, label); res.addElement(w); } return res; }
private static Vector<NEWord> splitWord(NEWord word) { String[] sentence = {word.form + " "}; Parser parser = new WordSplitter(new SentenceSplitter(sentence)); LinkedVector words = (LinkedVector) parser.next(); Vector<NEWord> res = new Vector<>(); if (words == null) { res.add(word); return res; } String label = word.neLabel; for (int i = 0; i < words.size(); i++) { if (label.contains("B-") && i > 0) label = "I-" + label.substring(2); NEWord w = new NEWord(new Word(((Word) words.get(i)).form), null, label); res.addElement(w); } return res; }
/** * Trains the chunker models with the specified training data * * @param parser Parser for the training data. Initialized in trainModels(String trainingData) */ public void trainModelsWithParser(Parser parser) { Chunker.isTraining = true; // Run the learner for (int i = 1; i <= iter; i++) { LinkedVector ex; while ((ex = (LinkedVector) parser.next()) != null) { for (int j = 0; j < ex.size(); j++) { chunker.learn(ex.get(j)); } } parser.reset(); chunker.doneWithRound(); logger.info("Iteration number : " + i); } chunker.doneLearning(); }
/** * This method returns {@link Token}s until the input is exhausted, at * which point it returns <code>null</code>. **/ public Object next() { while (next == null) { LinkedVector words = (LinkedVector) parser.next(); if (words == null) return null; Word w = (Word) words.get(0); Token t = new Token(w, null, null); for (w = (Word) w.next; w != null; w = (Word) w.next) { t.next = new Token(w, t, null); t = (Token) t.next; } LinkedVector tokens = new LinkedVector(t); next = (Token) tokens.get(0); } Token result = next; next = (Token) next.next; return result; }
/** * This method returns {@link Token}s until the input is exhausted, at * which point it returns <code>null</code>. **/ public Object next() { while (next == null) { LinkedVector words = (LinkedVector) parser.next(); if (words == null) return null; Word w = (Word) words.get(0); Token t = new Token(w, null, null); for (w = (Word) w.next; w != null; w = (Word) w.next) { t.next = new Token(w, t, null); t = (Token) t.next; } LinkedVector tokens = new LinkedVector(t); next = (Token) tokens.get(0); } Token result = next; next = (Token) next.next; return result; }
/** * prints Bayraktar baseline performance based on only those commas whose Bayraktar patterns * have been annotated */ public static EvaluateDiscrete getBayraktarBaselinePerformance(Parser parser, boolean testOnGold) { parser.reset(); EvaluateDiscrete bayraktarEvaluation = new EvaluateDiscrete(); Comma comma; while ((comma = (Comma) parser.next()) != null) { if (!BayraktarPatternLabeler.isLabelAvailable(comma)) continue; Comma.useGoldFeatures(true); String goldLabel = comma.getLabel(); Comma.useGoldFeatures(testOnGold); String bayraktarPrediction = comma.getBayraktarLabel(); bayraktarEvaluation.reportPrediction(bayraktarPrediction, goldLabel); } return bayraktarEvaluation; }
/** * prints Bayraktar baseline performance based on only those commas whose Bayraktar patterns * have been annotated */ public static EvaluateDiscrete getBayraktarBaselinePerformance(Parser parser, boolean testOnGold) { parser.reset(); EvaluateDiscrete bayraktarEvaluation = new EvaluateDiscrete(); Comma comma; while ((comma = (Comma) parser.next()) != null) { if (!BayraktarPatternLabeler.isLabelAvailable(comma)) continue; Comma.useGoldFeatures(true); String goldLabel = comma.getLabel(); Comma.useGoldFeatures(testOnGold); String bayraktarPrediction = comma.getBayraktarLabel(); bayraktarEvaluation.reportPrediction(bayraktarPrediction, goldLabel); } return bayraktarEvaluation; }