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();
}
}
}
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!");
}
}
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);
}
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();
}
}
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();
}
}
Aggregations