Hello everyone, I have a code to get the first noun of a sentence from parsed result. I wrote the following code. But there seems to some problem. If statement does not break for loop. Can any one please help me to fix it?
Thanks in advance.
public static String Find_Noun(Parse p)
{
label:
for(Parse k:p.getChildren())
{
if((k.getType()).equals("NN")||(k.getType()).equals("NNP")||
(k.getType()).equals("NNS")||(k.getType()).equals("NNPS"))
{
noun=k.toString();
System.out.println(noun);
break label; // I am aware that label is not needed,
// but it doesn't work either way.
}
else
{
System.out.println("else "+k);
Find_Noun(k);
}
}
return noun;
}
Input:
became\VBD a\DT regular\JJ customer\NN of\IN a\DT suburban\JJ garden\NN
The output is:
else became
else became
else a regular customer of a suburban garden
else a regular customer
else a
else a
else regular
else regular
customer \\This is the string to be extracted
else of a suburban garden
else of
else of
else a suburban garden
else a
else a
else suburban
else suburban
garden
garden
break;is not broken. Step through the code with the debugger and you'll see what's going wrong.