Package opennlp.tools.parser

Examples of opennlp.tools.parser.Parse


      String tok = str.nextToken();
      tokens.add(tok);
      sb.append(tok).append(" ");
    }
    String text = sb.substring(0, sb.length() - 1);
    Parse p = new Parse(text, new Span(0, text.length()), AbstractBottomUpParser.INC_NODE, 0, 0);
    int start = 0;
    int i=0;
    for (Iterator<String> ti = tokens.iterator(); ti.hasNext();i++) {
      String tok = ti.next();
      p.insert(new Parse(text, new Span(start, start + tok.length()), AbstractBottomUpParser.TOK_NODE, 0,i));
      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) {
                //not sure how to get head index, but its not used at this point.
                Parse snp = new Parse(p.getText(),extents[ei].getSpan(),"NML",1.0,0);
                p.insert(snp);
                extents[ei].setParse(new DefaultParse(snp,sentenceNumber));
              }

            }
View Full Code Here

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

      }
    }

    public void show() {
      for (int pi=0,pn=parses.size();pi<pn;pi++) {
        Parse p = parses.get(pi);
        show(p);
        System.out.println();
      }
    }
View Full Code Here

        //System.out.print(p.hashCode()+"-"+parseMap.containsKey(p));
        System.out.print(" ");
      }
      Parse[] children = p.getChildren();
      for (int pi=0,pn=children.length;pi<pn;pi++) {
        Parse c = children[pi];
        Span s = c.getSpan();
        if (start < s.getStart()) {
          System.out.print(p.getText().substring(start, s.getStart()));
        }
        show(c);
        start = s.getEnd();
View Full Code Here

  public void testTokensAreCorrect() throws IOException {
   
    ObjectStream<Parse> samples =
        new ConstitParseSampleStream(ObjectStreamUtils.createObjectStream(getSample1()));
   
    Parse p = samples.read();
   
    Parse[] tagNodes = p.getTagNodes();
    String[] tokens = new String[tagNodes.length];
    for (int ti=0;ti<tagNodes.length;ti++){
      tokens[ti] = tagNodes[ti].getCoveredText();
    }
   
View Full Code Here

     
      List<String[]> sentences = sample.getTexts();
     
      for (String sentence[] : sentences) {
       
        Parse p = FullParseCorefEnhancerStream.createIncompleteParse(sentence);
        p.setType(AbstractBottomUpParser.TOP_NODE);
       
        Parse parseTokens[] = p.getChildren();
       
        // construct incomplete parse here ..
        String tags[] = posTagger.tag(sentence);
       
        for (int i = 0; i < parseTokens.length; i++) {
          p.insert(new Parse(p.getText(), parseTokens[i].getSpan(), tags[i], 1d, parseTokens[i].getHeadIndex()));
        }
       
        // insert tags into incomplete parse
        Span chunks[] = chunker.chunkAsSpans(sentence, tags);
       
        for (Span chunk : chunks) {
          if ("NP".equals(chunk.getType())) {
            p.insert(new Parse(p.getText(), new Span(0,0), chunk.getType(), 1d, p.getHeadIndex()));
          }
        }
       
        enhancedParses.add(p);
      }
View Full Code Here

  @Override
  protected void addParseEvents(List<Event> parseEvents, Parse[] chunks) {
    int ci = 0;
    while (ci < chunks.length) {
      //System.err.println("parserEventStream.addParseEvents: chunks="+Arrays.asList(chunks));
      Parse c = chunks[ci];
      Parse parent = c.getParent();
      if (parent != null) {
        String type = parent.getType();
        String outcome;
        if (firstChild(c, parent)) {
          outcome = AbstractBottomUpParser.START + type;
        }
        else {
View Full Code Here

  }

  private boolean containsPunct(Collection<Parse> puncts, String punct){
    if (puncts != null){
      for (Iterator<Parse> pi=puncts.iterator();pi.hasNext();) {
        Parse p = pi.next();
        if (p.getType().equals(punct)) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

   * @return A set of contextual features about this attachment.
   */
  public String[] getContext(Parse[] constituents, int index, List<Parse> rightFrontier, int rfi) {
    List<String> features = new ArrayList<String>(100);
    int nodeDistance = rfi;
    Parse fn = rightFrontier.get(rfi);
    Parse fp = null;
    if (rfi+1 < rightFrontier.size()) {
      fp = rightFrontier.get(rfi+1);
    }
    Parse p_1 = null;
    if (rightFrontier.size() > 0) {
      p_1 = rightFrontier.get(0);
    }
    Parse p0 = constituents[index];
    Parse p1 = null;
    if (index+1 < constituents.length) {
      p1 = constituents[index+1];
    }

    Collection<Parse> punct1s = null;
    Collection<Parse> punct_1s = null;
    Collection<Parse> punct_1fs = null;
    punct_1fs = fn.getPreviousPunctuationSet();
    punct_1s=p0.getPreviousPunctuationSet();
    punct1s=p0.getNextPunctuationSet();

    String consfp = cons(fp,-3);
    String consf = cons(fn,-2);
    String consp_1 = cons(p_1,-1);
    String consp0 = cons(p0,0);
    String consp1 = cons(p1,1);

    String consbofp = consbo(fp,-3);
    String consbof = consbo(fn,-2);
    String consbop_1 = consbo(p_1,-1);
    String consbop0 = consbo(p0,0);
    String consbop1 = consbo(p1,1);

    Cons cfp = new Cons(consfp,consbofp,-3,true);
    Cons cf = new Cons(consf,consbof,-2,true);
    Cons c_1 = new Cons(consp_1,consbop_1,-1,true);
    Cons c0 = new Cons(consp0,consbop0,0,true);
    Cons c1 = new Cons(consp1,consbop1,1,true);

    //default
    features.add("default");

    //unigrams
    features.add(consfp);
    features.add(consbofp);
    features.add(consf);
    features.add(consbof);
    features.add(consp_1);
    features.add(consbop_1);
    features.add(consp0);
    features.add(consbop0);
    features.add(consp1);
    features.add(consbop1);

    //productions
    String prod = production(fn,false);
    //String punctProd = production(fn,true,punctSet);
    features.add("pn="+prod);
    features.add("pd="+prod+","+p0.getType());
    features.add("ps="+fn.getType()+"->"+fn.getType()+","+p0.getType());
    if (punct_1s != null) {
      StringBuilder punctBuf = new StringBuilder(5);
      for (Iterator<Parse> pi=punct_1s.iterator();pi.hasNext();) {
        Parse punct = pi.next();
        punctBuf.append(punct.getType()).append(",");
      }
      //features.add("ppd="+punctProd+","+punctBuf.toString()+p0.getType());
      //features.add("pps="+fn.getType()+"->"+fn.getType()+","+punctBuf.toString()+p0.getType());
    }

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.