Search in sources :

Example 1 with ModCollinsHeadFinder

use of edu.stanford.nlp.trees.ModCollinsHeadFinder in project CoreNLP by stanfordnlp.

the class Preferences method lookupHeadFinder.

static HeadFinder lookupHeadFinder(String headfinderName) {
    if (headfinderName.equalsIgnoreCase("ArabicHeadFinder")) {
        return new ArabicHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("BikelChineseHeadFinder")) {
        return new BikelChineseHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("ChineseHeadFinder")) {
        return new ChineseHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("ChineseSemanticHeadFinder")) {
        return new ChineseSemanticHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("CollinsHeadFinder")) {
        return new CollinsHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("DybroFrenchHeadFinder")) {
        return new DybroFrenchHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("LeftHeadFinder")) {
        return new LeftHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("ModCollinsHeadFinder")) {
        return new ModCollinsHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("NegraHeadFinder")) {
        return new NegraHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("SemanticHeadFinder")) {
        return new SemanticHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("SunJurafskyChineseHeadFinder")) {
        return new SunJurafskyChineseHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("TueBaDZHeadFinder")) {
        return new TueBaDZHeadFinder();
    } else if (headfinderName.equalsIgnoreCase("UniversalSemanticHeadFinder")) {
        return new UniversalSemanticHeadFinder();
    } else {
        //try to find the class
        try {
            Class<?> headfinder = Class.forName(headfinderName);
            HeadFinder hf = (HeadFinder) headfinder.newInstance();
            return hf;
        } catch (Exception e) {
            return null;
        }
    }
}
Also used : ChineseSemanticHeadFinder(edu.stanford.nlp.trees.international.pennchinese.ChineseSemanticHeadFinder) ModCollinsHeadFinder(edu.stanford.nlp.trees.ModCollinsHeadFinder) BikelChineseHeadFinder(edu.stanford.nlp.trees.international.pennchinese.BikelChineseHeadFinder) ChineseHeadFinder(edu.stanford.nlp.trees.international.pennchinese.ChineseHeadFinder) SunJurafskyChineseHeadFinder(edu.stanford.nlp.trees.international.pennchinese.SunJurafskyChineseHeadFinder) DybroFrenchHeadFinder(edu.stanford.nlp.trees.international.french.DybroFrenchHeadFinder) LeftHeadFinder(edu.stanford.nlp.trees.LeftHeadFinder) TueBaDZHeadFinder(edu.stanford.nlp.trees.international.tuebadz.TueBaDZHeadFinder) ArabicHeadFinder(edu.stanford.nlp.trees.international.arabic.ArabicHeadFinder) NegraHeadFinder(edu.stanford.nlp.trees.international.negra.NegraHeadFinder) UniversalSemanticHeadFinder(edu.stanford.nlp.trees.UniversalSemanticHeadFinder) ChineseSemanticHeadFinder(edu.stanford.nlp.trees.international.pennchinese.ChineseSemanticHeadFinder) UniversalSemanticHeadFinder(edu.stanford.nlp.trees.UniversalSemanticHeadFinder) SemanticHeadFinder(edu.stanford.nlp.trees.SemanticHeadFinder) ChineseSemanticHeadFinder(edu.stanford.nlp.trees.international.pennchinese.ChineseSemanticHeadFinder) DybroFrenchHeadFinder(edu.stanford.nlp.trees.international.french.DybroFrenchHeadFinder) BikelChineseHeadFinder(edu.stanford.nlp.trees.international.pennchinese.BikelChineseHeadFinder) TueBaDZHeadFinder(edu.stanford.nlp.trees.international.tuebadz.TueBaDZHeadFinder) ChineseHeadFinder(edu.stanford.nlp.trees.international.pennchinese.ChineseHeadFinder) CollinsHeadFinder(edu.stanford.nlp.trees.CollinsHeadFinder) UniversalSemanticHeadFinder(edu.stanford.nlp.trees.UniversalSemanticHeadFinder) NegraHeadFinder(edu.stanford.nlp.trees.international.negra.NegraHeadFinder) ModCollinsHeadFinder(edu.stanford.nlp.trees.ModCollinsHeadFinder) SunJurafskyChineseHeadFinder(edu.stanford.nlp.trees.international.pennchinese.SunJurafskyChineseHeadFinder) HeadFinder(edu.stanford.nlp.trees.HeadFinder) LeftHeadFinder(edu.stanford.nlp.trees.LeftHeadFinder) SemanticHeadFinder(edu.stanford.nlp.trees.SemanticHeadFinder) ArabicHeadFinder(edu.stanford.nlp.trees.international.arabic.ArabicHeadFinder) CollinsHeadFinder(edu.stanford.nlp.trees.CollinsHeadFinder) ModCollinsHeadFinder(edu.stanford.nlp.trees.ModCollinsHeadFinder) SunJurafskyChineseHeadFinder(edu.stanford.nlp.trees.international.pennchinese.SunJurafskyChineseHeadFinder) BikelChineseHeadFinder(edu.stanford.nlp.trees.international.pennchinese.BikelChineseHeadFinder)

