利用Stanford parser与多线程获取语句中名词集合工具实现

  最近有处理一批语句获取名词集合的需求,写了个小工具。

Stanford Parser导入

  利用maven引入Stanford Parser的包,没有特殊需求的话直接使用里面训练完的各国语言文件即可,很方便。

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>3.9.2</version>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-parser</artifactId>
            <version>3.9.2</version>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>3.9.2</version>
            <classifier>models</classifier>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-parser</artifactId>
            <version>3.9.2</version>
            <classifier>models</classifier>
        </dependency>

  Stanford Parser java实现使用了slf4j进行输出提示管理,为了不报错把slf4j也引入。

		<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.25</version>
            <scope>test</scope>
        </dependency>

语句处理

  Stanford Parser有个Type Dependency的概念,表示词之间和词本身的关系。每个词对应的td有对应的tag,该属性表示了词汇在当前句法树中的词性。Stanford Parser定义了很多种词汇的性质,具体可参考Stanford Parser标记含义

  这边我们按照需求,将tag为NN(常见名词)和NR(固有名词)的词汇进行分析输出。
  获取模型

	private String model="edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz";

    public LexicalizedParser createParser(){
   
        LexicalizedParser lp = LexicalizedParser.loadModel(model);
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值