如何使用Open nlp的分块解析器提取名词短语 [英] How to extract the noun phrases using Open nlp's chunking parser

查看:931
本文介绍了如何使用Open nlp的分块解析器提取名词短语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是自然语言处理的新手。我需要从文本中提取名词短语。到目前为止,我已经使用open nlp的分块解析器来解析我的文本以获得树结构。但是我无法提取名词树结构中的短语,在打开的nlp中是否有任何正则表达式模式,以便我可以用它来提取名词短语。



以下是我正在使用的代码

  InputStream is = new FileInputStream(en-parser-chunking.bin); 
ParserModel model = new ParserModel(is);
Parser parser = ParserFactory.create(model);
Parse topParses [] = ParserTool.parseLine(line,parser,1);
for(Parse p:topParses){
p.show();}

这里我得到的输出为



(TOP(S(S(ADJP(JJ welcome)(PP(TO to)(NP(NNP Big)(NNP)数据。)))))(S(NP(PRP We))(VP(VP(VBP))(VP(VBG工作)(PP(IN on)(NP(NNP Natural)(NNP语言))(NNP处理。 can)))))(NP(DT some)(CD one)(NN帮助))(NP(PRP us))(PP(IN in)(S(VP(VBG提取)(NP(DT))(NN) (NNS短语))(PP(IN)(NP(DT)(NN树)(WP结构)))))))))))



<请问有人可以帮助我获取NP,NNP,NN等名词短语。可以告诉我,我是否需要使用任何其他NP Chunker来获取名词短语?是否有任何正则表达式模式来实现相同的。



请帮助我。



提前致谢



Gouse。

解决方案

Parse 对象是一个树;你可以使用 getParent() getChildren() getType()导航树。

 列表< Parse>名词短语; 

public void getNounPhrases(Parse p){
if(p.getType()。equals(NP)){
nounPhrases.add(p);
}
for(Parse child:p.getChildren()){
getNounPhrases(child);
}
}


I am newbie to Natural Language processing.I need to extract the noun phrases from the text.So far i have used open nlp's chunking parser for parsing my text to get the Tree structure.But i am not able to extract the noun phrases from the tree structure, is there any regular expression pattern in open nlp so that i can use it to extract the noun phrases.

Below is the code that i am using

    InputStream is = new FileInputStream("en-parser-chunking.bin");
    ParserModel model = new ParserModel(is);
    Parser parser = ParserFactory.create(model);
    Parse topParses[] = ParserTool.parseLine(line, parser, 1);
        for (Parse p : topParses){
                 p.show();}

Here I am getting the output as

(TOP (S (S (ADJP (JJ welcome) (PP (TO to) (NP (NNP Big) (NNP Data.))))) (S (NP (PRP We)) (VP (VP (VBP are) (VP (VBG working) (PP (IN on) (NP (NNP Natural) (NNP Language) (NNP Processing.can))))) (NP (DT some) (CD one) (NN help)) (NP (PRP us)) (PP (IN in) (S (VP (VBG extracting) (NP (DT the) (NN noun) (NNS phrases)) (PP (IN from) (NP (DT the) (NN tree) (WP stucture.))))))))))

Can some one please help me in getting the noun phrases like NP,NNP,NN etc.Can some one tell me do I need to use any other NP Chunker to get the noun phrases?Is there any regex pattern to achieve the same.

Please help me on this.

Thanks in advance

Gouse.

解决方案

The Parse object is a tree; you can use getParent() and getChildren() and getType() to navigate the tree.

List<Parse> nounPhrases;

public void getNounPhrases(Parse p) {
    if (p.getType().equals("NP")) {
         nounPhrases.add(p);
    }
    for (Parse child : p.getChildren()) {
         getNounPhrases(child);
    }
}

这篇关于如何使用Open nlp的分块解析器提取名词短语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