Go to the documentation of this file.00001 #include "StaticFacts.h"
00002
00003 #include <boost/algorithm/string.hpp>
00004 #include <boost/filesystem.hpp>
00005 #include <boost/foreach.hpp>
00006 #include <fstream>
00007
00008 using namespace std;
00009 using namespace actasp;
00010
00011 namespace bwi_krexec {
00012
00013 std::list<actasp::AspAtom> StaticFacts::static_facts;
00014
00015 void StaticFacts::retrieveStaticFacts(AspKR *reasoner, const std::string& domain_directory) {
00016
00017
00018
00019 std::vector<std::string> query_string_list;
00020 if (boost::filesystem::exists(domain_directory)) {
00021 boost::filesystem::directory_iterator itr(domain_directory);
00022 boost::filesystem::directory_iterator end_itr;
00023 for (; itr != end_itr; ++itr) {
00024 if (boost::algorithm::contains(itr->path().string(), ".asp")) {
00025
00026 std::ifstream infile(itr->path().string().c_str());
00027 std::string line;
00028 while (std::getline(infile, line)) {
00029 if (boost::algorithm::contains(line, "#hide")) {
00030 boost::replace_all(line, "#hide", "#show");
00031 query_string_list.push_back(line);
00032 }
00033 }
00034 infile.close();
00035 }
00036 }
00037 }
00038
00039
00040 std::string query = boost::algorithm::join(query_string_list, "\n");
00041 static_facts = (reasoner->query(query, 0, 0)).front();
00042 }
00043
00044 std::list<actasp::AspAtom> StaticFacts::staticFacts() {
00045 return static_facts;
00046 }
00047
00048 }