WordNet 2.1 compatibility -- null pointer ex

  • msammer

    msammer - 2005-08-12

    Using the jwnl13rc3 download and WordNet 2.1, the getDirectHypernym method throws a null pointer exception. (this is after using the fix noted in an earlier thread that allows WordNet 2.1 to work at all).  Under WordNet 2.0, this exception is not thrown.  Has anyone found a fix for this?  It does not appear that the problem actually has anything to do with the getDirectHypernym method -- that is just where it is showing up for me.

    • se_webster

      se_webster - 2005-09-22

      Could you send the word you searched for and full stack dump, I think this is because new instance hypernym's have been added for 2.1  - its a simple fix as long as all you want to do is map instance hypernym's (@i) to hypernym's (@)


    • Jim Irwin

      Jim Irwin - 2005-10-26

      So what is the quick fix?  For example, I've encountered this with "Hegira" sense 1 failing to find hypernym because it does have the new instance hypernym pointer type.

      I prevented the exception by adding the following to the JWNLResource_en.properties file:


      It is also necessary to add the following to the net.didion.jwnl.data.PointerType.java file:

      // New hypernym pointer types for Wordnet 2.1

      public static final PointerType INSTANCE_HYPERNYM = new PointerType("INSTANCE_HYPERNYM", "INSTANCE_HYPERNYM_KEY", N | V);

      public static final PointerType INSTANCES_HYPONYM = new PointerType("INSTANCES_HYPONYM", "INSTANCES_HYPONYM_KEY", N | V);

      And modify the ALL_TYPES list in the same file to add the new pointer types:
      /** A list of all <code>PointerType</code>s. */
      private static final List ALL_TYPES = Collections.unmodifiableList(Arrays.asList(new PointerType[] {
              // New pointer types for Wordnet 2.1

      These changes prevent the exception, but they don't function like the Wordnet code.  A search for HYPERNYM pointer types won't return the INSTANCE_HYPERNYM pointers.

    • Jim Irwin

      Jim Irwin - 2005-10-26

      Addendum:  the following modification to net.didion.jwnl.data.PointerTarget will properly handle searchs for hypernyms and hyponyms.  A search for hypernyms will return the new instance-of hypernym, and a search for hyponyms will return the new has-instance hyponyms:

      /** Get all pointers of type <code>type</code>.*/
      public Pointer[] getPointers(PointerType type) {
          List list = new ArrayList();
          Pointer[] pointers = getPointers();
          for (int i = 0; i < pointers.length; ++i) {
              if (pointers[i].getType().equals(type)
                  || (type.equals(PointerType.HYPERNYM) && pointers[i].getType().equals(PointerType.INSTANCE_HYPERNYM))
                  || (type.equals(PointerType.HYPONYM) && pointers[i].getType().equals(PointerType.INSTANCES_HYPONYM))) {
          return (Pointer[])list.toArray(new Pointer[list.size()]);

    • Dan Blanchard

      Dan Blanchard - 2006-01-09

      I implemented both of these fixes and still get a NullPointerException when I call the getHypernymTree function on certain words (i.e., "chair") but not all ("cheese" and "bottle" work fine).  Anyone have any idea why that owuld be?

    • Dan Blanchard

      Dan Blanchard - 2006-01-09

      On further analysis, I found the NullPointerException is because a call in PointerTarget.getPointers(PointerType type) to pointers[i].getType sometimes returns null.  I have no idea why this happens, but some of the pointers in the pointer list getPointers returns have null pointer types, but not targets or anything else.

      • Jim Irwin

        Jim Irwin - 2006-01-09

        I don't get any exceptions on any of the words you mentioned.  Are you sure you implemented all the code fixes?  See both my previous postings.

        I do see one additional change I made to my code base that I didn't mention in the earlier posts.  I don't know if it would prevent the error you are seeing.

        add the following to the static initializer that follows the initialize() method definition:

        setSymmetric(INSTANCE_HYPERNYM, INSTANCES_HYPONYM);  // New with Wordnet 2.1

    • Dan Blanchard

      Dan Blanchard - 2006-01-09

      I just added the setSymmetric code you mentioned, and I double-checked the modifications you specified, and I still get the problem that _pointers[13] for:
      [Synset: [Offset: 4114532] [POS: noun] Words: seat -- (furniture that is designed for sitting on; "there were not enough seats for all the guests")]
      has a null pointer type during a getHypernymTree call.  Are there any other small modifications you made?

      • Jim Irwin

        Jim Irwin - 2006-01-09

        As far as I can tell, null pointer types are being returned by the utility, but not because of (or the lack of) code added to handle the new INSTANCE hypernym types.  The structure of the PointerUtil code that is used to create the tree list prevents it from recording the type of the actual pointer that was followed when an item was added to the tree list.

        It looks like each tree contains a root node that represents the original synset, and that root node always has a null pointer type (since no pointer was followed to obtain the root node).  The rest of the nodes have a pointer type of HYPERNYM, regardless of whether the pointer was actually HYPERNYN or INSTANCE_HYPERNYM.

        If you need to distinguish between HYPERNYM and INSTANCE_HYPERNYM types, it looks like you will have to write your own code to walk the synsets instead of using the PointerUtils class. 

    • Dan Blanchard

      Dan Blanchard - 2006-01-10

      I don't need to distinguish between the HYPERNYM and INSTANCE_HYPERNYM types, but I do need getHypernymTree to work correctly.  Currently, some synsets throw exceptions as I mentioned above.  Does your code not throw exceptions for getHypernymTree on the first noun synset of "stool"?

      • Jim Irwin

        Jim Irwin - 2006-01-10

        Nope, calling getHypernymTree does not throw exceptions for me.  For "stools" sense 1, I get the following results when I walk the tree with getAllMatches():

        stool => seat => furniture => furnishing => instrumentality => artifact => unit => object => physical_entity => entity

        I don't think there are any of the new INSTANCE pointer types in that tree, so perhaps your code has some other problem.

    • Toph

      Toph - 2006-01-17

      I'm experiencing the same NullPointerException with "seat" after making all the changes suggested (which will be nevertheless useful at some point).

      • Dan Blanchard

        Dan Blanchard - 2006-01-17

        I ended up modifying the getPointers method to just ignore pointers that have a null PointerType.

        • Toph

          Toph - 2006-01-17

          After much searching, I isolated the problem to PointerType.getPointerTypeForKey(String) which was not retrieving the new instance types even though they were seemingly added correctly to the KEY_TO_POINTER_TYPE_MAP. 

          In frustration, I had a crazy idea.  I thought maybe there was a new line problem in JWNLResource_en.properties because I copied and pasted from Firefox. 

          After erasing the INSTANCE_HYPERNYM_KEY and INSTANCES_HYPONYM_KEY lines provided by jimiriwn and retyping them exactly, the problem was resolved.  I guess it was adding some invisible ASCII to the new tags therefore they weren't being properly recalled by the HashMap when the key from WordNet itself was used.  Maybe others are having this same problem?  Very frustrating.

          Now "seat", "stool", "chair", etc. work.  Thanks jimirwin for the hacks.

        • Anonymous

          Anonymous - 2006-03-02

          Could you please post the modified part into this forum? I have the same problem with the Null Pointer Exception.
          Thanks a lot.

    • qhreul

      qhreul - 2006-04-04

      I also get the problem on the following two bits of code:

      PointerTargetTree hypernyms = PointerUtils.getInstance().getHypernymTree(dict.lookupIndexWord(POS.NOUN, "country").getSense(1));


      DOG = dict.lookupIndexWord(POS.NOUN, "country");
      Synset dogSyns = DOG.getSense(1);
      Pointer [] point = dogSyns.getPointers();
      for ( int i =0, j = point.length; i < j; i++ ) {
        if ( point[i].getType().getLabel().equals("hypernym")) {

    • Rohit Kochar

      Rohit Kochar - 2007-09-21

      I am trying to find the relation among two nouns using jwnl and wordnet but whenever i  try to use findrelationship() method of class RelationshipFinder i get an NULL Pointer Exception
      This method always throws an exception whenever i try to find
      HYPERNYM or HYPONYM type of realtion.I am using Wordnet 2.0 and jwnl 1.3.

      The code taht i tried is as follows..

      public static void main(String args[])
      IndexWord DOG;
      IndexWord CAT;
      String propsFile = args[0];
              try {
                  JWNL.initialize(new FileInputStream(propsFile));
                  } catch (Exception ex) {}
      DOG = Dictionary.getInstance().getIndexWord(POS.NOUN, "dog");
      CAT = Dictionary.getInstance().lookupIndexWord(POS.NOUN, "cat");
      RelationshipFinder r=RelationshipFinder.getInstance();
      RelationshipList list =r.findRelationships(CAT.getSense(1), DOG.getSense(1),PointerType.HYPERNYM);
          System.out.println("Hypernym relationship between \&quot;" + DOG.getLemma() + "\&quot; and \&quot;" + CAT.getLemma() + "\&quot;:");
              for (Iterator itr = list.iterator(); itr.hasNext();) {
                  ((Relationship) itr.next()).getNodeList().print();
      }catch(Exception e){e.printStackTrace();};

      Please help to fix this problem.

    • Vanessa Lopez

      Vanessa Lopez - 2007-10-25


      Jim, I made all the modifications you suggested in the code, and in properties file, but it is giving me a null pointer exception error in
      int framesSize = Integer.parseInt(JWNL.resolveMessage("NUMBER_OF_VERB_FRAMES"));

      which I can avoid with int framesSize = 35; .. but then I have the pointers null exception .. I think I am missing something here, which is probably related to the JWNLResource_en.properties, I just found it somewhere on the web and put it on my classpath.. Should I do something else?

      Many thanks!

  • Nabeel Naqeebi

    Nabeel Naqeebi - 2017-10-17

    hey every one, I want to get All the hypernyms of a specific word(i.e. apple) and here is the code, kindly change in it.
    private void demonstrateListOperation(IndexWord word) throws JWNLException {
    // Get all of the hypernyms (parents) of the first sense of word
    PointerTargetNodeList hypernyms = PointerUtils.getInstance().getDirectHypernyms(word.getSense(1));
    System.out.println("Direct hypernyms of \"" + word.getLemma() + "\":");


Log in to post a comment.