本文整理汇总了C++中ParsedQuery类的典型用法代码示例。如果您正苦于以下问题:C++ ParsedQuery类的具体用法?C++ ParsedQuery怎么用?C++ ParsedQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParsedQuery类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(QueryExecutionTreeTest, testPlantsEdibleLeaves) {
try {
ParsedQuery pq = SparqlParser::parse(
"SELECT ?a \n "
"WHERE {?a <is-a> <Plant> . ?c ql:contains-entity ?a. "
"?c ql:contains-word \"edible leaves\"} TEXTLIMIT 5");
pq.expandPrefixes();
QueryPlanner qp(nullptr);
QueryPlanner::TripleGraph tg = qp.createTripleGraph(&pq._rootGraphPattern);
ASSERT_EQ(1u, tg._nodeMap.find(0)->second->_variables.size());
QueryExecutionTree qet = qp.createExecutionTree(pq);
ASSERT_EQ(
"{\n TEXT OPERATION WITH FILTER: co-occurrence with words: "
"\"edible leaves\" and 1 variables with textLimit = 5 "
"filtered by\n {\n SCAN POS with P = \"<is-a>\", "
"O = \"<Plant>\"\n qet-width: 1 \n }\n filtered on "
"column 0\n qet-width: 3 \n}",
qet.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();
}
}
示例2: TEST
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);
}
示例3: LOG
// _____________________________________________________________________________
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';
}
}
示例4: _tryQueryByPKHack
bool _tryQueryByPKHack(const char *ns, const BSONObj &query,
const ParsedQuery &pq, CurOp &curop, Message &result) {
BSONObj resObject;
bool found = false;
Collection *cl = getCollection(ns);
if (cl == NULL) {
return false; // ns doesn't exist, fall through to optimizer for legacy reasons
}
const BSONObj &pk = cl->getSimplePKFromQuery(query);
if (pk.isEmpty()) {
return false; // unable to query by PK - resort to using the optimizer
}
found = queryByPKHack(cl, pk, query, resObject);
if ( shardingState.needShardChunkManager( ns ) ) {
ShardChunkManagerPtr m = shardingState.getShardChunkManager( ns );
if ( m && ! m->belongsToMe( resObject ) ) {
// I have something for this _id
// but it doesn't belong to me
// so return nothing
resObject = BSONObj();
found = false;
}
}
BufBuilder bb(sizeof(QueryResult)+resObject.objsize()+32);
bb.skip(sizeof(QueryResult));
if ( found ) {
fillQueryResultFromObj( bb , pq.getFields() , resObject );
}
auto_ptr< QueryResult > qr( (QueryResult *) bb.buf() );
bb.decouple();
qr->setResultFlagsToOk();
qr->len = bb.len();
curop.debug().responseLength = bb.len();
qr->setOperation(opReply);
qr->cursorId = 0;
qr->startingFrom = 0;
qr->nReturned = found ? 1 : 0;
result.setData( qr.release(), true );
return true;
}
示例5: 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;
}