Wordnet Find Synonyms

前端 未结 4 1158
小鲜肉
小鲜肉 2020-12-23 10:44

I am searching for a way to find all the synonyms of a particular word using wordnet. I am using JAWS.

For example:

love(v):

4条回答
  •  失恋的感觉
    2020-12-23 11:22

    How about using RitaWN instead of JAWS? I see it is listed as one of the available API in http://wordnet.princeton.edu/wordnet/related-projects/#Java I also see it has getAllSynonyms() method, they provide an example and it works.

    Check this out:

    import java.io.IOException;
    import java.util.Arrays;
    
    import rita.*;
    
    public class Synonyms {
    
    public static void main(String[] args) throws IOException {
    
        // Would pass in a PApplet normally, but we don't need to here
        RiWordNet wordnet = new RiWordNet("C:\\Program Files (x86)\\WordNet\\2.1");
    
        // Get a random noun
        String word = "love";//wordnet.getRandomWord("n");
        // Get max 15 synonyms
        String[] synonyms = wordnet.getAllSynonyms(word, "v");
    
        System.out.println("Random noun: " + word);
        if (synonyms != null) {
            // Sort alphabetically
            Arrays.sort(synonyms);
            for (int i = 0; i < synonyms.length; i++) {
                System.out.println("Synonym " + i + ": " + synonyms[i]);
            }
        } else {
            System.out.println("No synyonyms!");
        }
    }
    

    Make sure to get the latest downloads and documentation from http://www.rednoise.org/rita/wordnet-old/documentation/index.htm

提交回复
热议问题