在NLP的帮助下分析句子并提取人名,组织和位置 [英] Analyse the sentences and extract person name, organization and location with the help of NLP

查看:180
本文介绍了在NLP的帮助下分析句子并提取人名,组织和位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用NLP解决以下问题,你能否指点一下如何使用OpenNLP API实现这个目标

I need to solve the following using NLP, can you give me pointers on how to achieve this using OpenNLP API

a。如何判断某句话是否暗示过去,现在或将来的某种行为。

a. How to find out if a sentence implies a certain action in the past, present or future.

(e.g.) I was very sad last week - past
       I feel like hitting my neighbor - present
       I am planning to go to New York next week - future

b。如何找到与个人,公司或国家相对应的单词

b. How to find the word which corresponds to a person or company or country

(e.g.) John is planning to specialize in Electrical Engineering in UC Berkley and pursue a career with IBM).

Person = John

Person = John

公司= IBM

位置=伯克利

谢谢

推荐答案

我可以提供解决方案

解决方案b。

这是代码:

    public class tikaOpenIntro {

    public String Tokens[];

    public static void main(String[] args) throws IOException, SAXException,
            TikaException {

        tikaOpenIntro toi = new tikaOpenIntro();


        String cnt;

        cnt="John is planning to specialize in Electrical Engineering in UC Berkley and pursue a career with IBM.";

                toi.tokenization(cnt);

        String names = toi.namefind(toi.Tokens);
        String org = toi.orgfind(toi.Tokens);

                System.out.println("person name is : "+names);
        System.out.println("organization name is: "+org);

    }
        public String namefind(String cnt[]) {
        InputStream is;
        TokenNameFinderModel tnf;
        NameFinderME nf;
        String sd = "";
        try {
            is = new FileInputStream(
                    "/home/rahul/opennlp/model/en-ner-person.bin");
            tnf = new TokenNameFinderModel(is);
            nf = new NameFinderME(tnf);

            Span sp[] = nf.find(cnt);

            String a[] = Span.spansToStrings(sp, cnt);
            StringBuilder fd = new StringBuilder();
            int l = a.length;

            for (int j = 0; j < l; j++) {
                fd = fd.append(a[j] + "\n");

            }
            sd = fd.toString();

        } catch (FileNotFoundException e) {

            e.printStackTrace();
        } catch (InvalidFormatException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }
        return sd;
    }

    public String orgfind(String cnt[]) {
        InputStream is;
        TokenNameFinderModel tnf;
        NameFinderME nf;
        String sd = "";
        try {
            is = new FileInputStream(
                    "/home/rahul/opennlp/model/en-ner-organization.bin");
            tnf = new TokenNameFinderModel(is);
            nf = new NameFinderME(tnf);
            Span sp[] = nf.find(cnt);
            String a[] = Span.spansToStrings(sp, cnt);
            StringBuilder fd = new StringBuilder();
            int l = a.length;

            for (int j = 0; j < l; j++) {
                fd = fd.append(a[j] + "\n");

            }

            sd = fd.toString();

        } catch (FileNotFoundException e) {

            e.printStackTrace();
        } catch (InvalidFormatException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }
        return sd;

    }


    public void tokenization(String tokens) {

        InputStream is;
        TokenizerModel tm;

        try {
            is = new FileInputStream("/home/rahul/opennlp/model/en-token.bin");
            tm = new TokenizerModel(is);
            Tokenizer tz = new TokenizerME(tm);
            Tokens = tz.tokenize(tokens);
            // System.out.println(Tokens[1]);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

和你一起想要位置,然后导入位置模型也可以在 openNLP source Forge 上找到。你可以下载并且您可以使用它们。

and you want location also then import location model also that is available on openNLP source Forge. you can download and you can use them.

我不确定名称,位置和组织提取的可能性,但几乎它识别所有名称,位置,组织。

I am not sure about what will be probability of Name, Location, and Organization Extraction but almost it recognize all names,location,organization.

如果找不到openNLP,那么请使用Stanford Parser进行名称实体识别。

这篇关于在NLP的帮助下分析句子并提取人名,组织和位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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