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


C++ ParsedQuery::expandPrefixes方法代码示例

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


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

示例1: qp

TEST(QueryPlannerTest, createTripleGraph) {
  try {
    {
      ParsedQuery pq = SparqlParser::parse(
          "PREFIX : <http://rdf.myprefix.com/>\n"
          "PREFIX ns: <http://rdf.myprefix.com/ns/>\n"
          "PREFIX xxx: <http://rdf.myprefix.com/xxx/>\n"
          "SELECT ?x ?z \n "
          "WHERE \t {?x :myrel ?y. ?y ns:myrel ?z.?y xxx:rel2 "
          "<http://abc.de>}");
      pq.expandPrefixes();
      QueryPlanner qp(nullptr);
      auto tg = qp.createTripleGraph(&pq._rootGraphPattern);
      ASSERT_EQ(
          "0 {s: ?x, p: <http://rdf.myprefix.com/myrel>, o: ?y} : (1, 2)\n"
          "1 {s: ?y, p: <http://rdf.myprefix.com/ns/myrel>, o: ?z} : (0, 2)\n"
          "2 {s: ?y, p: <http://rdf.myprefix.com/xxx/rel2>, o: "
          "<http://abc.de>} : (0, 1)",
          tg.asString());
    }

    {
      ParsedQuery pq = SparqlParser::parse(
          "SELECT ?x WHERE {?x ?p <X>. ?x ?p2 <Y>. <X> ?p <Y>}");
      pq.expandPrefixes();
      QueryPlanner qp(nullptr);
      auto tg = qp.createTripleGraph(&pq._rootGraphPattern);
      ASSERT_EQ(
          "0 {s: ?x, p: ?p, o: <X>} : (1, 2)\n"
          "1 {s: ?x, p: ?p2, o: <Y>} : (0)\n"
          "2 {s: <X>, p: ?p, o: <Y>} : (0)",
          tg.asString());
    }

    {
      ParsedQuery pq = SparqlParser::parse(
          "SELECT ?x WHERE { ?x <is-a> <Book> . \n"
          "?x <Author> <Anthony_Newman_(Author)> }");
      pq.expandPrefixes();
      QueryPlanner qp(nullptr);
      auto tg = qp.createTripleGraph(&pq._rootGraphPattern);
      ASSERT_EQ(
          "0 {s: ?x, p: <is-a>, o: <Book>} : (1)\n"
          "1 {s: ?x, p: <Author>, o: <Anthony_Newman_(Author)>} : (0)",
          tg.asString());
    }
  } catch (const ad_semsearch::Exception& e) {
    std::cout << "Caught: " << e.getFullErrorMessage() << std::endl;
    FAIL() << e.getFullErrorMessage();
  } catch (const std::exception& e) {
    std::cout << "Caught: " << e.what() << std::endl;
    FAIL() << e.what();
  }
}
开发者ID:Buchhold,项目名称:SparqlEngineDraft,代码行数:54,代码来源:QueryPlannerTest.cpp

示例2:

