当前位置: 首页>>代码示例>>C++>>正文


C++ Parse::getPreviousPunctuationSet方法代码示例

本文整理汇总了C++中Parse::getPreviousPunctuationSet方法的典型用法代码示例。如果您正苦于以下问题:C++ Parse::getPreviousPunctuationSet方法的具体用法?C++ Parse::getPreviousPunctuationSet怎么用?C++ Parse::getPreviousPunctuationSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parse的用法示例。


在下文中一共展示了Parse::getPreviousPunctuationSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cons

                std::string *AttachContextGenerator::getContext(Parse constituents[], int index, std::vector<Parse*> &rightFrontier, int rfi)
                {
                  std::vector<std::string> features = std::vector<std::string>(100);
                  int nodeDistance = rfi;
                  Parse *fn = rightFrontier[rfi];
                  Parse *fp = 0;
                  if (rfi + 1 < rightFrontier.size())
                  {
                    fp = rightFrontier[rfi + 1];
                  }
                  Parse *p_1 = 0;
                  if (rightFrontier.size() > 0)
                  {
                    p_1 = rightFrontier[0];
                  }
                  Parse *p0 = constituents[index];
                  Parse *p1 = 0;
                  if (index + 1 < sizeof(constituents) / sizeof(constituents[0]))
                  {
                    p1 = constituents[index + 1];
                  }

                  Collection<Parse*> *punct1s = 0;
                  Collection<Parse*> *punct_1s = 0;
                  Collection<Parse*> *punct_1fs = 0;
                  punct_1fs = fn->getPreviousPunctuationSet();
                  punct_1s = p0->getPreviousPunctuationSet();
                  punct1s = p0->getNextPunctuationSet();

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

                  std::string consbofp = consbo(fp,-3);
                  std::string consbof = consbo(fn,-2);
                  std::string consbop_1 = consbo(p_1,-1);
                  std::string consbop0 = consbo(p0,0);
                  std::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.push_back("default");

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

                  //productions
                  std::string prod = production(fn,false);
                  //String punctProd = production(fn,true,punctSet);
                  features.push_back("pn=" + prod);
                  features.push_back("pd=" + prod + "," + p0->getType());
                  features.push_back("ps=" + fn->getType() + "->" + fn->getType() + "," + p0->getType());
                  if (punct_1s != 0)
                  {
                    StringBuffer *punctBuf = new StringBuffer(5);
                    for (Collection<Parse*>::const_iterator pi = punct_1s->begin(); pi != punct_1s->end(); ++pi)
                    {
                      Parse *punct = *pi;
                      punctBuf->append(punct->getType())->append(",");
                    }
                    //features.add("ppd="+punctProd+","+punctBuf.toString()+p0.getType());
                    //features.add("pps="+fn.getType()+"->"+fn.getType()+","+punctBuf.toString()+p0.getType());
                  }

                  //bi-grams
                  //cons(fn),cons(0)
                  cons2(features,cfp,c0,punct_1s,true);
                  cons2(features,cf,c0,punct_1s,true);
                  cons2(features,c_1,c0,punct_1s,true);
                  cons2(features,c0,c1,punct1s,true);
                  cons3(features,cf,c_1,c0,0,punct_1s,true,true,true);
                  cons3(features,cf,c0,c1,punct_1s,punct1s,true,true,true);
                  cons3(features,cfp,cf,c0,0,punct_1s,true,true,true);
                  /*
                  for (int ri=0;ri<rfi;ri++) {
                    Parse jn = (Parse) rightFrontier.get(ri);
                    features.add("jn="+jn.getType());
                  }
                  */
                  int headDistance = (p0->getHeadIndex() - fn->getHeadIndex());
                  features.push_back("hd=" + headDistance);
                  features.push_back("nd=" + nodeDistance);

                  features.push_back("nd=" + p0->getType() + "." + nodeDistance);
//.........这里部分代码省略.........
开发者ID:benlm54,项目名称:myassist-repo,代码行数:101,代码来源:AttachContextGenerator.cpp

示例2: addParseEvents

                void ParserEventStream::addParseEvents(std::vector<Event*> &parseEvents, Parse chunks[])
                {
                  /// <summary>
                  /// Frontier nodes built from node in a completed parse.  Specifically,
                  /// they have all their children regardless of the stage of parsing.
                  /// </summary>
                  std::vector<Parse*> rightFrontier = std::vector<Parse*>();
                  std::vector<Parse*> builtNodes = std::vector<Parse*>();
                  /// <summary>
                  /// Nodes which characterize what the parse looks like to the parser as its being built.
                  /// Specifically, these nodes don't have all their children attached like the parents of
                  /// the chunk nodes do.
                  /// </summary>
                  Parse currentChunks[sizeof(chunks) / sizeof(chunks[0])];
                  for (int ci = 0;ci < sizeof(chunks) / sizeof(chunks[0]);ci++)
                  {
                    currentChunks[ci] = static_cast<Parse*>(chunks[ci]->clone());
                    currentChunks[ci]->setPrevPunctuation(chunks[ci]->getPreviousPunctuationSet());
                    currentChunks[ci]->setNextPunctuation(chunks[ci]->getNextPunctuationSet());
                    currentChunks[ci]->setLabel(Parser::COMPLETE);
                    chunks[ci]->setLabel(Parser::COMPLETE);
                  }
                  for (int ci = 0;ci < sizeof(chunks) / sizeof(chunks[0]);ci++)
                  {
                    //System.err.println("parserEventStream.addParseEvents: chunks="+Arrays.asList(chunks));
                    Parse *parent = chunks[ci]->getParent();
                    Parse *prevParent = chunks[ci];
                    int off = 0;
                    //build un-built parents
                    if (!chunks[ci]->isPosTag())
                    {
                      builtNodes.push_back(off++,chunks[ci]);
                    }
                    //perform build stages
                    while (parent->getType() != AbstractBottomUpParser::TOP_NODE && parent->getLabel() == "")
                    {
                      if (parent->getLabel() == "" && prevParent->getType() != parent->getType())
                      {
                        //build level
                        if (debug)
                            System::err::println("Build: " + parent->getType() + " for: " + currentChunks[ci]);
                        if (etype == opennlp::tools::parser::BUILD)
                        {
                          parseEvents.push_back(new Event(parent->getType(), buildContextGenerator->getContext(currentChunks, ci)));
                        }
                        builtNodes.push_back(off++,parent);
                        Parse *newParent = new Parse(currentChunks[ci]->getText(),currentChunks[ci]->getSpan(),parent->getType(),1,0);
                        newParent->add(currentChunks[ci],rules);
                        newParent->setPrevPunctuation(currentChunks[ci]->getPreviousPunctuationSet());
                        newParent->setNextPunctuation(currentChunks[ci]->getNextPunctuationSet());
                        currentChunks[ci]->setParent(newParent);
                        currentChunks[ci] = newParent;
                        newParent->setLabel(Parser::BUILT);
                        //see if chunk is complete
                        if (lastChild(chunks[ci], parent))
                        {
                          if (etype == opennlp::tools::parser::CHECK)
                          {
                            parseEvents.push_back(new Event(Parser::COMPLETE, checkContextGenerator->getContext(currentChunks[ci],currentChunks, ci,false)));
                          }
                          currentChunks[ci]->setLabel(Parser::COMPLETE);
                          parent->setLabel(Parser::COMPLETE);
                        }
                        else
                        {
                          if (etype == opennlp::tools::parser::CHECK)
                          {
                            parseEvents.push_back(new Event(Parser::INCOMPLETE, checkContextGenerator->getContext(currentChunks[ci],currentChunks,ci,false)));
                          }
                          currentChunks[ci]->setLabel(Parser::INCOMPLETE);
                          parent->setLabel(Parser::COMPLETE);
                        }

                        chunks[ci] = parent;
                        //System.err.println("build: "+newParent+" for "+parent);
                      }
                      //TODO: Consider whether we need to set this label or train parses at all.
                      parent->setLabel(Parser::BUILT);
                      prevParent = parent;
                      parent = parent->getParent();
                    }
                    //decide to attach
                    if (etype == opennlp::tools::parser::BUILD)
                    {
                      parseEvents.push_back(new Event(Parser::DONE, buildContextGenerator->getContext(currentChunks, ci)));
                    }
                    //attach node
                    std::string attachType = "";
                    /// <summary>
                    /// Node selected for attachment. </summary>
                    Parse *attachNode = 0;
                    int attachNodeIndex = -1;
                    if (ci == 0)
                    {
                      Parse *top = new Parse(currentChunks[ci]->getText(),new Span(0,currentChunks[ci]->getText()->length()),AbstractBottomUpParser::TOP_NODE,1,0);
                      top->insert(currentChunks[ci]);
                    }
                    else
                    {
                      /// <summary>
//.........这里部分代码省略.........
开发者ID:benlm54,项目名称:myassist-repo,代码行数:101,代码来源:ParserEventStream.cpp


注:本文中的Parse::getPreviousPunctuationSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。