1

This is part of my code:

String sentence = "The system Does Not Require users to identify themselves to search for books according to certain criteria and to check the availability of a particular book. However to check out books, to check their respective book loan status, and to place holds on books that are already on loan, users must first identify themselves to the system.";

Parse topParses[] =ParserTool.parseLine(sentence, parser, /*numParses=*/ 3);

for (Parse parseTree: topParses){

parseTree.show();

How can I get verbs in the sentence? Please!

I mean, how can I get nodes of tree?

ceving
  • 21,900
  • 13
  • 104
  • 178
Hamood
  • 11
  • 2
  • Does a parseTree have a method that returns its children? And do they have a method that return their children, etc? Iterate or recurse over them. – Patashu Mar 27 '13 at 05:32
  • yes,it's this parseTree.getChildren(); how can i itrate them sorry i am new to java.. – Hamood Mar 27 '13 at 05:37
  • Ok. Write a tree recursion algorithm then. The function would be like this: If the node has children, foreach loop over them and call this function on each one. Otherwise, we're at a leaf node, do some function on it (like add it to a list). – Patashu Mar 27 '13 at 05:38
  • i spent much time till i get the sentence parsed but when i try to get the verb from this"(TOP (S (NP (DT The) (NNS systemDoesNotRequireusers)) (VP (TO to) (VP (VB identify)" i could not so please just do your previous explanation on this as java code, thanks – Hamood Mar 27 '13 at 05:43
  • Nodes can be arbitrarily deep in the tree, so use a recursive algorithm. – Patashu Mar 27 '13 at 05:44
  • can you provide simple example on sentence parsed above please? – Hamood Mar 27 '13 at 05:58
  • `function exploreTree(Parse currentNode) { if (currentNode.hasChildren) { for (Parse child : currentNode.getChildren()) { exploreTree(child); } else { System.out.println(currentNode.ToString() } }` – Patashu Mar 27 '13 at 06:06
  • there is no default hasChildren method.. – Hamood Mar 27 '13 at 06:16
  • one last question, could you give me the package name for haschilden that you used please? – Hamood Mar 27 '13 at 06:53
  • I have never used this package, I just wrote pseudocode – Patashu Mar 27 '13 at 08:00

2 Answers2

0

If only you need to get the verbs from the sentence , then POSTagger in opennlp is sufficient.All you have to do is to use a Opennlp tokenizer to get tokens in a array and feed it to the POSTaggerME.It will give you the corresponding POS tags..Then you can filter by tags for the Verb like VB, VBZ etc.

igopimac13
  • 33
  • 4
0

If you are looking for verb phrases then use the Chunker, if you need just verbs then use the POS tagger. Check out this answer How to extract the noun phrases using Open nlp's chunking parser

Community
  • 1
  • 1
Mark Giaconia
  • 3,844
  • 5
  • 20
  • 42