TEST(ParserTest, testExpandPrefixes) {
  ParsedQuery pq = SparqlParser::parse(
      "PREFIX : <http://rdf.myprefix.com/>\n"
          "PREFIX ns: <http://rdf.myprefix.com/ns/>\n"
          "PREFIX xxx: <http://rdf.myprefix.com/xxx/>\n"
          "SELECT ?x ?z \n "
          "WHERE \t {?x :myrel ?y. ?y ns:myrel ?z.?y nsx:rel2 <http://abc.de>}");
  pq.expandPrefixes();
  ASSERT_EQ(3, pq._prefixes.size());
  ASSERT_EQ(2, pq._selectedVariables.size());
  ASSERT_EQ(3, pq._whereClauseTriples.size());
  ASSERT_EQ("", pq._prefixes[0]._prefix);
  ASSERT_EQ("<http://rdf.myprefix.com/>", pq._prefixes[0]._uri);
  ASSERT_EQ("ns", pq._prefixes[1]._prefix);
  ASSERT_EQ("<http://rdf.myprefix.com/ns/>", pq._prefixes[1]._uri);
  ASSERT_EQ("?x", pq._selectedVariables[0]);
  ASSERT_EQ("?z", pq._selectedVariables[1]);
  ASSERT_EQ("?x", pq._whereClauseTriples[0]._s);
  ASSERT_EQ("<http://rdf.myprefix.com/myrel>", pq._whereClauseTriples[0]._p);
  ASSERT_EQ("?y", pq._whereClauseTriples[0]._o);
  ASSERT_EQ("?y", pq._whereClauseTriples[1]._s);
  ASSERT_EQ("<http://rdf.myprefix.com/ns/myrel>", pq._whereClauseTriples[1]
      ._p);
  ASSERT_EQ("?z", pq._whereClauseTriples[1]._o);
  ASSERT_EQ("?y", pq._whereClauseTriples[2]._s);
  ASSERT_EQ("nsx:rel2", pq._whereClauseTriples[2]._p);
  ASSERT_EQ("<http://abc.de>", pq._whereClauseTriples[2]._o);
  ASSERT_EQ("", pq._limit);
  ASSERT_EQ("", pq._offset);
}
开发者ID:anukat2015,项目名称:SparqlEngineDraft,代码行数:30,代码来源:SparqlParserTest.cpp

示例3: process

// _____________________________________________________________________________
void Server::process(Socket *client, QueryExecutionContext *qec) const {
  string request;
  string response;
  string query;
  string contentType;
  client->recieve(&request);

  size_t indexOfGET = request.find("GET");
  size_t indexOfHTTP = request.find("HTTP");
  size_t upper = indexOfHTTP;

  if (indexOfGET != request.npos && indexOfHTTP != request.npos) {
    size_t indexOfQuest = request.find("?", indexOfGET);
    if (indexOfQuest != string::npos && indexOfQuest < indexOfHTTP) {
      upper = indexOfQuest + 1;
    }
    string file = request.substr(indexOfGET + 5, upper - (indexOfGET + 5) - 1);
    // Use hardcoded white-listing for index.html and style.css
    // can be changed if more should ever be needed, for now keep it simple.
    LOG(DEBUG) << "file: " << file << '\n';
    if (file == "index.html" || file == "style.css" || file == "script.js") {
      serveFile(client, file);
      return;
    }
    if (indexOfQuest == string::npos) {
      LOG(INFO) << "Ignoring request for file " << file << '\n';
      return;
    }

    try {
      ParamValueMap params = parseHttpRequest(request);
      if (ad_utility::getLowercase(params["cmd"]) == "clearcache") {
        qec->clearCache();
      }
      query = createQueryFromHttpParams(params);
      LOG(INFO) << "Query: " << query << '\n';
      ParsedQuery pq = SparqlParser::parse(query);
      pq.expandPrefixes();

      QueryGraph qg(qec);
      qg.createFromParsedQuery(pq);
      const QueryExecutionTree& qet = qg.getExecutionTree();
      response = composeResponseJson(pq, qet);
      contentType = "application/json";
    } catch (const ad_semsearch::Exception& e) {
      response = composeResponseJson(query, e);
    } catch (const ParseException& e) {
      response = composeResponseJson(query, e);
    }
    string httpResponse = createHttpResponse(response, contentType);
    client->send(httpResponse);
  } else {
    LOG(INFO) << "Ignoring invalid request " << request << '\n';
  }
}
开发者ID:zhiwei2017,项目名称:SparqlEngineDraft,代码行数:56,代码来源:Server.cpp

示例4: 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

示例5: FILTER

