Search in sources :

Example 16 with TreeTransformer

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);
}
Also used : TreeNormalizer(edu.stanford.nlp.trees.TreeNormalizer) NumberRangesFileFilter(edu.stanford.nlp.io.NumberRangesFileFilter) Tree(edu.stanford.nlp.trees.Tree) TreeReaderFactory(edu.stanford.nlp.trees.TreeReaderFactory) TreeTransformer(edu.stanford.nlp.trees.TreeTransformer)

Example 17 with TreeTransformer

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()));
}
Also used : DiskTreebank(edu.stanford.nlp.trees.DiskTreebank) TreePath(javax.swing.tree.TreePath) Treebank(edu.stanford.nlp.trees.Treebank) DiskTreebank(edu.stanford.nlp.trees.DiskTreebank) TransformingTreebank(edu.stanford.nlp.trees.TransformingTreebank) TransformingTreebank(edu.stanford.nlp.trees.TransformingTreebank) TreeTransformer(edu.stanford.nlp.trees.TreeTransformer)

Example 18 with TreeTransformer

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());
    }
}
Also used : Tree(edu.stanford.nlp.trees.Tree) TreeTransformer(edu.stanford.nlp.trees.TreeTransformer)

Aggregations

TreeTransformer (edu.stanford.nlp.trees.TreeTransformer)18 Tree (edu.stanford.nlp.trees.Tree)16 Treebank (edu.stanford.nlp.trees.Treebank)10 PrintWriter (java.io.PrintWriter)9 TreebankLangParserParams (edu.stanford.nlp.parser.lexparser.TreebankLangParserParams)6 Language (edu.stanford.nlp.international.Language)5 Label (edu.stanford.nlp.ling.Label)5 ArrayList (java.util.ArrayList)4 EnglishTreebankParserParams (edu.stanford.nlp.parser.lexparser.EnglishTreebankParserParams)3 TreeReaderFactory (edu.stanford.nlp.trees.TreeReaderFactory)3 Pair (edu.stanford.nlp.util.Pair)3 NumberRangesFileFilter (edu.stanford.nlp.io.NumberRangesFileFilter)2 CoreLabel (edu.stanford.nlp.ling.CoreLabel)2 HasWord (edu.stanford.nlp.ling.HasWord)2 LexicalizedParser (edu.stanford.nlp.parser.lexparser.LexicalizedParser)2 CompositeTreeTransformer (edu.stanford.nlp.trees.CompositeTreeTransformer)2 MemoryTreebank (edu.stanford.nlp.trees.MemoryTreebank)2 TreeReader (edu.stanford.nlp.trees.TreeReader)2 HashIndex (edu.stanford.nlp.util.HashIndex)2 File (java.io.File)2