How to pluck the substrings out of nodelists?

Help
2004-02-25
2013-04-29
  • Pat Halogen

    Pat Halogen - 2004-02-25

    Is there a simple way of getting the common parent for two words out of the nodelist that is printed to console? i.e. How do you get the common parent node out of the PointerTargetNodeList resulting from the line:

                        PointerTargetNodeList hypernyms = PointerUtils.getInstance().getDirectHypernyms(start.getSense(i));

    Can I use the commonParentIndex to count the nodes from the source-node to the common parent?

    The methods are badly documented, and it is hard to know what they do unless you get to the source code level. For example, it seems to me that the root node should actually be called source node: in any ontology the root node is the topmost ancestral node. Or have I got it completely wrong? Try printing root node's children, and you actually get source node's ancestors. Hey, I guess I must have had too many beers today, but it doesn`t seem to make any sense.

    For example, the following code line:

                        PointerTargetTreeNodeList pttnode = rootnode.getChildTreeList();

    gives the following printout:

    rootnode: :[PointerTargetTreeNode: [Synset: [Offset: 2001223] [POS: noun] Words: dog, domestic_dog, Canis_familiaris -- (a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds; "the dog barked all night")] null [Has Parent? true] [Has Children? true] [Has Pointers? false]]
      [PointerTargetTreeNode: [Synset: [Offset: 2000516] [POS: noun] Words: canine, canid -- (any of various fissiped mammals with nonretractile claws and typically long muzzles)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? true] [Has Children? true] [Has Pointers? false]]
        [PointerTargetTreeNode: [Synset: [Offset: 1992546] [POS: noun] Words: carnivore -- (terrestrial or aquatic flesh-eating mammal; terrestrial carnivores have four or five clawed digits on each limb)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
          [PointerTargetTreeNode: [Synset: [Offset: 1805729] [POS: noun] Words: placental, placental_mammal, eutherian, eutherian_mammal -- (mammals having a placenta; all mammals except monotremes and marsupials)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
            [PointerTargetTreeNode: [Synset: [Offset: 1780968] [POS: noun] Words: mammal -- (any warm-blooded vertebrate having the skin more or less covered with hair; young are born alive except for the small subclass of monotremes and nourished with milk)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
              [PointerTargetTreeNode: [Synset: [Offset: 1394664] [POS: noun] Words: vertebrate, craniate -- (animals having a bony or cartilaginous skeleton with a segmented spinal column and a large brain enclosed in a skull or cranium)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
                [PointerTargetTreeNode: [Synset: [Offset: 1389442] [POS: noun] Words: chordate -- (any animal of the phylum Chordata having a notochord or spinal column)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
                  [PointerTargetTreeNode: [Synset: [Offset: 12748] [POS: noun] Words: animal, animate_being, beast, brute, creature, fauna -- (a living organism characterized by voluntary movement)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
                    [PointerTargetTreeNode: [Synset: [Offset: 3226] [POS: noun] Words: organism, being -- (a living thing that has (or can develop) the ability to act or function independently)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
                      [PointerTargetTreeNode: [Synset: [Offset: 3009] [POS: noun] Words: living_thing, animate_thing -- (a living (or once living) entity)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
                        [PointerTargetTreeNode: [Synset: [Offset: 16236] [POS: noun] Words: object, physical_object -- (a tangible and visible entity; an entity that can cast a shadow; "it was full of rackets, balls and other objects")] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
                          [PointerTargetTreeNode: [Synset: [Offset: 1740] [POS: noun] Words: entity -- (that which is perceived or known or inferred to have its own distinct existence (living or nonliving))] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? false] [Has Pointers? false]]

    Or is it that the JWNL's child nodes have nothing to do with the child nodes in WordNet's conceptual hierarchy being two separate node structures?

    All this puzzles me greatly, and instead of using the API, I have converted the PrintStream to FileStream and use then the file to StringTokenize the desired substrings from the lists of hypernyms. This is, of course, a silly way to do it, but it is better can getting nothing done.

    ps

     
    • Anonymous - 2004-03-01

      Hi,

      I've been trying to do the same thing; I am just using the commonParentIndex as an index to get the parent node. I am not sure if this is actually right but seems to do a reasonable job sometimes :) I agree the documentation isn't great but its not like you are paying for it...

      Also, in relation to your other post I am using a size check to see if the relationship is empty, and if it is ignore it.

                              RelationshipList list = RelationshipFinder.getInstance().findRelationships(synsetA[x], synsetB[y], PointerType.HYPERNYM);
                              //Make sure there are some relationships
                              if(list.size()>0){

      This sort of thing.

      if you have msn messenger may be we could swap tips add nickpholden@hotmail.com

       
    • dbcubix

      dbcubix - 2006-10-18

      @ puusee
      Is there a simple way of getting the common parent for two words out of the nodelist that is printed to console?

      I came across the same thing and here is the code to do it.  It may not be pretty but it works...

      package net.didion.jwnl.utilities;

      import net.didion.jwnl.JWNL;
      import net.didion.jwnl.JWNLException;
      import net.didion.jwnl.data.IndexWord;
      import net.didion.jwnl.data.POS;
      import net.didion.jwnl.data.Synset;
      import net.didion.jwnl.data.Pointer;
      import net.didion.jwnl.data.Word;
      import net.didion.jwnl.data.PointerType;
      import net.didion.jwnl.data.PointerUtils;
      import net.didion.jwnl.data.list.PointerTargetNodeList;
      import net.didion.jwnl.data.list.PointerTargetTree;
      import net.didion.jwnl.data.relationship.AsymmetricRelationship;
      import net.didion.jwnl.data.relationship.Relationship;
      import net.didion.jwnl.data.relationship.RelationshipFinder;
      import net.didion.jwnl.data.relationship.RelationshipList;
      import net.didion.jwnl.dictionary.Dictionary;

      import java.io.FileInputStream;
      import java.util.*;

      public class WordCore {

        private static final String USAGE = "java Examples <properties file>";

        public static void main(String[] args) {
          if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(-1);
            }
          String propsFile = args[0];
          try {
            // initialize JWNL (this must be done before JWNL can be used)
            JWNL.initialize(new FileInputStream(propsFile));
            new WordCore().go();
            }
          catch (Exception ex) {
            ex.printStackTrace();
            System.exit(-1);
            }
          }

        public void go() throws JWNLException {
          Testing("Aryan", "Jews");
          }

        private void Testing(String word1, String word2) throws JWNLException {
          IndexWord j = Dictionary.getInstance().lookupIndexWord(POS.NOUN, word1);
          IndexWord k = Dictionary.getInstance().lookupIndexWord(POS.NOUN, word2);
         
          RelationshipList list = RelationshipFinder.getInstance().findRelationships(j.getSense(1), k.getSense(1), PointerType.HYPERNYM);
          // This 'for statement' is for debugging purposes
          for (Iterator itr = list.iterator(); itr.hasNext();) {
            ((Relationship) itr.next()).getNodeList().print();
            }
          int CommonParentIndex = ((AsymmetricRelationship) list.get(0)).getCommonParentIndex();
         
          String lemma1 = j.getLemma();
          String lemma2 = k.getLemma();
          String parent = lemma1;
          System.out.println(lemma1);
          for(int x = 1; x <= CommonParentIndex; x++) {
            IndexWord l = Dictionary.getInstance().lookupIndexWord(POS.NOUN, parent);
            parent = GetParentSynset(l.getSense(1)).getWord(0).getLemma();
            }
          System.out.println("  " + parent);
          System.out.println(lemma2);
         
          System.out.println("Common Parent Index: " + CommonParentIndex);
          System.out.println("Links Away: " + ((Relationship) list.get(0)).getDepth());
          }

        public static Synset GetParentSynset(Synset node) throws JWNLException {
          Synset parent = node;
          Pointer [] point = node.getPointers();
          for (int i = 0, d = point.length; i < d; i++) {
            if (point[i].getType().getLabel().equals("hypernym")) {
              parent = point[i].getTargetSynset();
              }
            }
          return parent;
          }
        }

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks