use of edu.stanford.nlp.trees.TreeTransformer in project CoreNLP by stanfordnlp.
the class TaggedFileRecord method createRecord.
public static TaggedFileRecord createRecord(Properties config, String description) {
String[] pieces = description.split(",");
if (pieces.length == 1) {
return new TaggedFileRecord(description, Format.TEXT, getEncoding(config), getTagSeparator(config), null, null, null, null, null, null, null);
}
String[] args = new String[pieces.length - 1];
System.arraycopy(pieces, 0, args, 0, pieces.length - 1);
String file = pieces[pieces.length - 1];
Format format = Format.TEXT;
String encoding = getEncoding(config);
String tagSeparator = getTagSeparator(config);
TreeTransformer treeTransformer = null;
TreeNormalizer treeNormalizer = null;
TreeReaderFactory trf = null;
NumberRangesFileFilter treeRange = null;
Predicate<Tree> treeFilter = null;
Integer wordColumn = null, tagColumn = null;
for (String arg : args) {
String[] argPieces = arg.split("=", 2);
if (argPieces.length != 2) {
throw new IllegalArgumentException("TaggedFileRecord argument " + arg + " has an unexpected number of =s");
}
if (argPieces[0].equalsIgnoreCase(FORMAT)) {
format = Format.valueOf(argPieces[1]);
} else if (argPieces[0].equalsIgnoreCase(ENCODING)) {
encoding = argPieces[1];
} else if (argPieces[0].equalsIgnoreCase(TAG_SEPARATOR)) {
tagSeparator = argPieces[1];
} else if (argPieces[0].equalsIgnoreCase(TREE_TRANSFORMER)) {
treeTransformer = ReflectionLoading.loadByReflection(argPieces[1]);
} else if (argPieces[0].equalsIgnoreCase(TREE_NORMALIZER)) {
treeNormalizer = ReflectionLoading.loadByReflection(argPieces[1]);
} else if (argPieces[0].equalsIgnoreCase(TREE_READER)) {
trf = ReflectionLoading.loadByReflection(argPieces[1]);
} else if (argPieces[0].equalsIgnoreCase(TREE_RANGE)) {
String range = argPieces[1].replaceAll(":", ",");
treeRange = new NumberRangesFileFilter(range, true);
} else if (argPieces[0].equalsIgnoreCase(TREE_FILTER)) {
treeFilter = ReflectionLoading.loadByReflection(argPieces[1]);
} else if (argPieces[0].equalsIgnoreCase(WORD_COLUMN)) {
wordColumn = Integer.valueOf(argPieces[1]);
} else if (argPieces[0].equalsIgnoreCase(TAG_COLUMN)) {
tagColumn = Integer.valueOf(argPieces[1]);
} else {
throw new IllegalArgumentException("TaggedFileRecord argument " + argPieces[0] + " is unknown");
}
}
return new TaggedFileRecord(file, format, encoding, tagSeparator, treeTransformer, treeNormalizer, trf, treeRange, treeFilter, wordColumn, tagColumn);
}
use of edu.stanford.nlp.trees.TreeTransformer in project CoreNLP by stanfordnlp.
the class FileTreeModel method addFileFolder.
/**
* Forks off a new thread to load your files based on the filters you set in the interface
*/
public void addFileFolder(final EnumMap<FilterType, String> filters, final File[] files) {
List<FileTreeNode> newFiles = new ArrayList<>();
//findLoadableFiles updates newFiles
findLoadableFiles(filters, files, newFiles, FileTreeModel.this.getRoot());
for (FileTreeNode fileNode : newFiles) {
Treebank treebank = new DiskTreebank(trf, curEncoding);
treebank.loadPath(fileNode.getFile(), null, true);
TreeTransformer transformer = TregexGUI.getInstance().transformer;
if (transformer != null) {
treebank = new TransformingTreebank(treebank, transformer);
}
fileNode.setTreebank(treebank);
}
// System.out.println("Loadable files are: " + newFiles);
FileTreeModel.this.fireTreeStructureChanged(new TreePath(getRoot()));
}
use of edu.stanford.nlp.trees.TreeTransformer in project CoreNLP by stanfordnlp.
the class CTBErrorCorrectingTreeNormalizerTest method runTest.
private static void runTest(String input, String output) {
Tree inputTree = Tree.valueOf(input);
TreeTransformer tt = new CTBErrorCorrectingTreeNormalizer(false, false, false, false);
Tree outputTree = tt.apply(inputTree);
if (output == null) {
assertNull(outputTree);
} else {
assertEquals(output, outputTree.toString());
}
}
Aggregations