Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find synonyms in estimated frequency order using JWNL(Wordnet Library)?

Does anyone know how I can take the synonyms of a word using JWNL (Java Wordnet Library) ordered by estimated frequency? I know this can be done somehow, because Wordnet's application can do it. (I don't know if it matters, but I am using Wordnet 2.1)

Here is my code of how I get synonyms, could anyone please tell me what I should add... (completely different ways of doing it are also welcomed!)

  ArrayList<String> synonyms=new ArrayList<String>();
  System.setProperty("wordnet.database.dir", filepath);
  String wordForm = "make";
  Synset[] synsets = database.getSynsets(wordForm,SynsetType.VERB);
  if (synsets.length > 0) {
       for (int i = 0; i < synsets.length; i++) {
    String[] wordForms = synsets[i].getWordForms();
    for (int j = 0; j < wordForms.length; j++) {
           if(!synonyms.contains(wordForms[j])){
        synonyms.add(wordForms[j]); }
                }
           }
     }
like image 771
missrg Avatar asked Dec 11 '12 14:12

missrg


1 Answers

Since noone answered, I suppose there must be more people wondering the same think and not knowing the answer.

Well, I figured out that there is the function Synset.getTagCount(String), which returns the value of the estimated frequency of every synset relating to the word(String). So, all I had to do was to sort the ArrayList with the synonyms according to this.

But it was proved that the synsets are by default returned sorted, so what I get using the code I wrote at the question is already ordered by estimated frequency!

I hope this will help somebody in the future :)

like image 69
missrg Avatar answered Nov 01 '22 10:11

missrg