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

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

问题描述

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

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.

下面是我使用的代码

    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 欢迎) (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短语)) (PP (IN from) (NP (DT the) (NN树) (WP 结构.)))))))))))

(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.))))))))))

有人可以帮助我获取名词短语,如 NP、NNP、NN 等.有人可以告诉我我是否需要使用任何其他 NP Chunker 来获取名词短语?是否有任何正则表达式模式可以实现一样.

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.

请帮我解决这个问题.

提前致谢

鹅.

推荐答案

Parse 对象是一棵树;您可以使用 getParent()getChildren()getType() 来导航树.

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天全站免登陆