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


C++ Index::dumpAsciiLists方法代码示例

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


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

示例1: main

// Main function.
int main(int argc, char** argv) {
  cout.sync_with_stdio(false);
  std::cout << std::endl
            << EMPH_ON << "WriteIndexListsMain, version " << __DATE__ << " "
            << __TIME__ << EMPH_OFF << std::endl
            << std::endl;

  char* locale = setlocale(LC_CTYPE, "");
  cout << "Set locale LC_CTYPE to: " << locale << endl;

  std::locale loc;
  ad_utility::ReadableNumberFacet facet(1);
  std::locale locWithNumberGrouping(loc, &facet);
  ad_utility::Log::imbue(locWithNumberGrouping);

  string indexName = "";
  bool freebase = false;

  optind = 1;
  // Process command line arguments.
  while (true) {
    int c = getopt_long(argc, argv, "i:f", options, NULL);
    if (c == -1) break;
    switch (c) {
      case 'i':
        indexName = optarg;
        break;
      case 'f':
        freebase = true;
        break;
      default:
        cout << endl
             << "! ERROR in processing options (getopt returned '" << c
             << "' = 0x" << std::setbase(16) << c << ")" << endl
             << endl;
        exit(1);
    }
  }

  if (indexName.size() == 0) {
    cout << "Missing required argument --index (-i)..." << endl;
    exit(1);
  }

  try {
    Index index;
    index.createFromOnDiskIndex(indexName);
    index.addTextFromOnDiskIndex();

    vector<string> lists;
    lists.push_back("algo*");
    bool decodeGapsAndFrequency = true;
    index.dumpAsciiLists(lists, decodeGapsAndFrequency);

    Engine engine;
    QueryExecutionContext qec(index, engine);
    ParsedQuery q;
    if (!freebase) {
      q = SparqlParser::parse("SELECT ?x WHERE {?x <is-a> <Scientist>}");
    } else {
      q = SparqlParser::parse(
          "PREFIX fb: <http://rdf.freebase.com/ns/> SELECT ?p WHERE {?p "
          "fb:people.person.profession fb:m.06q2q}");
      q.expandPrefixes();
    }
    QueryPlanner queryPlanner(&qec);
    auto qet = queryPlanner.createExecutionTree(q);
    const auto res = qet.getResult();
    AD_CHECK(res->size() > 0);
    AD_CHECK(res->_data.cols() == 1);
    string personlistFile = indexName + ".list.scientists";
    std::ofstream f(personlistFile.c_str());
    const IdTable& ids = res->_data;
    for (size_t i = 0; i < ids.size(); ++i) {
      f << ids(i, 0) << ' ';
    }
    f.close();

  } catch (const std::exception& e) {
    cout << e.what() << std::endl;
  }

  return 0;
}
开发者ID:Buchhold,项目名称:SparqlEngineDraft,代码行数:85,代码来源:WriteIndexListsMain.cpp


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