how to check whether word in wordNet or not

非 Y 不嫁゛ 提交于 2020-01-04 02:06:11

问题


I start to learn about wordNet and till know I found the synonymous for a specific word now I have a file and I want to tokenize this text using n-gram for example

String s="I like to wear tee shirt";

after using n-gram it will be

I
like
to 
wear 
tee 
shirt
.
.
.
wear tee
tee shirt

and so on and then I want to know if tee shirt is a biword (I can consider it as one word in the search index) so I thought to use wordNet to check whether (tee shirt) in wordNet or not

if True then it is a biword and have a synonymous for example jersey, T-shirt, tee shirt

if false then it is Not

is there any method in Jaws check if this word in wordnet or not?? or I should see if the word has a synonymous then it's by default in it (as a solution I thought of)


回答1:


I found a solution for my problem since no one answer the question I will post what the answer for future visitor that will have the same problem I hope that will be useful :)

public static boolean is_Missing_WordNet(String r,String posTag){
   // System.out.println("inside is_missing_Wordnet "+r);
          boolean flag=true;
              configureJWordNet();
              Dictionary dictionary = Dictionary.getInstance();
              IndexWord word;
        try {
            if(posTag.equals("VBG"))//Verb
                 { word = dictionary.lookupIndexWord(POS.VERB, r);}
            else {word = dictionary.lookupIndexWord(POS.NOUN, r);}

            Synset[] senses = word.getSenses();

                if(senses!=null && senses.length>0){
                 if(senses[0].toString().toLowerCase().contains(r)|| senses[0].toString().contains(r.replace(" ","_")))
                 { System.out.println("sense;;;; "+senses[0].toString());flag=false;}
                  }                                       
                else{System.out.println("wordnet has no sense of "+r );return true; }


                }
        catch(NullPointerException ex){return true;}
         catch (JWNLException ex) {return true;
                    }
        return flag; 
    } 

this function return true if it is missing from WordNet dictionary



来源:https://stackoverflow.com/questions/33946485/how-to-check-whether-word-in-wordnet-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!