用bfs搜索
我已经从 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。谁能帮助我吗?先感谢您..
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 concept 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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来你想要这样的东西:
它或多或少是同义词的递归扩展(这基本上就是 BFS)。
Sounds like you want something like this:
It's more or less a recursive expansion of the synonyms (which is basically what BFS is).