use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class TextChunkRepresentationManager method IOEa2Bio.
private static void IOEa2Bio(Data data, LabelToLookAt labelType) {
for (int docid = 0; docid < data.documents.size(); docid++) {
ArrayList<LinkedVector> sentences = data.documents.get(docid).sentences;
for (int i = sentences.size() - 1; i >= 0; i--) {
LinkedVector v = sentences.get(i);
for (int j = v.size() - 1; j >= 0; j--) {
NEWord w = (NEWord) v.get(j);
String label = w.getPrediction(labelType);
if (label != null && !label.equalsIgnoreCase("O")) {
String labelSuffix = label.substring(2);
NEWord prev = (NEWord) w.previous;
String prevLabel = "O";
String prevLabelSuffix = "O";
if (prev != null)
prevLabel = prev.getPrediction(labelType);
if (prevLabel.contains("-"))
prevLabelSuffix = prevLabel.substring(2);
if ((!prevLabelSuffix.equalsIgnoreCase(labelSuffix)) || (prevLabel.startsWith("E-")))
w.setPrediction("B-" + labelSuffix, labelType);
if (w.getPrediction(labelType).startsWith("E-"))
w.setPrediction("I-" + labelSuffix, labelType);
}
}
}
}
}
use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class TextChunkRepresentationManager method Bio2IOEb.
// ----------------------- IOE2 -------------------
private static void Bio2IOEb(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")) {
String labelSuffix = label.substring(2);
NEWord next = (NEWord) w.next;
String nextLabel = "O";
String nextLabelSuffix = "O";
if (next != null) {
nextLabel = next.getPrediction(labelType);
nextLabelSuffix = nextLabel;
}
if (nextLabel.contains("-"))
nextLabelSuffix = nextLabel.substring(2);
if ((!nextLabelSuffix.equals(labelSuffix)) || nextLabel.startsWith("B-"))
w.setPrediction("E-" + labelSuffix, labelType);
else if (w.getPrediction(labelType).startsWith("B-"))
w.setPrediction("I-" + labelSuffix, labelType);
}
}
}
}
}
use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class TextChunkRepresentationManager method Bio2Bilou.
// ------------- BILOU -----------------
private static void Bio2Bilou(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;
NEWord next = (NEWord) w.next;
String nextType = "O";
String nextLabel = "O";
String prevType = "O";
if (next != null) {
nextType = next.getPrediction(labelType);
nextLabel = next.getPrediction(labelType);
}
if (nextType.contains("-"))
nextType = nextType.substring(2);
if (prev != null)
prevType = prev.getPrediction(labelType);
if (prevType.contains("-"))
prevType = prevType.substring(2);
if ((!nextType.equalsIgnoreCase(label)) && (!prevType.equalsIgnoreCase(label)))
w.setPrediction("U-" + label, labelType);
else if (((!nextType.equalsIgnoreCase(label)) || nextLabel.startsWith("B-")) && (w.getPrediction(labelType).startsWith("B-")))
w.setPrediction("U-" + label, labelType);
else if ((!nextType.equalsIgnoreCase(label)) && (prevType.equalsIgnoreCase(label)))
w.setPrediction("L-" + label, labelType);
}
}
}
}
}
use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class TextChunkRepresentationManager method Bilou2Bio.
private static void Bilou2Bio(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.equalsIgnoreCase("O")) {
if (w.getPrediction(labelType).startsWith("U-"))
w.setPrediction("B-" + label.substring(2), labelType);
if (w.getPrediction(labelType).startsWith("L-"))
w.setPrediction("I-" + label.substring(2), labelType);
}
}
}
}
}
use of edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector in project cogcomp-nlp by CogComp.
the class TextChunkRepresentationManager method Bio2IOEa.
// ----------------------- IOE1 -------------------
private static void Bio2IOEa(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")) {
String labelSuffix = label.substring(2);
NEWord next = (NEWord) w.next;
String nextLabel = "O";
String nextLabelSuffix = "O";
if (next != null) {
nextLabel = next.getPrediction(labelType);
nextLabelSuffix = nextLabel;
}
if (nextLabel.contains("-"))
nextLabelSuffix = nextLabel.substring(2);
if ((nextLabelSuffix.equals(labelSuffix)) && nextLabel.startsWith("B-"))
w.setPrediction("E-" + labelSuffix, labelType);
else if (label.startsWith("B-"))
w.setPrediction("I-" + labelSuffix, labelType);
}
}
}
}
}
Aggregations