对给定的一句话进行依存分析

import java.util.List;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;

class ParserDemo {

  public static void main(String[] args) {
    String parserModel = "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz";
    LexicalizedParser lp = LexicalizedParser.loadModel(parserModel);
    demoAPI(lp);
    
  }
 
  public static void demoAPI(LexicalizedParser lp) {
    
	String str = "Next , we wanted to explore whether the BMP - 6 induced phosphorylation of Smad 1 / 5 / 8 also could induce transcriptional changes of target genes .";
	String[] sent = str.split(" ");
    //String[] sent = { "This", "is", "an", "easy", "sentence", "." };
    List<CoreLabel> rawWords = Sentence.toCoreLabelList(sent);
    Tree parse = lp.apply(rawWords);
    

    TreebankLanguagePack tlp = lp.treebankLanguagePack(); // PennTreebankLanguagePack for English
    GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
    GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
    List<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
    System.out.println(tdl);
    System.out.println();
    for(int i = 0; i < tdl.size(); i++)
    {
    	TypedDependency td = tdl.get(i);
    	System.out.print(td.dep() + "  "); 
    	System.out.print(td.gov() + "  ");
    	System.out.print(td.reln());
    	System.out.println();  
    	System.out.print(td.dep().nodeString()+"          ");    	
    	System.out.println(td.dep().index());    	
    }

  }

  private ParserDemo() {} // static methods only

}



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>