All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.parser.lexparser.BoundaryRemover Maven / Gradle / Ivy

Go to download

Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.

There is a newer version: 3.9.2
Show newest version
package edu.stanford.nlp.parser.lexparser;

import java.util.List;

import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreeTransformer;

/**
 * Removes a boundary symbol (Lexicon.BOUNDARY_TAG or Lexicon.BOUNDARY), which
 * is the rightmost daughter of a tree.  Otherwise does nothing.
 * This is needed because the dependency parser uses such symbols.
 * 

* Note: This method is a function and not destructive. A new root tree is returned. * * @author Christopher Manning */ public class BoundaryRemover implements TreeTransformer { public BoundaryRemover() { } @Override public Tree transformTree(Tree tree) { Tree last = tree.lastChild(); if (last.label().value().equals(Lexicon.BOUNDARY_TAG) || last.label().value().equals(Lexicon.BOUNDARY)) { List childList = tree.getChildrenAsList(); List lastGoneList = childList.subList(0, childList.size() - 1); return tree.treeFactory().newTreeNode(tree.label(), lastGoneList); } else { return tree; } } } // end class BoundaryRemover





© 2015 - 2024 Weber Informatics LLC | Privacy Policy