Example 2 with ModCollinsHeadFinder

use of edu.stanford.nlp.trees.ModCollinsHeadFinder in project CoreNLP by stanfordnlp.

the class CoNLLDocumentReader method writeTabSep.

public static void writeTabSep(PrintWriter pw, CoreMap sentence, CollectionValuedMap<String, CoreMap> chainmap) {
    HeadFinder headFinder = new ModCollinsHeadFinder();
    List<CoreLabel> sentenceAnno = sentence.get(CoreAnnotations.TokensAnnotation.class);
    Tree sentenceTree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
    Map<Pair<Integer, Integer>, String> sentenceInfo = Generics.newHashMap();
    Set<Tree> sentenceSubTrees = sentenceTree.subTrees();
    sentenceTree.setSpans();
    Map<Pair<Integer, Integer>, Tree> treeSpanMap = Generics.newHashMap();
    Map<Pair<Integer, Integer>, List<Tree>> wordSpanMap = Generics.newHashMap();
    for (Tree ctree : sentenceSubTrees) {
        IntPair span = ctree.getSpan();
        if (span != null) {
            treeSpanMap.put(Pair.makePair(span.getSource(), span.getTarget()), ctree);
            wordSpanMap.put(Pair.makePair(span.getSource(), span.getTarget()), ctree.getLeaves());
        }
    }
    String[][] finalSentence;
    finalSentence = new String[sentenceAnno.size()][];
    Map<Pair<Integer, Integer>, String> allHeads = Generics.newHashMap();
    int index = -1;
    for (CoreLabel newAnno : sentenceAnno) {
        index += 1;
        String word = newAnno.word();
        String tag = newAnno.tag();
        String cat = newAnno.ner();
        String coref = newAnno.get(CorefCoreAnnotations.CorefAnnotation.class);
        finalSentence[index] = new String[4];
        finalSentence[index][0] = word;
        finalSentence[index][1] = tag;
        finalSentence[index][2] = cat;
        finalSentence[index][3] = coref;
        if (coref == null) {
            sentenceInfo.put(Pair.makePair(index, index), coref);
            finalSentence[index][3] = "O";
        } else {
            String[] allC = coref.split("\\|");
            for (String corefG : allC) {
                Pair<Integer, Integer> mention = getMention(index, corefG, sentenceAnno);
                if (!include(sentenceInfo, mention, corefG)) {
                    // find largest NP in mention
                    sentenceInfo.put(mention, corefG);
                    Tree mentionTree = treeSpanMap.get(mention);
                    String head = null;
                    if (mentionTree != null) {
                        head = mentionTree.headTerminal(headFinder).nodeString();
                    } else if (mention.first.equals(mention.second)) {
                        head = word;
                    }
                    allHeads.put(mention, head);
                }
            }
            if (allHeads.values().contains(word)) {
                finalSentence[index][3] = "MENTION";
            } else {
                finalSentence[index][3] = "O";
            }
        }
    }
    for (int i = 0; i < finalSentence.length; i++) {
        String[] wordInfo = finalSentence[i];
        if (i < finalSentence.length - 1) {
            String[] nextWordInfo = finalSentence[i + 1];
            if (nextWordInfo[3].equals("MENTION") && nextWordInfo[0].equals("'s")) {
                wordInfo[3] = "MENTION";
                finalSentence[i + 1][3] = "O";
            }
        }
        pw.println(wordInfo[0] + "\t" + wordInfo[1] + "\t" + wordInfo[2] + "\t" + wordInfo[3]);
    }
    pw.println("");
}
Also used : ModCollinsHeadFinder(edu.stanford.nlp.trees.ModCollinsHeadFinder) TreeCoreAnnotations(edu.stanford.nlp.trees.TreeCoreAnnotations) CorefCoreAnnotations(edu.stanford.nlp.coref.CorefCoreAnnotations) IntPair(edu.stanford.nlp.util.IntPair) ModCollinsHeadFinder(edu.stanford.nlp.trees.ModCollinsHeadFinder) HeadFinder(edu.stanford.nlp.trees.HeadFinder) ChineseSemanticHeadFinder(edu.stanford.nlp.trees.international.pennchinese.ChineseSemanticHeadFinder) CoreLabel(edu.stanford.nlp.ling.CoreLabel) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) TreeCoreAnnotations(edu.stanford.nlp.trees.TreeCoreAnnotations) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) CorefCoreAnnotations(edu.stanford.nlp.coref.CorefCoreAnnotations) Tree(edu.stanford.nlp.trees.Tree) List(java.util.List) ArrayList(java.util.ArrayList) IntPair(edu.stanford.nlp.util.IntPair) Pair(edu.stanford.nlp.util.Pair)

