Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching WordNet for Synonym gives only one result

I am using java jwi API for searching the wordnet to get the synonyms of a word. The problem is that it only gives me one result the word to find its synonyms itself. Please guide me. Is it possible to get the list of all possible synonyms of a given word? My code is:

  public void searcher() {
    try {

        url = new URL("file", null, path);


        dict = new Dictionary(url);
        try {
            dict.open();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "Dictionary directory does not exist\n" + ex + "\nClass:Meaning Thread", "Dictionary Not Found Error", JOptionPane.ERROR_MESSAGE);

        }

        IIndexWord idxWord = dict.getIndexWord("capacity", POS.NOUN);
        IWordID wordID = idxWord.getWordIDs().get(0);
        IWord word = dict.getWord(wordID);


        //Adding Related Words to List of Realted Words
        ISynset synset = word.getSynset();
        for (IWord w : synset.getWords()) {
            System.out.println(w.getLemma());
        }


    } catch (Exception e) {
    }

}

The output is only:

capacity

itself! The actual synonyms must be:

  capability
  capacitance 
  content
  electrical capacitance
  mental ability...(so on)

So is there anything I missed in the code or can somebodygive me any ideas what is the real problem?

Thanks in advance

like image 437
Java Nerd Avatar asked Mar 23 '14 10:03

Java Nerd


People also ask

How do I find synonyms for a phrase?

Using the thesaurus, you can look up synonyms (different words with the same meaning) and antonyms (words with the opposite meaning). Tip: In the desktop versions of Word, PowerPoint, and Outlook, you can get a quick list of synonyms by right-clicking a word and choosing Synonyms.

What is WordNet How is sense defined in WordNet explain with example ques10?

WordNet. saurus —a database that represents word senses—with versions in many languages. WordNet also represents relations between senses. For example, there is an IS-A relation between dog and mammal (a dog is a kind of mammal) and a part-whole relation between engine and car (an engine is a part of a car).


2 Answers

So, here comes the answer i use Java JAWS for wordnet searching! The steps are:

    1- Download WordNet Dictionary from 

Here

    2- Install WordNet
    3- Go to Installed Directory and copied the WordNet Directory (in my case C:\Program Files (x86) was the Directory for WordNet Folder)
    4- Pasted it into my Java Project (under MyProject>WordNet)
    5- Making Path to the directory as:
       File f=new File("WordNet\\2.1\\dict");
       System.setProperty("wordnet.database.dir", f.toString());
    6- Got Synonyms as:

       public class TestJAWS{
              public static void main(String[] args){
                    String wordForm = "capacity";
                    //  Get the synsets containing the word form=capicity

                   File f=new File("WordNet\\2.1\\dict");
                   System.setProperty("wordnet.database.dir", f.toString());
                   //setting path for the WordNet Directory

                   WordNetDatabase database = WordNetDatabase.getFileInstance();
                   Synset[] synsets = database.getSynsets(wordForm);
                   //  Display the word forms and definitions for synsets retrieved

                   if (synsets.length > 0){
                      ArrayList<String> al = new ArrayList<String>();
                      // add elements to al, including duplicates
                      HashSet hs = new HashSet();
                      for (int i = 0; i < synsets.length; i++){
                         String[] wordForms = synsets[i].getWordForms();
                           for (int j = 0; j < wordForms.length; j++)
                           {
                             al.add(wordForms[j]);
                           }


                      //removing duplicates
                       hs.addAll(al);
                       al.clear();
                       al.addAll(hs);

                      //showing all synsets
                      for (int i = 0; i < al.size(); i++) {
                            System.out.println(al.get(i));
                      }
                   }
              }
              }
              else
              {
               System.err.println("No synsets exist that contain the word form '" + wordForm + "'");
              }
       } 

The Thing is you must have jaws-bin.jar

like image 63
Java Nerd Avatar answered Nov 03 '22 22:11

Java Nerd


What you are getting is "capacity#1", which has the meaning of "capability to perform or produce", and it does indeed only have one synonym. (Play around with the PWN search page to get a feel for how WordNet organizes the words into synsets.)

It sounds like what you are after is the union of all synonyms in all the synsets? I think you either use getSenseEntryIterator(), or simply put a loop around idxWord.getWordIDs().get(0);, replacing the 0 with the loop counter, so you are not only ever getting the first item in the array.

like image 38
Darren Cook Avatar answered Nov 03 '22 23:11

Darren Cook