2016-07-24 63 views
1

我想爲我的搜索引擎從數據庫中提取基本的同義詞列表。這包括通常拼寫的名字,如Shaun對Shawn,穆罕默德的不同變體,聯合國(UN)或嚴重急性呼吸系統綜合症(SARS)等具名實體的縮略語。從Wordnet中提取單詞列表

提取後,這個同義詞列表將被放置在服務器中,並存儲爲 - 一串相關的術語/同義詞。

Example

我用爪API,並設法得到的,我已經進入了特定詞的同義詞。這是我嘗試過的一個例子。 NASA的

別名:

  1. 美國國家航空和航天局:負責航空航天美國政府的一個獨立機構。

以下是我用過的代碼。

/** 
* Main entry point. The command-line arguments are concatenated together 
* (separated by spaces) and used as the word form to look up. 
*/ 
public static void main(String[] args) 
{ 
    arg[0]="NASA"; 
    if (args.length > 0) 
    { 
     // Concatenate the command-line arguments 
     StringBuffer buffer = new StringBuffer(); 
     for (int i = 0; i < args.length; i++) 
     { 
      buffer.append((i > 0 ? " " : "") + args[i]); 
     } 
     String wordForm = buffer.toString(); 
     // Get the synsets containing the wrod form 
     WordNetDatabase database = WordNetDatabase.getFileInstance(); 
     Synset[] synsets = database.getSynsets(wordForm); 
     // Display the word forms and definitions for synsets retrieved 
     if (synsets.length > 0) 
     { 
      System.out.println("The following synsets contain '" + 
        wordForm + "' or a possible base form " + 
        "of that text:"); 
      for (int i = 0; i < synsets.length; i++) 
      { 
       System.out.println(""); 
       String[] wordForms = synsets[i].getWordForms(); 
       for (int j = 0; j < wordForms.length; j++) 
       { 
        System.out.print((j > 0 ? ", " : "") + 
          wordForms[j]); 
       } 
       System.out.println(": " + synsets[i].getDefinition()); 
      } 
     } 
     else 
     { 
      System.err.println("No synsets exist that contain " + 
        "the word form '" + wordForm + "'"); 
     } 
    } 
    else 
    { 
     System.err.println("You must specify " + 
       "a word form for which to retrieve synsets."); 
    } 
} 

但是,這種方法將要求我手動輸入所有我想查詢的單詞。有沒有辦法循環遍歷整個字典,將所有的單詞及其同義詞存儲在單詞列表(文本格式)中?

謝謝

回答