use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class Decoder method clearPredictions.
public static void clearPredictions(Data data) {
for (int docid = 0; docid < data.documents.size(); docid++) {
ArrayList<LinkedVector> sentences = data.documents.get(docid).sentences;
for (LinkedVector sentence : sentences) {
for (int i = 0; i < sentence.size(); i++) {
((NEWord) sentence.get(i)).neTypeLevel1 = null;
((NEWord) sentence.get(i)).neTypeLevel2 = null;
}
}
}
}
use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class NEDisplayPredictions method reportPredictions.
/**
* Report the results.
*
* @param dataSet the parsed and annotated data.
*/
public static void reportPredictions(Data dataSet) {
for (int docid = 0; docid < dataSet.documents.size(); docid++) {
NERDocument doc = dataSet.documents.get(docid);
System.out.println("\nGetting document " + doc.docname);
ArrayList<LinkedVector> sentences = doc.sentences;
for (int k = 0; k < sentences.size(); k++) {
LinkedVector sentence = sentences.get(k);
int N = sentence.size();
for (int i = 0; i < N; ++i) {
NEWord word = (NEWord) sentence.get(i);
System.out.println(word.form + "\tL:" + word.neLabel + "\t1:" + word.neTypeLevel1 + "\t2:" + word.neTypeLevel2 + "\t(" + doc.docname + ")");
for (String h2 : word.gazetteers) System.out.print(" " + h2);
System.out.println();
}
}
}
}
use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class TextChunkRepresentationManager method Bio2IOB.
// ------------------- IOB1 ---------------------------
private static void Bio2IOB(Data data, LabelToLookAt labelType) {
for (int docid = 0; docid < data.documents.size(); docid++) {
ArrayList<LinkedVector> sentences = data.documents.get(docid).sentences;
for (LinkedVector v : sentences) {
for (int j = 0; j < v.size(); j++) {
NEWord w = (NEWord) v.get(j);
String label = w.getPrediction(labelType);
if (label != null && !label.equalsIgnoreCase("O")) {
label = label.substring(2);
NEWord prev = (NEWord) w.previous;
String prevLabel = "O";
if (prev != null)
prevLabel = prev.getPrediction(labelType);
if (prevLabel.contains("-"))
prevLabel = prevLabel.substring(2);
if ((!prevLabel.equals(label)) && w.getPrediction(labelType).startsWith("B-"))
w.setPrediction("I-" + label, labelType);
}
}
}
}
}
use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class TextChunkRepresentationManager method IOB2Bio.
private static void IOB2Bio(Data data, LabelToLookAt labelType) {
for (int docid = 0; docid < data.documents.size(); docid++) {
ArrayList<LinkedVector> sentences = data.documents.get(docid).sentences;
for (LinkedVector v : sentences) {
for (int j = 0; j < v.size(); j++) {
NEWord w = (NEWord) v.get(j);
String label = w.getPrediction(labelType);
if (label != null && !label.equalsIgnoreCase("O")) {
label = label.substring(2);
NEWord prev = (NEWord) w.previous;
String prevLabel = "O";
if (prev != null)
prevLabel = prev.getPrediction(labelType);
if (prevLabel.contains("-"))
prevLabel = prevLabel.substring(2);
if (!prevLabel.equalsIgnoreCase(label))
w.setPrediction("B-" + label, labelType);
}
}
}
}
}
use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class ColumnFileReader method next.
public Object next() {
String token = null;
String pos = null;
String label = null;
linec++;
// Skip to start of next line, skip unnecessary blank lines, headers and so on.
String[] line = (String[]) super.next();
while (line != null && (line.length == 0 || (line.length > 4 && line[4].equals("-X-")))) {
line = (String[]) super.next();
linec++;
}
if (line == null)
return null;
// parse the data, CoNLL 2002 or CoNLL 2003.
if (line.length == 2) {
token = line[0];
label = line[1];
} else {
token = line[5];
label = line[0];
pos = line[4];
}
LinkedVector res = new LinkedVector();
NEWord w = new NEWord(new Word(token, pos), null, label);
NEWord.addTokenToSentence(res, w.form, w.neLabel);
for (line = (String[]) super.next(); line != null && line.length > 0; line = (String[]) super.next()) {
linec++;
// parse the data, CoNLL 2002 or CoNLL 2003.
if (line.length == 2) {
token = line[0];
label = line[1];
} else if (line.length > 5) {
token = line[5];
label = line[0];
pos = line[4];
} else {
System.out.println("Line " + linec + " in " + filename + " is wrong with " + line.length);
for (String a : line) System.out.print(":" + a);
System.out.println();
continue;
}
w = new NEWord(new Word(token, pos), null, label);
NEWord.addTokenToSentence(res, w.form, w.neLabel);
}
if (res.size() == 0)
return null;
return res;
}
Aggregations