Package opennlp.tools.parser

Examples of opennlp.tools.parser.Parse


 
  public List getNamedEntities() {
    List names = new ArrayList();
    List kids = new LinkedList(Arrays.asList(parse.getChildren()));
    while (kids.size() > 0) {
      Parse p = (Parse) kids.remove(0);
      if (entitySet.contains(p.getType())) {
        names.add(p);
      }
      else {
        kids.addAll(Arrays.asList(p.getChildren()));
      }
    }
    return createParses((Parse[]) names.toArray(new Parse[names.size()]));
  }
View Full Code Here


  }

  public List getSyntacticChildren() {
    List kids = new ArrayList(Arrays.asList(parse.getChildren()));
    for (int ci = 0; ci < kids.size(); ci++) {
      Parse kid = (Parse) kids.get(ci);
      if (entitySet.contains(kid.getType())) {
        kids.remove(ci);
        kids.addAll(ci, Arrays.asList(kid.getChildren()));
        ci--;
      }
    }
    return createParses((Parse[]) kids.toArray(new Parse[kids.size()]));
  }
View Full Code Here

  public List getTokens() {
    List tokens = new ArrayList();
    List kids = new LinkedList(Arrays.asList(parse.getChildren()));
    while (kids.size() > 0) {
      Parse p = (Parse) kids.remove(0);
      if (p.isPosTag()) {
        tokens.add(p);
      }
      else {
        kids.addAll(0,Arrays.asList(p.getChildren()));
      }
    }
    return createParses((Parse[]) tokens.toArray(new Parse[tokens.size()]));
  }
View Full Code Here

      return null;
    }
  }

  public boolean isParentNAC() {
    Parse parent = parse.getParent();
    while(parent != null) {
      if (parent.getType().equals("NAC")) {
        return true;
      }
      parent = parent.getParent();
    }
    return false;
  }
View Full Code Here

    }
    return false;
  }

  public opennlp.tools.coref.mention.Parse getParent() {
    Parse parent = parse.getParent();
    if (parent == null) {
      return null;
    }
    else {
      return new DefaultParse(parent,sentenceNumber);
View Full Code Here

    return parse.toString();
  }

 
  public opennlp.tools.coref.mention.Parse getPreviousToken() {
    Parse parent = parse.getParent();
    Parse node = parse;
    int index=-1;
    //find parent with previous children
    while(parent != null && index < 0) {
      index = parent.indexOf(node)-1;
      if (index < 0) {
        node = parent;
        parent = parent.getParent();
      }
    }
    //find right-most child which is a token
    if (index < 0) {
      return null;
    }
    else {
      Parse p = parent.getChildren()[index];
      while (!p.isPosTag()) {
        Parse[] kids = p.getChildren();
        p = kids[kids.length-1];
      }
      return new DefaultParse(p,sentenceNumber);
    }
  }
View Full Code Here

      return new DefaultParse(p,sentenceNumber);
    }
  }
 
  public opennlp.tools.coref.mention.Parse getNextToken() {
    Parse parent = parse.getParent();
    Parse node = parse;
    int index=-1;
    //find parent with subsequent children
    while(parent != null) {
      index = parent.indexOf(node)+1;
      if (index == parent.getChildCount()) {
        node = parent;
        parent = parent.getParent();
      }
      else {
        break;
      }
    }
    //find left-most child which is a token
    if (parent == null) {
      return null;
    }
    else {
      Parse p = parent.getChildren()[index];
      while (!p.isPosTag()) {
        p = p.getChildren()[0];
      }
      return new DefaultParse(p,sentenceNumber);
    }
  }
View Full Code Here

      String tok = convertToken(str.nextToken());
      tokens.add(tok);
      sb.append(tok).append(" ");
    }
    String text = sb.substring(0, sb.length() - 1).toString();
    Parse p = new Parse(text, new Span(0, text.length()), "INC", 1, null);
    int start = 0;
    for (Iterator ti = tokens.iterator(); ti.hasNext();) {
      String tok = (String) ti.next();
      p.insert(new Parse(text, new Span(start, start + tok.length()), ParserME.TOK_NODE, 0));
      start += tok.length() + 1;
    }
    Parse[] parses;
    if (numParses == 1) {
      parses = new Parse[] { parser.parse(p)};
View Full Code Here

        sentenceNumber=0;
        document.clear();
        parses.clear();
      }
      else {
        Parse p = Parse.parseParse(line);
        parses.add(p);
        Mention[] extents = treebankLinker.getMentionFinder().getMentions(new DefaultParse(p,sentenceNumber));
        //construct new parses for mentions which don't have constituents.
        for (int ei=0,en=extents.length;ei<en;ei++) {
          //System.err.println("PennTreebankLiner.main: "+ei+" "+extents[ei]);
         
          if (extents[ei].getParse() == null) {
            Parse snp = new Parse(p.getText(),extents[ei].getSpan(),"NML",1.0);
            p.insert(snp);
            extents[ei].setParse(new DefaultParse(snp,sentenceNumber));
          }
         
        }
View Full Code Here

    parseMap = new HashMap();
    for (int ei=0,en=entities.length;ei<en;ei++) {
      if (entities[ei].getNumMentions() > 1) {
        for (Iterator mi=entities[ei].getMentions();mi.hasNext();) {
          MentionContext mc = (MentionContext) mi.next();
          Parse mentionParse = ((DefaultParse) mc.getParse()).getParse();
          parseMap.put(mentionParse,new Integer(ei+1));
          //System.err.println("CorefParse: "+mc.getParse().hashCode()+" -> "+ (ei+1));
        }
      }
    }
View Full Code Here

TOP

Related Classes of opennlp.tools.parser.Parse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.