Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

How to Print Hypernym to a String

Help
A. Shiraz
2009-04-25
2013-04-29
  • A. Shiraz
    A. Shiraz
    2009-04-25

    I would like to get the output from hypernym.print() into a string and then regex or search the string.

    This is what I have :

            String dir ="C:\\SET\\lib\\wordnet\\wordnet\\jwnl14-rc2\\config\\";
            try {
                JWNL.initialize(new FileInputStream(dir +"file_properties.xml"));
                Dictionary dict = Dictionary.getInstance();
                IndexWord word = dict.getIndexWord(POS.NOUN, "Lydia");
                PointerTargetTreeNodeList hypernyms = PointerUtils.getInstance().getHypernymTree(word.getSense(1)).getRootNode().getChildTreeList();
                hypernyms.print(); } catch (Exception e) {
                e.printStackTrace();
            }

    It gives me an output like this:
      [PointerTargetTreeNode: [Synset: [Offset: 8454420] [POS: noun] Words: geographical_area, geographic_area, geographical_region, geographic_region -- (a demarcated area of the Earth)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? true] [Has Children? true] [Has Pointers? false]]
        [PointerTargetTreeNode: [Synset: [Offset: 8510527] [POS: noun] Words: region -- (a large indefinite location on the surface of the Earth; "penguins inhabit the polar regions")] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
          [PointerTargetTreeNode: [Synset: [Offset: 26074] [POS: noun] Words: location -- (a point or extent in space)] [PointerType: [Label: hypernym] [Key: @] Applies To: noun, verb] [Has Parent? false] [Has Children? true] [Has Pointers? false]]
            [PointerTargetTreeNode: [Synset: [Offset: 3122] [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: 1930] [POS: noun] Words: physical_entity -- (an entity that has physical existence)] [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]]

    I would like to take this output into a string and then query it please. How do I do that short of writing it into a file and then querying that file?

     
    • A. Shiraz
      A. Shiraz
      2009-04-26

      Ok just figured this out. I dont wish this befalls anyone else , kindly please put a wrapper function that does this:

              super();
              try {
                  JWNL.initialize(new FileInputStream(dir));
                  dict = Dictionary.getInstance();
                  word = dict.getIndexWord(POS.NOUN, noun);
                  hypernyms = PointerUtils.getInstance().getHypernymTree(word.getSense(1)).getRootNode().getChildTreeList();
             
      ByteArrayOutputStream b = new ByteArrayOutputStream();
                  PrintStream out = new PrintStream(b);
                  hypernyms .print(out);
                  System.out.println("\n\n *** \n\n" + b.toString());
             
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }