StaticFacts.cpp
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   // Construct the query by showing everything. From the ASP files, collect every hide statement and convert it to a 
00017   // show statement. Then make a generic query.
00018   /* std::cout << "in" << std::endl; */
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         // Read this file and collect all lines with #show on them.
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   /* std::cout << "out" << std::endl; */
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 }


bwi_kr_execution
Author(s): Matteo Leonetti, Piyush Khandelwal
autogenerated on Fri Aug 28 2015 10:14:46