Question

**I am making a project on sentiment analysis. so i used stanford POS tagger to tag the sentence. I want to extract noun phrases from the sentences but it was only tagging noun. How do i get noun phrases from that. i code in java. i searched on websites and i found this for making a noun phrase: For noun phrases, this pattern or regular expression is the following:

(Adjective | Noun)* (Noun Preposition)? (Adjective | Noun)* Noun i.e. Zero or more adjectives or nouns, followed by an option group of a noun and a preposition, followed again by zero or more adjectives or nouns, followed by a single noun.

i was trying to code it using java's reguler expression library. i.e regex. but couldnt find the desired result. Does anyone has code for it? **

No correct solution

OTHER TIPS

I have coded this. and solution is.. it will extracy all the noun phrase from a sentence containing only noun. for eg. like NP is: the white tiger. it will extract "white tiger".

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;
    }
}

Could you please check the link and comment on this. Could you please me if "the white tiger" would get the same result with your above code.probably the code is not complete and thats why I am getting some error.

for eg:

sent.nouns[i++] = noun; // sent.nouns????? it seems to be undefined. could you please get the complete code or if you can commnet on the below link.

here is the link

Extract Noun phrase using stanford NLP

Thanks for the help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top