Search in sources :

Example 1 with TreeReaderFactory

use of edu.stanford.nlp.trees.TreeReaderFactory 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 TreeReaderFactory

use of edu.stanford.nlp.trees.TreeReaderFactory 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 TreeReaderFactory

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

the class TregexGUI method loadPreferences.

/**
   * Load and apply application preferences.
   */
void loadPreferences() {
    //general parameters
    InputPanel.getInstance().enableTsurgeon(Preferences.getEnableTsurgeon());
    MatchesPanel.getInstance().setShowOnlyMatchedPortion(Preferences.getMatchPortionOnly());
    //display stuff
    MatchesPanel.getInstance().setHighlightColor(Preferences.getHighlightColor());
    InputPanel.getInstance().setNumRecentPatterns(Preferences.getHistorySize());
    MatchesPanel.getInstance().setMaxMatches(Preferences.getMaxMatches());
    //tree display stuff
    DisplayMatchesPanel.getInstance().setMatchedColor(Preferences.getMatchedColor());
    DisplayMatchesPanel.getInstance().setDefaultColor(Preferences.getTreeColor());
    DisplayMatchesPanel.getInstance().setFontName(Preferences.getFont());
    MatchesPanel.getInstance().setFontName(Preferences.getFont());
    int fontSize = Preferences.getFontSize();
    if (fontSize != 0)
        DisplayMatchesPanel.getInstance().setFontSize(Preferences.getFontSize());
    //advanced stuff
    HeadFinder hf = Preferences.getHeadFinder();
    InputPanel.getInstance().setHeadFinder(hf);
    TreeReaderFactory trf = Preferences.getTreeReaderFactory();
    FilePanel.getInstance().setTreeReaderFactory(trf);
    String hfName = hf.getClass().getSimpleName();
    String trfName = trf.getClass().getSimpleName();
    String encoding = Preferences.getEncoding();
    if (encoding != null && !encoding.equals(""))
        FileTreeModel.setCurEncoding(encoding);
    if (PreferencesPanel.isChinese(hfName, trfName))
        setChineseFont();
    else if (PreferencesPanel.isArabic(hfName, trfName))
        setArabicFont();
    if (preferenceDialog == null)
        preferenceDialog = new PreferencesPanel(this);
    preferenceDialog.checkEncodingAndDisplay(hfName, trfName);
}
Also used : HeadFinder(edu.stanford.nlp.trees.HeadFinder) TreeReaderFactory(edu.stanford.nlp.trees.TreeReaderFactory)

Example 4 with TreeReaderFactory

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

the class FrenchXMLTreeReader method main.

/**
   * For debugging.
   *
   * @param args
   */
