本文整理汇总了C++中ParseTree::terminals方法的典型用法代码示例。如果您正苦于以下问题:C++ ParseTree::terminals方法的具体用法?C++ ParseTree::terminals怎么用?C++ ParseTree::terminals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseTree
的用法示例。
在下文中一共展示了ParseTree::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]);
}
}
}
}