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


C++ ParseTree::non_terminals方法代码示例

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


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

示例1: Initialize

void ParseTreeNumeric::Initialize(const ConstituencyDictionary &dictionary,
                                  const ParseTree &parse_tree) {
  terminals_.clear();
  non_terminals_.clear();

  // Build a map from parse tree nodes to their indices in
  // terminal/non-terminals.
  std::map<ParseTreeNode*, int> map_terminals;
  std::map<ParseTreeNode*, int> map_non_terminals;
  for (int i = 0; i < parse_tree.terminals().size(); ++i) {
    map_terminals[parse_tree.terminals()[i]] = i;
  }
  for (int i = 0; i < parse_tree.non_terminals().size(); ++i) {
    map_non_terminals[parse_tree.non_terminals()[i]] = i;
  }

  terminals_.resize(parse_tree.terminals().size());
  non_terminals_.resize(parse_tree.non_terminals().size());
  for (int i = 0; i < parse_tree.terminals().size(); ++i) {
    terminals_[i] = new ParseTreeNumericNode;
  }
  for (int i = 0; i < parse_tree.non_terminals().size(); ++i) {
    non_terminals_[i] = new ParseTreeNumericNode;
  }
  for (int i = 0; i < parse_tree.terminals().size(); ++i) {
    ParseTreeNode *original_node = parse_tree.terminals()[i];
    ParseTreeNumericNode *node = terminals_[i];
    node->set_label(-1); // Terminal nodes receive no label.
    node->set_span(original_node->span());
    if (!original_node->parent()) {
      node->set_parent(NULL);
      root_ = node;
    } else {
      int parent_index = map_non_terminals[original_node->parent()];
      node->set_parent(non_terminals_[parent_index]);
    }
    CHECK_EQ(original_node->GetNumChildren(), 0);
  }

  for (int i = 0; i < parse_tree.non_terminals().size(); ++i) {
    ParseTreeNode *original_node = parse_tree.non_terminals()[i];
    ParseTreeNumericNode *node = non_terminals_[i];
    int id = dictionary.GetConstituentId(original_node->label());
    CHECK_LT(id, 0xffff);
    if (id < 0) id = TOKEN_UNKNOWN;
    node->set_label(id);
    node->set_span(original_node->span());
    if (!original_node->parent()) {
      node->set_parent(NULL);
      root_ = node;
    } else {
      int parent_index = map_non_terminals[original_node->parent()];
      node->set_parent(non_terminals_[parent_index]);
    }
    for (int j = 0; j < original_node->GetNumChildren(); ++j) {
      ParseTreeNode *child = original_node->GetChild(j);
      if (child->IsLeaf()) {
        int child_index = map_terminals[child];
        node->AddChild(terminals_[child_index]);
      } else {
        int child_index = map_non_terminals[child];
        node->AddChild(non_terminals_[child_index]);
      }
    }
  }
}
开发者ID:davidlegit,项目名称:TurboParser,代码行数:66,代码来源:ConstituencyInstanceNumeric.cpp


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