public static void main(String[] args) {
    if (args.length < 1) {
        System.err.printf("Usage: java %s tree_file(s)%n%n", FrenchXMLTreeReader.class.getName());
        System.exit(-1);
    }
    List<File> fileList = new ArrayList<>();
    for (String arg : args) fileList.add(new File(arg));
    TreeReaderFactory trf = new FrenchXMLTreeReaderFactory(false);
    int totalTrees = 0;
    Set<String> morphAnalyses = Generics.newHashSet();
    try {
        for (File file : fileList) {
            TreeReader tr = trf.newTreeReader(new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")));
            Tree t;
            int numTrees;
            String canonicalFileName = file.getName().substring(0, file.getName().lastIndexOf('.'));
            for (numTrees = 0; (t = tr.readTree()) != null; numTrees++) {
                String ftbID = ((CoreLabel) t.label()).get(CoreAnnotations.SentenceIDAnnotation.class);
                System.out.printf("%s-%s\t%s%n", canonicalFileName, ftbID, t.toString());
                List<Label> leaves = t.yield();
                for (Label label : leaves) {
                    if (label instanceof CoreLabel)
                        morphAnalyses.add(((CoreLabel) label).originalText());
                }
            }
            tr.close();
            System.err.printf("%s: %d trees%n", file.getName(), numTrees);
            totalTrees += numTrees;
        }
        //wsg2011: Print out the observed morphological analyses
        //      for(String analysis : morphAnalyses)
        //        log.info(analysis);
        System.err.printf("%nRead %d trees%n", totalTrees);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : TreeReader(edu.stanford.nlp.trees.TreeReader) Tree(edu.stanford.nlp.trees.Tree) TreeReaderFactory(edu.stanford.nlp.trees.TreeReaderFactory)

Example 5 with TreeReaderFactory

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

the class SplitMaker method main.

/**
   * @param args
   */
public static void main(String[] args) {
    if (args.length != 1) {
        System.err.printf("Usage: java %s tree_file%n", SplitMaker.class.getName());
        System.exit(-1);
    }
    TreebankLanguagePack tlp = new HebrewTreebankLanguagePack();
    String inputFile = args[0];
    File treeFile = new File(inputFile);
    try {
        TreeReaderFactory trf = new HebrewTreeReaderFactory();
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(treeFile), tlp.getEncoding()));
        TreeReader tr = trf.newTreeReader(br);
        PrintWriter pwDev = new PrintWriter(new PrintStream(new FileOutputStream(inputFile + ".clean.dev"), false, tlp.getEncoding()));
        PrintWriter pwTrain = new PrintWriter(new PrintStream(new FileOutputStream(inputFile + ".clean.train"), false, tlp.getEncoding()));
        PrintWriter pwTest = new PrintWriter(new PrintStream(new FileOutputStream(inputFile + ".clean.test"), false, tlp.getEncoding()));
        int numTrees = 0;
        for (Tree t; ((t = tr.readTree()) != null); numTrees++) {
            if (numTrees < 483)
                pwDev.println(t.toString());
            else if (numTrees >= 483 && numTrees < 5724)
                pwTrain.println(t.toString());
            else
                pwTest.println(t.toString());
        }
        tr.close();
        pwDev.close();
        pwTrain.close();
        pwTest.close();
        System.err.printf("Processed %d trees.%n", numTrees);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : TreeReader(edu.stanford.nlp.trees.TreeReader) Tree(edu.stanford.nlp.trees.Tree) TreebankLanguagePack(edu.stanford.nlp.trees.TreebankLanguagePack) TreeReaderFactory(edu.stanford.nlp.trees.TreeReaderFactory)

Aggregations

TreeReaderFactory (edu.stanford.nlp.trees.TreeReaderFactory)23 Tree (edu.stanford.nlp.trees.Tree)20 TreeReader (edu.stanford.nlp.trees.TreeReader)17 FrenchTreeReaderFactory (edu.stanford.nlp.trees.international.french.FrenchTreeReaderFactory)7 FileInputStream (java.io.FileInputStream)7 InputStreamReader (java.io.InputStreamReader)7 BufferedReader (java.io.BufferedReader)6 IOException (java.io.IOException)6 FileNotFoundException (java.io.FileNotFoundException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 CoreLabel (edu.stanford.nlp.ling.CoreLabel)4 ArabicTreeReaderFactory (edu.stanford.nlp.trees.international.arabic.ArabicTreeReaderFactory)4 TwoDimensionalCounter (edu.stanford.nlp.stats.TwoDimensionalCounter)3 LabeledScoredTreeReaderFactory (edu.stanford.nlp.trees.LabeledScoredTreeReaderFactory)3 TreeTransformer (edu.stanford.nlp.trees.TreeTransformer)3 TreebankLanguagePack (edu.stanford.nlp.trees.TreebankLanguagePack)3 FrenchXMLTreeReader (edu.stanford.nlp.trees.international.french.FrenchXMLTreeReader)3 SpanishTreeReaderFactory (edu.stanford.nlp.trees.international.spanish.SpanishTreeReaderFactory)3 Label (edu.stanford.nlp.ling.Label)2 PennTreeReader (edu.stanford.nlp.trees.PennTreeReader)2