2011-08-14 8 views
1

私はワードネットからsynsetを取得し、それを配列として返します。これは私のコードの一部ですbfsで検索する

<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> 

この行までは、私は正常にsynsetsを取得しました。私がしようとしているのは、WordNet synsetsを検索する際のBreadth First Searchを実装することです。私は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を適用するために私を示唆しました。誰でも助けてくれますか?

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 

それは(BFSが何であるかを基本的に)同義語の多かれ少なかれ再帰的な展開です:

+1

synset以上のBFSはどういう意味ですか?それらはプレーンなデータであり、BFSはグラフで検索するためのアルゴリズムです。 – ffriend

+0

別の[質問](http://stackoverflow.com/questions/6935916/nested-search-of-synsets-from-wordnet-using-java)からあなたのアイデアを得ましたが、BFSで何を探していますか?シノニムのすべてのシノニムとシノニム、シノニムのシノニムのシノニムなどを列挙したい場合は、再帰を使用してすべてのシノニムをHashSetに入れてサークルを避けます。 – ffriend

+0

ありがとうございました。実際にはBFSは訪問先と未訪問のグラフの概念を使用しています。私は検索の限界を設定するためにこれを実装したい。シノニムが検索されている場合(BFSで訪問したとマークされます)、検索は停止します。システムは、検索によって見つかったすべての同義語を一覧表示します。 –

答えて

0

は、あなたがこのような何かをしたいような音..事前にありがとうございます。

+0

ありがとう@ジェイムズ..私はそれを試してみる.. =) –