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


C++ Grammar::find方法代码示例

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


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

示例1: gen_aux

void gen_aux(const Grammar& g, const string& word, vector<string>& ret, const int depth) {
  if (depth > 3) {
    return;
  }
  if (!bracketed(word)) {
    ret.push_back(word);
  } else {
    // locate rule that corresponds to word
    Grammar::const_iterator it = g.find(word);
    if (it == g.end()) {
      throw logic_error("empty rule");
    }

    // fetch the set of possible rules
    const Rule_collection& c = it->second;

    int index = nrand(c.size());
    const Rule& r = c[index];

    // recursively expand the selected rule
    for (Rule::const_iterator i = r.begin();
      i != r.end();
      ++i) {
      gen_aux(g, *i, ret, depth + 1);
    }
  }
}
开发者ID:lichunming,项目名称:learn-cpp,代码行数:27,代码来源:generate_sentence.cpp

示例2: logic_error

void
gen_aux(const Grammar& g, const string& word, vector<string>& ret)
{
    if (!bracketed(word))
    {
        ret.push_back(word);
    }
    else
    {
        // locate the rule that corresponds to word
        Grammar::const_iterator it = g.find(word);
        if (it == g.end())
            throw logic_error("empty rule");

        // fetch the set of possible rules
        const Rule_collection& c = it->second;

        // from which we select one at random
        const Rule& r = c[nrand(c.size())];

        // recursively expand the selected rule
        for (Rule::const_iterator i = r.begin(); i != r.end(); ++i)
            gen_aux(g, *i, ret);
    }
}
开发者ID:esengie,项目名称:SideProjects,代码行数:25,代码来源:generator.cpp

示例3:

void
expand_aux (const Grammar &g, const std::string &word, TokenStack &result)
{
  Grammar::const_iterator it = g.find (word);
  if (g.end() != it)
    {
      const RuleCollection &rc = it->second;
      const Rule &r = rc[nrand(rc.size())];
      for (int i = r.size() - 1; i > -1; --i)
      {
        result.push(r[i]);
      }
    }
}
开发者ID:juanjosealegre,项目名称:cpp-tutorial,代码行数:14,代码来源:grammar_stack.cpp

示例4: gen_aux

void gen_aux(const Grammar& g, const std::string& word, std::list<std::string>& ret)
{
    if(!bracketed(word)) {
	ret.push_back(word);
    }
    else {
	Grammar::const_iterator it = g.find(word);
	if(it == g.end())
	    throw std::logic_error("empty rule");
	const Rule_collection& c = it->second;
	const Rule& r = c[nrand(c.size())];
	for(Rule::const_iterator i = r.begin(); i != r.end(); ++i)
	    gen_aux(g, *i, ret);
    }
}
开发者ID:joharrow,项目名称:acpp,代码行数:15,代码来源:grammar_list.cpp

示例5: logic_error

void
gen_aux (const Grammar &g, const std::string &word, std::vector<std::string> &result)
{
  if (!bracketed (word))
    {
      result.push_back (word);
    }
  else
    {
      Grammar::const_iterator it = g.find (word);

      if (g.end() == it)
        throw std::logic_error ("empty grammar rule");

      const RuleCollection &rc = it->second;
      const Rule &r = rc[nrand(rc.size())];

      for (Rule::const_iterator r_it = r.begin(); r_it != r.end(); ++r_it)
        gen_aux (g, *r_it, result);
    }
}
开发者ID:juanjosealegre,项目名称:cpp-tutorial,代码行数:21,代码来源:grammar.cpp

示例6: gen_aux

void gen_aux(const Grammar& g, const std::string& word, std::vector<std::string>& ret)
{
	if (!bracketed(word)) {
		ret.push_back(word);
	}
	else {
		Grammar::const_iterator it = g.find(word);
		if (it == g.end()) {
			std::logic_error("Rule is empty");
		}

		// get rule collection from grammar
		const Rule_collection& c = it->second;

		// select a new rule from collection at random
		const Rule& r = c[nrand(c.size())];

		// expand rule
		for (Rule::const_iterator i = r.begin(); i != r.end(); ++i) {
			gen_aux(g, *i, ret);
		}
	}
}
开发者ID:MatthewGrim,项目名称:acceleratedC-,代码行数:23,代码来源:GenerateSentence.cpp


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