Coverting PointerTargetTree's to Strings

Help
devilspawn
2007-06-28
2013-04-29
  • devilspawn
    devilspawn
    2007-06-28

    Would be possible to get the code for this? I have tried to modify the PointerUtils.makePointerTargetTreeList() function but I have been unable to make it work for Word only.

    Thanks

     
  • devilspawn
    devilspawn
    2007-06-28

    private ArrayList getHypernym( PointerTargetTreeNodeList l, ArrayList p ) throws JWNLException {
      ArrayList parent = p;
      for (Iterator itr = l.iterator(); itr.hasNext();) {
        PointerTargetNode node = (PointerTargetNode) itr.next();
        Synset synset = node.getSynset();
        String name = synset.getWord(0).getLemma();
        parent.add(name);        
        PointerTargetNodeList targets = new PointerTargetNodeList(synset.getTargets(PointerType.HYPERNYM));
        if (targets.size() > 0) {
          parent = getHypernymTerm( targets, parent, name);
        }
      }
      return parent;
    }
       
    private ArrayList getHypernymTerm( PointerTargetNodeList l, ArrayList p, String s ) 
            throws JWNLException{
      ArrayList parent = p;
      if ( !s.equals("entity") ) {
        for (Iterator itr = l.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;
    }

    I managed to get the code working for myself.

    Cheers,