Search in sources :

Example 1 with LabeledScoredTreeReaderFactory

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

the class Preferences method lookupTreeReaderFactory.

static TreeReaderFactory lookupTreeReaderFactory(String trfName) {
    if (trfName.equalsIgnoreCase("ArabicTreeReaderFactory")) {
        return new ArabicTreeReaderFactory();
    } else if (trfName.equalsIgnoreCase("ArabicTreeReaderFactory.ArabicRawTreeReaderFactory")) {
        return new ArabicTreeReaderFactory.ArabicRawTreeReaderFactory();
    } else if (trfName.equalsIgnoreCase("CTBTreeReaderFactory")) {
        return new CTBTreeReaderFactory();
    } else if (trfName.equalsIgnoreCase("NoEmptiesCTBTreeReaderFactory")) {
        return new NoEmptiesCTBTreeReaderFactory();
    } else if (trfName.equalsIgnoreCase("Basic categories only (LabeledScoredTreeReaderFactory)")) {
        return new LabeledScoredTreeReaderFactory();
    } else if (trfName.equalsIgnoreCase("FrenchTreeReaderFactory")) {
        //PTB format
        return new FrenchTreeReaderFactory();
    } else if (trfName.equalsIgnoreCase("PennTreeReaderFactory")) {
        return new PennTreeReaderFactory();
    } else if (trfName.equalsIgnoreCase("StringLabeledScoredTreeReaderFactory")) {
        return new StringLabeledScoredTreeReaderFactory();
    } else if (trfName.equalsIgnoreCase("TregexTreeReaderFactory")) {
        return new TregexPattern.TRegexTreeReaderFactory();
    } else {
        //try to find the class
        try {
            Class<?> trfClass = Class.forName(trfName);
            TreeReaderFactory trf = (TreeReaderFactory) trfClass.newInstance();
            return trf;
        } catch (Exception e) {
            return new PennTreeReaderFactory();
        }
    }
}
Also used : ArabicTreeReaderFactory(edu.stanford.nlp.trees.international.arabic.ArabicTreeReaderFactory) StringLabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.StringLabeledScoredTreeReaderFactory) FrenchTreeReaderFactory(edu.stanford.nlp.trees.international.french.FrenchTreeReaderFactory) NoEmptiesCTBTreeReaderFactory(edu.stanford.nlp.trees.international.pennchinese.NoEmptiesCTBTreeReaderFactory) CTBTreeReaderFactory(edu.stanford.nlp.trees.international.pennchinese.CTBTreeReaderFactory) NoEmptiesCTBTreeReaderFactory(edu.stanford.nlp.trees.international.pennchinese.NoEmptiesCTBTreeReaderFactory) PennTreeReaderFactory(edu.stanford.nlp.trees.PennTreeReaderFactory) FrenchTreeReaderFactory(edu.stanford.nlp.trees.international.french.FrenchTreeReaderFactory) CTBTreeReaderFactory(edu.stanford.nlp.trees.international.pennchinese.CTBTreeReaderFactory) StringLabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.StringLabeledScoredTreeReaderFactory) NoEmptiesCTBTreeReaderFactory(edu.stanford.nlp.trees.international.pennchinese.NoEmptiesCTBTreeReaderFactory) PennTreeReaderFactory(edu.stanford.nlp.trees.PennTreeReaderFactory) TreeReaderFactory(edu.stanford.nlp.trees.TreeReaderFactory) LabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.LabeledScoredTreeReaderFactory) ArabicTreeReaderFactory(edu.stanford.nlp.trees.international.arabic.ArabicTreeReaderFactory) StringLabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.StringLabeledScoredTreeReaderFactory) LabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.LabeledScoredTreeReaderFactory)

Example 2 with LabeledScoredTreeReaderFactory

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

the class Tdiff method main.

/**
   * @param args
   */
public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("Usage: java Tdiff tree1 tree2");
        return;
    }
    File tree1Path = new File(args[0]);
    File tree2Path = new File(args[1]);
    try {
        TreeReaderFactory trf = new LabeledScoredTreeReaderFactory();
        TreeReader tR1 = trf.newTreeReader(new BufferedReader(new FileReader(tree1Path)));
        TreeReader tR2 = trf.newTreeReader(new BufferedReader(new FileReader(tree2Path)));
        Tree t1 = tR1.readTree();
        Tree t2 = tR2.readTree();
        Set<Constituent> t1Diff = markDiff(t1, t2);
        System.out.println(t2.pennString());
        System.out.println();
        for (Constituent c : t1Diff) System.out.println(c);
    } catch (FileNotFoundException e) {
        log.info("File not found!");
    } catch (IOException e) {
        log.info("Unable to read file!");
    }
}
Also used : TreeReader(edu.stanford.nlp.trees.TreeReader) Tree(edu.stanford.nlp.trees.Tree) TreeReaderFactory(edu.stanford.nlp.trees.TreeReaderFactory) LabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.LabeledScoredTreeReaderFactory) LabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.LabeledScoredTreeReaderFactory) Constituent(edu.stanford.nlp.trees.Constituent) LabeledConstituent(edu.stanford.nlp.trees.LabeledConstituent)

Example 3 with LabeledScoredTreeReaderFactory

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

the class ThreadedParserSlowITest method readTrees.

public static List<Tree> readTrees(String filename, String encoding) {
    ArrayList<Tree> trees = new ArrayList<Tree>();
    try {
        TreeReaderFactory trf = new LabeledScoredTreeReaderFactory();
        TreeReader tr = trf.newTreeReader(new InputStreamReader(new FileInputStream(filename), encoding));
        Tree next;
        while ((next = tr.readTree()) != null) {
            trees.add(next);
        }
        System.out.println("Read " + trees.size() + " trees from " + filename);
        return trees;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Tree(edu.stanford.nlp.trees.Tree) TreeReader(edu.stanford.nlp.trees.TreeReader) TreeReaderFactory(edu.stanford.nlp.trees.TreeReaderFactory) LabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.LabeledScoredTreeReaderFactory) IOException(java.io.IOException) LabeledScoredTreeReaderFactory(edu.stanford.nlp.trees.LabeledScoredTreeReaderFactory) FileInputStream(java.io.FileInputStream)

Aggregations

LabeledScoredTreeReaderFactory (edu.stanford.nlp.trees.LabeledScoredTreeReaderFactory)3 TreeReaderFactory (edu.stanford.nlp.trees.TreeReaderFactory)3 Tree (edu.stanford.nlp.trees.Tree)2 TreeReader (edu.stanford.nlp.trees.TreeReader)2 Constituent (edu.stanford.nlp.trees.Constituent)1 LabeledConstituent (edu.stanford.nlp.trees.LabeledConstituent)1 PennTreeReaderFactory (edu.stanford.nlp.trees.PennTreeReaderFactory)1 StringLabeledScoredTreeReaderFactory (edu.stanford.nlp.trees.StringLabeledScoredTreeReaderFactory)1 ArabicTreeReaderFactory (edu.stanford.nlp.trees.international.arabic.ArabicTreeReaderFactory)1 FrenchTreeReaderFactory (edu.stanford.nlp.trees.international.french.FrenchTreeReaderFactory)1 CTBTreeReaderFactory (edu.stanford.nlp.trees.international.pennchinese.CTBTreeReaderFactory)1 NoEmptiesCTBTreeReaderFactory (edu.stanford.nlp.trees.international.pennchinese.NoEmptiesCTBTreeReaderFactory)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1