how can i get hypernyms of multiple words using java

444 Views Asked by At

I want to get "hypernyms"of multiple words using WordNet dictionary in java.

**What is Hypernyms?**a word with a broad meaning constituting a category into which words with more specific meanings fall; a superordinate. For example, colour is a hypernym of red.

So if we have following words 1) apple
2) banana
3) hepatitis
4) tree
5) mango

the desire output is that Sense 1:

Apple: -- (fruit with red or yellow or green skin and sweet to tart crisp whitish flesh)

=> edible fruit -- (edible reproductive body of a seed plant especially one having sweet flesh)

=> produce, green goods, green groceries, garden truck -- (fresh fruits and vegetable grown for the market)

=> food, solid food -- (any solid substance (as opposed to liquid) that is used as a source of nourishment; "food and drink")

=> solid -- (a substance that is solid at room temperature and pressure)

=> substance, matter -- (that which has mass and occupies space; "an atom is the smallest indivisible unit of matter")

=> physical entity -- (an entity that has physical existence)

=> entity -- (that which is perceived or known or inferred to have its own distinct existence (living or nonliving))

=> fruit -- (the ripened reproductive body of a seed plant)

=> reproductive structure -- (the parts of a plant involved in its reproduction)

=> plant organ -- (a functional and structural unit of a plant or fungus)

=> plant part, plant structure -- (any part of a plant or fungus)

=> natural object -- (an object occurring naturally; not made by man)

=> whole, unit -- (an assemblage of parts that is regarded as a single entity; "how big is that part compared to the whole?"; "the team is a unit")

=> object, physical object -- (a tangible and visible entity; an entity that can cast a shadow; "it was full of rackets, balls and other objects")

=> physical entity -- (an entity that has physical existence)

=> entity -- (that which is perceived or known or inferred to have its own distinct existence (living or nonliving))

=> pome, false fruit -- (a fleshy fruit (apple or pear or related fruits) having seed chambers and an outer fleshy part)

=> fruit -- (the ripened reproductive body of a seed plant)

=> reproductive structure -- (the parts of a plant involved in its reproduction)

=> plant organ -- (a functional and structural unit of a plant or fungus)

=> plant part, plant structure -- (any part of a plant or fungus)

=> natural object -- (an object occurring naturally; not made by man)

=> whole, unit -- (an assemblage of parts that is regarded as a single entity; "how big is that part compared to the whole?"; "the team is a unit")

=> object, physical object -- (a tangible and visible entity; an entity that can cast a shadow; "it was full of rackets, balls and other objects")

=> physical entity -- (an entity that has physical existence)

=> entity -- (that which is perceived or known or inferred to have its own distinct existence (living or nonliving))

3

There are 3 best solutions below

0
On BEST ANSWER

What is hypernyms ?

Answer: A word with a broad meaning constituting a category into which words with more specific meanings fall; a superordinate. For example, colour is a hypernym of red.

i am listing the code for extracting the hypernyms tree... it will give you the detailed tree of any word which is present in the WordNet 3.0 dictionary.

Call this method

private static ArrayList<String> getHypernymTerm( PointerTargetNodeList ptnl,
                                                        ArrayList<String> parent2, String str )  
            throws JWNLException{
      ArrayList<String> parent = parent2;
      if ( !str.equals("entity") ) {
        for (Iterator<?> itr = ptnl.iterator(); itr.hasNext();) {
          PointerTargetNode node = (PointerTargetNode) itr.next();
          Synset synset = node.getSynset();
          String term = synset.getWord(0).getLemma();
          parent.add(term);
          PointerTargetNodeList targets = new PointerTargetNodeList(synset.getTargets(PointerType.HYPERNYM) );
      if (targets.size() > 0) {
            parent = getHypernymTerm( targets, parent, term);
            }
        }

      }
      return parent;
    }

First of all you have to store the word in an array and rest of the code is as followed. if any one need the whole code then he/she can contact me at me g.mail: nabeelraza174

        for(int a = 0 ; a < strArray.length ; a++){
            FRUIT[a] = Dictionary.getInstance().getIndexWord(POS.NOUN, hyp[a]);
        }

        for(int b = 0 ; b < FRUIT.length  ; b++){
            ArrayList<String> arrayList = new ArrayList<String>();
            arrayList.add(hyp[b]);

            PointerTargetTree printlist= demonstrateListOperation(FRUIT[b]);
            //printlist.print();
            PointerTargetNodeList ppt = printlist.getRootNode().getChildTreeList();
        string is ArrayList type
            ListClass temp = new ListClass();
            temp.string_list = getHypernymTerm(ppt, arrayList, hyp[b]);
1
On

Use Wordnet.

Wordnet can be accessed using Java through its Java API. Before proceeding to APIs, first understand the structure of wordnet library on its portal.

0
On

It can be done by using Set to store all the Hypernyms then and Iterate over.