本文整理汇总了Java中edu.stanford.nlp.trees.Tree.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.valueOf方法的具体用法?Java Tree.valueOf怎么用?Java Tree.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.trees.Tree
的用法示例。
在下文中一共展示了Tree.valueOf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeIncrementalTrees
import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static Map<Integer, String> computeIncrementalTrees(String treeStr)
{
Map<Integer, String> map = new TreeMap<Integer, String>();
Tree tree = Tree.valueOf(treeStr);
List<Tree> leaves = tree.getLeaves();
Tree firstLeaf = leaves.get(0);
// first prefix tree by default is the sub-tree rooted on the preterminal (don't add, as we compute evalb for words>1)
// map.put(0, firstLeaf.parent(tree).toString());
for(int i = 1; i < leaves.size(); i++)
{
Tree lastLeaf = leaves.get(i);
map.put(i, getMinimalConnectedStructure(tree, firstLeaf, lastLeaf, i).toString());
}
return map;
}
示例2: computeIncrementalTree
import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static String computeIncrementalTree(String treeStr)
{
Tree tree = Tree.valueOf(treeStr);
List<Tree> leaves = tree.getLeaves();
leaves.get(leaves.size() - 1);
return computeIncrementalTree(treeStr, leaves.size() - 1).toString();
}
示例3: removeSubtreesAfterWord
import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
public static String removeSubtreesAfterWord(String inputTree, int numOfLeaves)
{
Tree tree = Tree.valueOf(inputTree);
List<Tree> leaves = tree.getLeaves();
if(leaves.size() > numOfLeaves)
{
// find common ancestor between last valid leaf and extraneous leaf
Tree firstLeaf = leaves.get(numOfLeaves - 1);
Tree lastLeaf = leaves.get(leaves.size() - 1);
Tree commonAncestorNode = lastLeaf.parent(tree);
while(!commonAncestorNode.getLeaves().contains(firstLeaf))
{
commonAncestorNode = commonAncestorNode.parent(tree);
}
// found the common ancestor, now we need to chop the children nodes the span of which is outwith the last valid leaf
Tree p = lastLeaf.parent(tree);
while(p != commonAncestorNode)
{
int numOfChildren = p.numChildren();
for(int i = 0; i < numOfChildren; i++)
p.removeChild(0);
p = p.parent(tree);
}
// remove last leftover parent node of the invalid leaf
commonAncestorNode.removeChild(commonAncestorNode.numChildren() - 1);
return tree.toString();
}
else
{
return inputTree;
}
}
示例4: ExtractPhrase
import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
@Override
public List<String> ExtractPhrase(String sentence) {
List<String> lstResult=new ArrayList<>();
List<String> lstPhrase=new ArrayList<>();
List<String> lstFinalPhrase=new ArrayList<>();
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,parse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation annotation = new Annotation(sentence);
pipeline.annotate(annotation);
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for(CoreMap sent:sentences)
{
Tree tree = sent.get(TreeAnnotation.class);
lstResult.add(tree.pennString());
}
TregexPattern tPattern = TregexPattern.compile("NP");
for(String strVal:lstResult)
{
Tree t = Tree.valueOf(strVal);
TregexMatcher tMatcher = tPattern.matcher(t);
while (tMatcher.find()) {
lstPhrase.add(tMatcher.getMatch().toString());
}
}
TregexPattern tPattern2 = TregexPattern.compile("VP");
for(String strVal2:lstResult)
{
Tree t2 = Tree.valueOf(strVal2);
TregexMatcher tMatcher2 = tPattern2.matcher(t2);
while (tMatcher2.find())
{
lstPhrase.add(tMatcher2.getMatch().toString());
}
}
//////////////////////////////////////////////////////////////
// for(String Data:lstPhrase) {
// String line="";
// String [] tempVal=Pattern.compile("\\)").split(Data);
// for(int i=0;i<tempVal.length;i++)
// {
// String [] getFinalVal=tempVal[i].split(" ");
// line+=getFinalVal[getFinalVal.length-1]+" ";
// }
// lstFinalPhrase.add(line);
// }
///return lstFinalPhrase;
return lstPhrase;
}
示例5: readAlignments
import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
private void readAlignments()
{
if(new File(opts.sentencesFile).exists() && new File(opts.GHKMTreeFile).exists() && new File(opts.alignmentsFile).exists())
{
String[] sentences = Utils.readLines(opts.sentencesFile);
String[] trees = Utils.readLines(opts.GHKMTreeFile);
String[] alignments = Utils.readLines(opts.alignmentsFile);
int numOfNull = 0;
for(int i = 0; i < sentences.length; i++)
{
String[] words = sentences[i].split(" ");
try
{
Tree tree = Tree.valueOf(trees[i]);
if(tree != null)
{
List<CoreLabel> yield = new ArrayList<>();
tree.yield(yield);
String[] alignment = alignments[i].split(" ");
for(String token : alignment)
{
String[] yieldWord = token.split("-");
int yieldIndex = Integer.valueOf(yieldWord[0]);
int wordIndex = Integer.valueOf(yieldWord[1]);
if(yieldIndex < yield.size() && wordIndex < words.length)
{
String key = yield.get(yieldIndex).word();
updateVocabulary(key, words[wordIndex]);
//System.out.println(key + " " + words[wordIndex]);
}
} // for
} // if
else
{
numOfNull++;
}
}
catch(Exception ioe)
{
LogInfo.error("Error reading tree " + trees[i]);
}
} // for
Utils.logs("Num of null trees: " + numOfNull);
} // if
}
示例6: toPtbFormat
import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
private String toPtbFormat(String input)
{
Tree tree = Tree.valueOf(input);
return tree.pennString();
}