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