1

wordnet から synset を取得し、それを配列として返します。これは私のコードの一部です

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

この行まで、synset を正常に取得しました。これから行うことは、WordNet synset の検索に幅優先検索を実装することです。すべての類義語を wordnet に格納する RiWordnet ライブラリからメソッド getAllSynsets を呼び出しています。ループ (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. 

また、BFS の代わりに HashSet を適用することを提案する人もいました。誰でも私を助けることができますか?前もって感謝します..

4

1 に答える 1

0

次のようなものが必要なようです。

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 です)。

于 2011-09-04T04:13:39.770 に答える