i have retrieve synsets from wordnet an return it as an array. This is part of my code
<pre>
RiWordnet wordnet = new RiWordnet();
String word = lineTF.getText();
// Get synsets
String[] synsets = wordnet.getAllSynsets(word, "n");
String outputSynset = "Word: " + word;
GUIsynonymTA.append("\n");
GUIsynonymTA.append(outputSynset);
GUIsynonymTA.append("\n");
if (synsets != null)
{
for (int i = 0; i < synsets.length; i++)
{
GUIsynonymTA.append("\n");
GUIsynonymTA.append("Synsets " + i + ": " + (synsets[i]));
GUIsynonymTA.append("\n");
//implement BFS here
<code>
until this line, i have retrieved the synsets successfully. What i'm going to do is to implement the Breadth First Search in searching WordNet synsets. I'm calling the method getAllSynsets from RiWordnet library which stores all synonym in wordnet. I try using looping (if..else), but i'm not sure where to stop my search. Using BFS is expected to know the scope of the search, where the search synonym be marked as the nodes that were visited. Here is a conce开发者_如何学JAVApt that i would like to implement using BFS in searching synonym.
For example:
student = {pupil, educatee, scholar, bookman}
pupil = {student, educatee, schoolchild}
educatee = {student, pupil} --> has been search, so go to the next synonym.
schoolchild = {pupil} --> has been search, so go to the next synonym.
scholar = {bookman, student, learner, assimilator}
bookman = {scholar, student} --> has been search, so go to the next synonym.
learner = {scholar, assimilator, apprentice, prentice}
assimilator = {learner, scholar} --> has been search, so go to the next synonym.
apprentice = {learner} --> has been search, so go to the next synonym.
prentice = {apprentice, learner} --> has been search, so go to the next synonym.
ALL SYNONYM HAS BEEN SEARCH, SO STOP.
Some people also suggested me to apply HashSet instead of BFS. Can anyone help me? Thank you in advance..
Sounds like you want something like this:
Queue<String> pending = ...
HashSet<String> processed = ...
pending.add("startWord");
processed.add("startWord");
while (!pending.isEmpty()) {
String word = pending.remove();
String[] possibilities = wordnet.getAllSynsets(word, "n");
for (String p : possibilities) {
// Make sure we haven't already processed the new word
if (!processed.contains(p)) {
pending.add(p);
processed.contains(p);
}
}
}
// At this point, processed contains all synonyms found
It's more or less a recursive expansion of the synonyms (which is basically what BFS is).
精彩评论