【问题标题】:Finding Noun Phrases in sentiment analysis using stanford POS tagger使用 stanford POS 标记器在情感分析中查找名词短语
【发布时间】:2014-02-14 07:23:18
【问题描述】:

**我正在做一个关于情绪分析的项目。所以我使用 stanford POS 标记器来标记句子。我想从句子中提取名词短语,但它只是标记名词。 我如何从中得到名词短语。我在java中编码。 我在网站上搜索,发现这是一个名词短语: 对于名词短语,此模式或正则表达式如下:

(形容词|名词)*(名词介词)? (形容词 | 名词)* 名词 即零个或多个形容词或名词,后跟一个名词和介词的选项组,再跟零个或多个形容词或名词,后跟一个名词。

我试图使用 java 的规则表达式库对其进行编码。即正则表达式。但找不到想要的结果。 有没有人有它的代码? **

【问题讨论】:

    标签: regex sentiment-analysis pos-tagger


    【解决方案1】:

    我已经对此进行了编码。解决方案是.. 它将从只包含名词的句子中提取所有名词短语。 例如。像NP是:白虎。它将提取“白虎”。

    public static void maketree(String sent, int sno, Sentences sen) 
    {
        try 
        {
            LexicalizedParser parser = LexicalizedParser.loadModel("stanford-parser-full-2014-01-04\\stanford-parser-3.3.1-models\\edu\\stanford\\nlp\\models\\lexparser\\englishPCFG.ser.gz");
            String sent2 = "Picture Quality of this camera is very good";
            String sent1[] = sent2.split(" ");
            List<CoreLabel> rawWords = Sentence.toCoreLabelList(sent1);
            Tree x = parser.apply(rawWords);
            x.indexLeaves();
            System.out.println(x);
            findNP(x,sen);
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }
    
    public static void findNP(Tree t, Sentences sent) 
    {
        if (t.label().value().equals("NP")) 
        {
            noun(t,sent);
        } 
        else
        {
            for (Tree child : t.children()) 
            {                
                findNP(child,sent);
            }
        }
    
    }
    
        public static void noun(Tree t,Sentences sent)
    {       
        String noun="";
        for(Tree temp : t.children())
        {
            String val = temp.label().value();
            if(val.equals("NN") || val.equals("NNS") || val.equals("NNP") || val.equals("NNPS"))
            {
                Tree nn[] = temp.children();
                String ss = Sentence.listToString(nn[0].yield());
                if(noun=="")
                {
                    noun = ss;
                }
                else
                {
                    noun = noun+" "+ss;
                }
            }
            else
            {   
                if(noun!="")
                {
                    sent.nouns[i++] = noun;
                    noun = "";
                }
                noun(temp,sent);
            }
        }
        if(noun!="")
        {
            sent.nouns[i++] = noun;
        }
    }
    

    【讨论】:

      【解决方案2】:

      请您检查链接并对此发表评论。如果你能取悦我吗 “白虎”会得到与您上面的代码相同的结果。可能代码不完整,这就是我收到一些错误的原因。

      例如:

      sent.nouns[i++] = 名词; // sent.nouns?????它似乎是未定义的。能否请您获取完整的代码,或者您可以通过以下链接进行交流。

      这是链接

      Extract Noun phrase using stanford NLP

      感谢您的帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-30
        • 1970-01-01
        • 2013-10-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-29
        • 1970-01-01
        相关资源
        最近更新 更多