Question

Can anyone explain to me how the 'getAllSynonyms' method i have used in the code below works? Every time I run it I get different results. Sometimes the words aren't synonyms at all! What is the significance of the middle argument in the call to the method? Links to any manuals that explain the methods of word net? Apologies if I have violated posting etiquette :).

import rita.wordnet.*;
import java.lang.reflect.Array;
import java.util.*;
public class Blah 
{


RiWordnet wordnet;

String word;

void setup() 
{

  wordnet = new RiWordnet();
  word = "car";
    String[] poss = wordnet.getPos(word);
    //System.out.println(poss)
    for (int j = 0; j < poss.length; j++) {
        System.out.println("\n\nSynonyms for " + word + " (pos: " + poss[j] + ")");
        String[] synonyms = wordnet.getAllSynonyms(word,poss[0],10);
        Arrays.sort(synonyms);
        for (int i = 0; i < 5; i++) {
            System.out.println(synonyms[i]);
        }
    }
}
public static void main(String args[])
{
    Blah b=new Blah();
    b.setup();

}


}
Was it helpful?

Solution

Documentation is here (just click the method names in the right column):

http://www.rednoise.org/rita/wordnet/documentation/

But I have to admit it is not very detailed.

When I run this, I repeatedly get poss = [n] synonyms = [chip, diode, microchip, thermistor]

If you don't, you may want to check if you have multiple versions of WordNet JARs in your classpath (the word lists are inside the Jar in a folder called rita/wordnet/wdict.dat)

You can use Arrays.toString() to easily print the contents of an array for debugging, without having to use a for loop every time.

The middle argument ('n') in this case is the word class ("a" = adjective, "n" = noun, "r" = adverb, "v" = verb) since some words (like "good") may exist in multiple classes and each of them has individual synonyms.

OTHER TIPS

In the current version of RiTa, you can call randomizeResults(false); to disable this behavior (though you will now need to download WordNet itself separately):

import rita.*;
import java.util.*;

public static void main(String[] args)
{
  RiWordNet rw = new RiWordNet("/WordNet-3.1"); // point to local installation
  rw.randomizeResults(false);                   // don't randomize results
  String[] s = rw.getAllSynonyms("car", "n");
  System.out.println(Arrays.asList(s));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top