Search in sources :

Example 16 with LinkedVector

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);
                }
            }
        }
    }
}
Also used : LinkedVector(edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector)

Example 17 with LinkedVector

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);
                }
            }
        }
    }
}
Also used : LinkedVector(edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector)

Example 18 with LinkedVector

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);
                }
            }
        }
    }
}
Also used : LinkedVector(edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector)

Example 19 with LinkedVector

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);
                }
            }
        }
    }
}
Also used : LinkedVector(edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector)

Example 20 with LinkedVector

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);
                }
            }
        }
    }
}
Also used : LinkedVector(edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector)

Aggregations

LinkedVector (edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector)46 Word (edu.illinois.cs.cogcomp.lbjava.nlp.Word)9 NEWord (edu.illinois.cs.cogcomp.ner.LbjTagger.NEWord)9 ArrayList (java.util.ArrayList)8 Vector (java.util.Vector)8 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)3 Sentence (edu.illinois.cs.cogcomp.lbjava.nlp.Sentence)3 SentenceSplitter (edu.illinois.cs.cogcomp.lbjava.nlp.SentenceSplitter)3 NERDocument (edu.illinois.cs.cogcomp.ner.LbjTagger.NERDocument)3 File (java.io.File)3 HashMap (java.util.HashMap)3 Sentence (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Sentence)2 Token (edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token)2 OutFile (edu.illinois.cs.cogcomp.ner.IO.OutFile)2 Matcher (java.util.regex.Matcher)2 ChunkLabel (edu.illinois.cs.cogcomp.chunker.main.lbjava.ChunkLabel)1 Chunker (edu.illinois.cs.cogcomp.chunker.main.lbjava.Chunker)1 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)1 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)1 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)1