In general, you should not create your own IndexedWord objects. (They are used to represent “tokens,” that is, specific words in the text, rather than “types of words,” and therefore the query for the word “problem” —type of a word — is really invalid, in particular, a sentence can have several tokens of this type of word.)
There are several convenient methods that let you do what you want:
- sg.getNodeByWordPattern (string pattern)
- sg.getAllNodesByWordPattern (string pattern)
The first is a little dangerous, as it simply returns the first IndexedWord matching the pattern, or null if none exist. But this is most directly what you requested.
Some other ways to start:
- sg.getFirstRoot () to find (at first, usually only) the root of the graph, and then go from there, for example, using the sg.getChildren (root) method.
- sg.vertexSet () to get all IndexWord objects in the graph.
- sg.getNodeByIndex (int), if you already know the input sentence, and therefore you can query for words by their integer index.
Usually these methods leave you iterating through the nodes. Indeed, the first two methods ... Node ... just do an iteration for you.
source share