Aggregations

HeadFinder (edu.stanford.nlp.trees.HeadFinder)2 ModCollinsHeadFinder (edu.stanford.nlp.trees.ModCollinsHeadFinder)2 ChineseSemanticHeadFinder (edu.stanford.nlp.trees.international.pennchinese.ChineseSemanticHeadFinder)2 CorefCoreAnnotations (edu.stanford.nlp.coref.CorefCoreAnnotations)1 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)1 CoreLabel (edu.stanford.nlp.ling.CoreLabel)1 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)1 CollinsHeadFinder (edu.stanford.nlp.trees.CollinsHeadFinder)1 LeftHeadFinder (edu.stanford.nlp.trees.LeftHeadFinder)1 SemanticHeadFinder (edu.stanford.nlp.trees.SemanticHeadFinder)1 Tree (edu.stanford.nlp.trees.Tree)1 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)1 UniversalSemanticHeadFinder (edu.stanford.nlp.trees.UniversalSemanticHeadFinder)1 ArabicHeadFinder (edu.stanford.nlp.trees.international.arabic.ArabicHeadFinder)1 DybroFrenchHeadFinder (edu.stanford.nlp.trees.international.french.DybroFrenchHeadFinder)1 NegraHeadFinder (edu.stanford.nlp.trees.international.negra.NegraHeadFinder)1 BikelChineseHeadFinder (edu.stanford.nlp.trees.international.pennchinese.BikelChineseHeadFinder)1 ChineseHeadFinder (edu.stanford.nlp.trees.international.pennchinese.ChineseHeadFinder)1 SunJurafskyChineseHeadFinder (edu.stanford.nlp.trees.international.pennchinese.SunJurafskyChineseHeadFinder)1 TueBaDZHeadFinder (edu.stanford.nlp.trees.international.tuebadz.TueBaDZHeadFinder)1