当前位置: 首页>>代码示例>>Java>>正文


Java Tree.valueOf方法代码示例

本文整理汇总了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;
    }
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:16,代码来源:Utils.java

示例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();
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:8,代码来源:Utils.java

示例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;
    }        
    
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:35,代码来源:Utils.java

示例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;
	}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:50,代码来源:ExtractPosTagData.java

示例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
}
 
开发者ID:sinantie,项目名称:Generator,代码行数:47,代码来源:ComputeAmrEstimates.java

示例6: toPtbFormat

import edu.stanford.nlp.trees.Tree; //导入方法依赖的package包/类
private String toPtbFormat(String input)
{
    Tree tree = Tree.valueOf(input);
    return tree.pennString();
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:6,代码来源:JsonResult.java


注:本文中的edu.stanford.nlp.trees.Tree.valueOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。