使用Java中的wordnet查找给定形容词的同义词和反义词集

问题描述 投票:2回答:1

我正在Java中的nlp项目上工作,我想使用wordnet获得给定形容词的同义词和反义词集。到目前为止,我已经做到了这一点,但是我没有得到所需的输出,它只是同义词和反义词集的列表。

    net.didion.jwnl.dictionary.Dictionary dict;
    File file = new File("properties.xml");
    JWNL.initialize(new FileInputStream(file));
    dict = net.didion.jwnl.dictionary.Dictionary.getInstance();

    IndexWord indexWord = dict.getIndexWord(POS.ADJECTIVE, "bad");

    Synset[] senses = indexWord.getSenses();


    for(int i=0;i<senses.length;i++){
        Synset set= senses[i];
        Word[] words=set.getWords();
        for(int k=0;k<words.length;k++){
            System.out.println(i+","+k+":"+words[k].getLemma());
        }

    }

输出

INFO:安装字典net.didion.jwnl.dictionary.FileBackedDictionary@70177ecd

好,满了好,好,可估计的好,尊敬的可敬的有益的好,好,好,只是,直立熟练专家,好,练习过精通熟练的熟练好,亲 ,好,附近,可信 ,好,安全安全好,对 ,成熟的好,好(p),有效,好,in_effect(p),in_force(p),好,好,认真的好,声音好,称呼好,诚实 ,好,未受破坏的未受破坏的好,

java nlp wordnet
1个回答
0
投票

您需要过滤答案,

Synset syn;
       String word = null;
       ArrayList syns = new ArrayList<>();
         for(int i=0;i<sensesVerbe.length;i++){
            // syn=sensesVerbe[i];          
            //System.out.println(sensesVerbe[i]); 
           
            String v= sensesVerbe[i].toString();
            //String v= sensesVerbe[i].toString();
            if(v.contains("Words:")){
                          //System.out.println("yeeh");
                          //System.out.println("Index of NN = "+ line.indexOf("N "));
                          int chaine = v.indexOf("Words:");
                          //System.out.println("index Words: ="+ chaine+"");
                          
                          int chaine1 = v.indexOf("--");
                          //System.out.println("index -- ="+ chaine1+"");
                          
                          word = v.substring(chaine+6, chaine1);
                          //System.out.println("the sub of line where index is ("+ chaine +","+ chaine1 +") is :" + word);
                         
                          //System.out.println(word); 
                          String mots[] =word.split(",");
                          //System.out.println("mots séparés :"); 
                          for (int j = 0; j < mots.length; j++) {
                                mots[j]=mots[j].replaceAll(" ", "");
                                //System.out.println(mots[j]);
                                if(!syns.contains(mots[j].toLowerCase())){
                                   syns.add(mots[j].toLowerCase());
                                }
                            }                                                    
               }
         }
© www.soinside.com 2019 - 2024. All rights reserved.