WordNet search for synonym gives only one result

I use the java jwi API to search in wordnet to get synonyms for a word. The problem is that he gives me only one result to find his synonyms. Please guide me. Is it possible to get a list of all possible synonyms for 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) {
    }

}

Output only:

capacity

myself! Actual synonyms should be:

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

So is there something that I missed in the code, or can someone give me some ideas, what is the problem?

Thanks in advance

+4
source share
3 answers

So here is the answer: I'm using Java JAWS to search in wordnet! Steps:

    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 + "'");
              }
       } 

Thing - you must have jaw-bin.jar

+4
source

, , " № 1", " ", . ( PWN, , WordNet synsets.)

, - ? , getSenseEntryIterator(), idxWord.getWordIDs().get(0);, 0 , .

+1

If you want to use JWI and want to get more than one synonym, change the code from this exact place:

IIndexWord idxWord = dict.getIndexWord(inputWord, POS.NOUN);
        try {
            int x = idxWord.getTagSenseCount();
            for (int i = 0; i < x; i++) {
                IWordID wordID = idxWord.getWordIDs().get(i);
                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());
                    // output.add(w.getLemma());
                }
            }
        } catch (Exception ex) {
            System.out.println("No synonym found!");
        }

It works great.

0
source

Source: https://habr.com/ru/post/1533043/


All Articles