我已经从 wordnet 中检索同义词集并将其作为数组返回。这是我的代码的一部分
<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>
直到这一行,我已经成功检索了同义词集。我要做的是在搜索 WordNet 同义词集时实现广度优先搜索。我正在调用 RiWordnet 库中的 getAllSynsets 方法,该库将所有同义词存储在 wordnet 中。我尝试使用循环(if..else),但我不确定在哪里停止搜索。使用 BFS 应该知道搜索的范围,其中搜索同义词被标记为被访问的节点。这是我想在搜索同义词时使用 BFS 实现的概念。
例如:
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.
有些人还建议我应用 HashSet 而不是 BFS。谁能帮我?先感谢您..