Search in sources :

Example 31 with LinkedVector

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

Example 32 with LinkedVector

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

Example 33 with LinkedVector

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

Example 34 with LinkedVector

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

Example 35 with LinkedVector

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

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