TEST(ParserTest, testParse) {
  try {
    ParsedQuery pq = SparqlParser::parse("SELECT ?x WHERE {?x ?y ?z}");
    ASSERT_GT(pq.asString().size(), 0);
    ASSERT_EQ(0, pq._prefixes.size());
    ASSERT_EQ(1, pq._selectedVariables.size());
    ASSERT_EQ(1, pq._whereClauseTriples.size());

    pq = SparqlParser::parse(
        "PREFIX : <http://rdf.myprefix.com/>\n"
            "PREFIX ns: <http://rdf.myprefix.com/ns/>\n"
            "PREFIX xxx: <http://rdf.myprefix.com/xxx/>\n"
            "SELECT ?x ?z \n "
            "WHERE \t {?x :myrel ?y. ?y ns:myrel ?z.?y nsx:rel2 <http://abc.de>}");
    ASSERT_EQ(3, pq._prefixes.size());
    ASSERT_EQ(2, pq._selectedVariables.size());
    ASSERT_EQ(3, pq._whereClauseTriples.size());

    ASSERT_EQ("", pq._prefixes[0]._prefix);
    ASSERT_EQ("<http://rdf.myprefix.com/>", pq._prefixes[0]._uri);
    ASSERT_EQ("ns", pq._prefixes[1]._prefix);
    ASSERT_EQ("<http://rdf.myprefix.com/ns/>", pq._prefixes[1]._uri);
    ASSERT_EQ("?x", pq._selectedVariables[0]);
    ASSERT_EQ("?z", pq._selectedVariables[1]);
    ASSERT_EQ("?x", pq._whereClauseTriples[0]._s);
    ASSERT_EQ(":myrel", pq._whereClauseTriples[0]._p);
    ASSERT_EQ("?y", pq._whereClauseTriples[0]._o);
    ASSERT_EQ("?y", pq._whereClauseTriples[1]._s);
    ASSERT_EQ("ns:myrel", pq._whereClauseTriples[1]._p);
    ASSERT_EQ("?z", pq._whereClauseTriples[1]._o);
    ASSERT_EQ("?y", pq._whereClauseTriples[2]._s);
    ASSERT_EQ("nsx:rel2", pq._whereClauseTriples[2]._p);
    ASSERT_EQ("<http://abc.de>", pq._whereClauseTriples[2]._o);
    ASSERT_EQ("", pq._limit);
    ASSERT_EQ("", pq._offset);

    pq = SparqlParser::parse(
        "PREFIX : <http://rdf.myprefix.com/>\n"
            "PREFIX ns: <http://rdf.myprefix.com/ns/>\n"
            "PREFIX xxx: <http://rdf.myprefix.com/xxx/>\n"
            "SELECT ?x ?z \n "
            "WHERE \t {\n?x :myrel ?y. ?y ns:myrel ?z.\n?y nsx:rel2 <http://abc.de>\n}");
    ASSERT_EQ(3, pq._prefixes.size());
    ASSERT_EQ(2, pq._selectedVariables.size());
    ASSERT_EQ(3, pq._whereClauseTriples.size());

    ASSERT_EQ("", pq._prefixes[0]._prefix);
    ASSERT_EQ("<http://rdf.myprefix.com/>", pq._prefixes[0]._uri);
    ASSERT_EQ("ns", pq._prefixes[1]._prefix);
    ASSERT_EQ("<http://rdf.myprefix.com/ns/>", pq._prefixes[1]._uri);
    ASSERT_EQ("?x", pq._selectedVariables[0]);
    ASSERT_EQ("?z", pq._selectedVariables[1]);
    ASSERT_EQ("?x", pq._whereClauseTriples[0]._s);
    ASSERT_EQ(":myrel", pq._whereClauseTriples[0]._p);
    ASSERT_EQ("?y", pq._whereClauseTriples[0]._o);
    ASSERT_EQ("?y", pq._whereClauseTriples[1]._s);
    ASSERT_EQ("ns:myrel", pq._whereClauseTriples[1]._p);
    ASSERT_EQ("?z", pq._whereClauseTriples[1]._o);
    ASSERT_EQ("?y", pq._whereClauseTriples[2]._s);
    ASSERT_EQ("nsx:rel2", pq._whereClauseTriples[2]._p);
    ASSERT_EQ("<http://abc.de>", pq._whereClauseTriples[2]._o);
    ASSERT_EQ("", pq._limit);
    ASSERT_EQ("", pq._offset);

    pq = SparqlParser::parse(
        "PREFIX ns: <http://ns/>"
            "SELECT ?x ?z \n "
            "WHERE \t {\n?x <Directed_by> ?y. ?y ns:myrel.extend ?z.\n"
            "?y nsx:rel2 \"Hello... World\"}");
    ASSERT_EQ(1, pq._prefixes.size());
    ASSERT_EQ(2, pq._selectedVariables.size());
    ASSERT_EQ(3, pq._whereClauseTriples.size());

    pq.expandPrefixes();

    ASSERT_EQ("?x", pq._selectedVariables[0]);
    ASSERT_EQ("?z", pq._selectedVariables[1]);
    ASSERT_EQ("?x", pq._whereClauseTriples[0]._s);
    ASSERT_EQ("<Directed_by>", pq._whereClauseTriples[0]._p);
    ASSERT_EQ("?y", pq._whereClauseTriples[0]._o);
    ASSERT_EQ("?y", pq._whereClauseTriples[1]._s);
    ASSERT_EQ("<http://ns/myrel.extend>", pq._whereClauseTriples[1]._p);
    ASSERT_EQ("?z", pq._whereClauseTriples[1]._o);
    ASSERT_EQ("?y", pq._whereClauseTriples[2]._s);
    ASSERT_EQ("nsx:rel2", pq._whereClauseTriples[2]._p);
    ASSERT_EQ("\"Hello... World\"", pq._whereClauseTriples[2]._o);
    ASSERT_EQ("", pq._limit);
    ASSERT_EQ("", pq._offset);


    pq = SparqlParser::parse(
        "SELECT ?x ?y WHERE {?x is-a Actor .  FILTER(?x != ?y)."
            "?y is-a Actor . FILTER(?y < ?x)} LIMIT 10");
    pq.expandPrefixes();
    ASSERT_EQ(2, pq._filters.size());
    ASSERT_EQ("?x", pq._filters[0]._lhs);
    ASSERT_EQ("?y", pq._filters[0]._rhs);
    ASSERT_EQ(SparqlFilter::FilterType::NE, pq._filters[0]._type);
    ASSERT_EQ("?y", pq._filters[1]._lhs);
    ASSERT_EQ("?x", pq._filters[1]._rhs);
//.........这里部分代码省略.........
开发者ID:anukat2015,项目名称:SparqlEngineDraft,代码行数:101,代码来源:SparqlParserTest.cpp

示例6: SCORE

TEST(ParserTest, testSolutionModifiers) {
  ParsedQuery pq = SparqlParser::parse(
      "SELECT ?x WHERE \t {?x :myrel ?y}");
  pq.expandPrefixes();
  ASSERT_EQ(0, pq._prefixes.size());
  ASSERT_EQ(1, pq._selectedVariables.size());
  ASSERT_EQ(1, pq._whereClauseTriples.size());
  ASSERT_EQ("", pq._limit);
  ASSERT_EQ("", pq._offset);
  ASSERT_EQ(size_t(0), pq._orderBy.size());
  ASSERT_FALSE(pq._distinct);
  ASSERT_FALSE(pq._reduced);


  pq = SparqlParser::parse(
      "SELECT ?x WHERE \t {?x :myrel ?y} LIMIT 10");
  pq.expandPrefixes();
  ASSERT_EQ(0, pq._prefixes.size());
  ASSERT_EQ(1, pq._selectedVariables.size());
  ASSERT_EQ(1, pq._whereClauseTriples.size());
  ASSERT_EQ("10", pq._limit);
  ASSERT_EQ("", pq._offset);
  ASSERT_EQ(size_t(0), pq._orderBy.size());
  ASSERT_FALSE(pq._distinct);
  ASSERT_FALSE(pq._reduced);

  pq = SparqlParser::parse(
      "SELECT ?x WHERE \t {?x :myrel ?y}\n"
          "LIMIT 10 OFFSET 15");
  pq.expandPrefixes();
  ASSERT_EQ(0, pq._prefixes.size());
  ASSERT_EQ(1, pq._selectedVariables.size());
  ASSERT_EQ(1, pq._whereClauseTriples.size());
  ASSERT_EQ("10", pq._limit);
  ASSERT_EQ("15", pq._offset);
  ASSERT_EQ(size_t(0), pq._orderBy.size());
  ASSERT_FALSE(pq._distinct);
  ASSERT_FALSE(pq._reduced);

  pq = SparqlParser::parse(
      "SELECT DISTINCT ?x ?y WHERE \t {?x :myrel ?y}\n"
          "ORDER BY ?y LIMIT 10 OFFSET 15");
  pq.expandPrefixes();
  ASSERT_EQ(0, pq._prefixes.size());
  ASSERT_EQ(2, pq._selectedVariables.size());
  ASSERT_EQ(1, pq._whereClauseTriples.size());
  ASSERT_EQ("10", pq._limit);
  ASSERT_EQ("15", pq._offset);
  ASSERT_EQ(size_t(1), pq._orderBy.size());
  ASSERT_EQ("?y", pq._orderBy[0]._key);
  ASSERT_FALSE(pq._orderBy[0]._desc);
  ASSERT_TRUE(pq._distinct);
  ASSERT_FALSE(pq._reduced);

  pq = SparqlParser::parse(
      "SELECT DISTINCT ?x SCORE(?x|?c) ?y WHERE \t {?x :myrel ?y}\n"
          "ORDER BY ASC(?y) DESC(SCORE(?x|?c)) LIMIT 10 OFFSET 15");
  pq.expandPrefixes();
  ASSERT_EQ(0, pq._prefixes.size());
  ASSERT_EQ(3, pq._selectedVariables.size());
  ASSERT_EQ("SCORE(?x|?c)", pq._selectedVariables[1]);
  ASSERT_EQ(1, pq._whereClauseTriples.size());
  ASSERT_EQ("10", pq._limit);
  ASSERT_EQ("15", pq._offset);
  ASSERT_EQ(size_t(2), pq._orderBy.size());
  ASSERT_EQ("?y", pq._orderBy[0]._key);
  ASSERT_FALSE(pq._orderBy[0]._desc);
  ASSERT_EQ("SCORE(?x|?c)", pq._orderBy[1]._key);
  ASSERT_TRUE(pq._orderBy[1]._desc);
  ASSERT_TRUE(pq._distinct);
  ASSERT_FALSE(pq._reduced);

  pq = SparqlParser::parse(
      "SELECT REDUCED ?x ?y WHERE \t {?x :myrel ?y}\n"
          "ORDER BY DESC(?x) ASC(?y) LIMIT 10 OFFSET 15");
  pq.expandPrefixes();
  ASSERT_EQ(0, pq._prefixes.size());
  ASSERT_EQ(2, pq._selectedVariables.size());
  ASSERT_EQ(1, pq._whereClauseTriples.size());
  ASSERT_EQ("10", pq._limit);
  ASSERT_EQ("15", pq._offset);
  ASSERT_EQ(size_t(2), pq._orderBy.size());
  ASSERT_EQ("?x", pq._orderBy[0]._key);
  ASSERT_TRUE(pq._orderBy[0]._desc);
  ASSERT_EQ("?y", pq._orderBy[1]._key);
  ASSERT_FALSE(pq._orderBy[1]._desc);
  ASSERT_FALSE(pq._distinct);
  ASSERT_TRUE(pq._reduced);

  pq = SparqlParser::parse(
      "SELECT ?x ?y WHERE {?x is-a Actor} LIMIT 10");
  pq.expandPrefixes();
  ASSERT_EQ("10", pq._limit);
}
开发者ID:anukat2015,项目名称:SparqlEngineDraft,代码行数:94,代码来源:SparqlParserTest.cpp


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