static bool compare(map_type const & MA, map_type const & MB)
			{
				std::vector < std::pair<std::string,std::string> > SA, SB;
				for ( typename map_type::const_iterator ita = MA.begin(); ita != MA.end(); ++ita )
					SA.push_back(std::pair<std::string,std::string>(ita->first,ita->second));
				for ( typename map_type::const_iterator ita = MB.begin(); ita != MB.end(); ++ita )
					SB.push_back(std::pair<std::string,std::string>(ita->first,ita->second));
				std::sort(SA.begin(),SA.end());
				std::sort(SB.begin(),SB.end());
				
				uint64_t ia = 0, ib = 0;
				
				for ( ; ia != SA.size() && ib != SB.size() ; ++ia, ++ib )
					if ( SA[ia] != SB[ib] )
					{
						#if 0
						std::cerr << printPair(SA[ia]) << " != " << printPair(SB[ib]) << std::endl;
						
						for ( uint64_t i = 0; i < SA.size(); ++i )
							std::cerr << SA[i].first << ";";
						std::cerr << MA.size();
						std::cerr << std::endl;
						for ( uint64_t i = 0; i < SB.size(); ++i )
							std::cerr << SB[i].first << ";";
						std::cerr << MB.size();
						std::cerr << std::endl;
						#endif
						
						return SA[ia] < SB[ib];
					}

				return ia < ib;
			}
예제 #2
0
int main(int argc, const char** argv)
{
   std::string text;
   for(int i = 1; i < argc; ++i)
   {
      cout << "Processing file " << argv[i] << endl;
      std::ifstream fs(argv[i]);
      load_file(text, fs);
      fs.close();
      // construct our iterators:
      boost::sregex_iterator m1(text.begin(), text.end(), expression);
      boost::sregex_iterator m2;
      std::for_each(m1, m2, &regex_callback);
      // copy results:
      cout << class_index.size() << " matches found" << endl;
      map_type::iterator c, d;
      c = class_index.begin();
      d = class_index.end();
      while(c != d)
      {
         cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
         ++c;
      }
      class_index.erase(class_index.begin(), class_index.end());
   }
   return 0;
}
예제 #3
0
inline void operation_sequence::execute(int id)
{
    log_.push_back(id);
    if (!failed_ && last_executed_ < id) {
        if (++total_executed_ == operations_.size())
            success_ = true;
        last_executed_ = id;
    } else {
        success_ = false;
        failed_ = true;
    }
}
예제 #4
0
static void find_unreachable_objects_impl(map_type const & m, map2_type & m2)
{
    // scan objects for shared_ptr members, compute internal counts

    {
        std::cout << "... " << m.size() << " objects in m.\n";

        for(map_type::const_iterator i = m.begin(); i != m.end(); ++i)
        {
            abt_boost::detail::sp_counted_base const * p = static_cast<abt_boost::detail::sp_counted_base const *>(i->first);

            BOOST_ASSERT(p->use_count() != 0); // there should be no inactive counts in the map

            m2[ i->first ];

            scan_and_count(i->second.first, i->second.second, m, m2);
        }

        std::cout << "... " << m2.size() << " objects in m2.\n";
    }

    // mark reachable objects

    {
        open_type open;

        for(map2_type::iterator i = m2.begin(); i != m2.end(); ++i)
        {
            abt_boost::detail::sp_counted_base const * p = static_cast<abt_boost::detail::sp_counted_base const *>(i->first);
            if(p->use_count() != i->second) open.push_back(p);
        }

        std::cout << "... " << open.size() << " objects in open.\n";

        for(open_type::iterator j = open.begin(); j != open.end(); ++j)
        {
            m2.erase(*j);
        }

        while(!open.empty())
        {
            void const * p = open.front();
            open.pop_front();

            map_type::const_iterator i = m.find(p);
            BOOST_ASSERT(i != m.end());

            scan_and_mark(i->second.first, i->second.second, m2, open);
        }
    }

    // m2 now contains the unreachable objects
}
예제 #5
0
int main(int argc, const char** argv)
{
   std::string text;
   for(int i = 1; i < argc; ++i)
   {
      cout << "Processing file " << argv[i] << endl;
      std::ifstream fs(argv[i]);
      load_file(text, fs);
      fs.close();
      IndexClasses(text);
      cout << class_index.size() << " matches found" << endl;
      map_type::iterator c, d;
      c = class_index.begin();
      d = class_index.end();
      while(c != d)
      {
         cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
         ++c;
      }
      class_index.erase(class_index.begin(), class_index.end());
   }
   return 0;
}
예제 #6
0
void strategy_c1(graph_type& graph, const string &q_entity, vec &f_q, map_type &index_of_kb, mat & Ws, vector<pair<double, AnswerInfo>> &answers){

	if (index_of_kb.count(q_entity) == 0){
		cout << "key error: can't find " << q_entity << "in index_of_kb" << endl;
	}
	
	static uniform_real_distribution<double> distribution(0.0, 1.0);
	static default_random_engine generator;
	unsigned start_index = index_of_kb.size();
	for (auto &item1 : graph[q_entity]){
		for (auto &candidate : item1.second){
			vector<unsigned> answer_vec;
			answer_vec.push_back(index_of_kb[q_entity]);
			answer_vec.push_back(index_of_kb[item1.first]);  // add relation in path
			answer_vec.push_back(index_of_kb[candidate]);

			double prob = min(1.0, 100.0 / graph[candidate].size());
			unordered_set<unsigned> subgraph_set;
			// add subgraph
			for (auto & item2 : graph[candidate]){
				if (distribution(generator) <= prob){
					subgraph_set.insert(start_index + index_of_kb[item2.first]);
					for (auto & obj : item2.second){
						subgraph_set.insert(start_index + index_of_kb[obj]);
					}
				}
			}
			//cout << "Element number of subgraph = " << subgraph_set.size() << endl;
			copy(subgraph_set.begin(), subgraph_set.end(), back_inserter(answer_vec));
			auto score = scoreFunc(f_q, answer_vec, Ws);
			answers.push_back(std::move(make_pair(score * 1.5, std::move(AnswerInfo{ candidate, q_entity, 1 }))));
			
		}
	}
	//sort(answers.begin(), answers.end(), [](const pair<double, string> &lhs, const pair<double, string>&rhs){return lhs.first > rhs.first; });
}
예제 #7
0
파일: Index.hpp 프로젝트: troyh/xmldb
		virtual size_t keyCount() const { return m_map.size(); }
예제 #8
0
void beam_search_c2(graph_type& graph, const string &q_entity, vec &f_q, map_type &index_of_kb, mat & Ws, vector<pair<double, AnswerInfo>> &answers){

	priority_queue<triple_type, vector<triple_type>, Cmp>  pq;
	static uniform_real_distribution<double> distribution(0.0, 1.0);
	static default_random_engine generator;
	if (index_of_kb.count(q_entity) == 0){
		cout << "key error: can't find " << q_entity << "in index_of_kb" << endl;
	}
	
	for (auto &item1 : graph[q_entity]){
		
		auto rel1 = item1.first;
		for (auto m : item1.second){ // mediator entity
			for (auto item2 : graph[m]){
				auto rel2 = item2.first; // the 2nd hop relation
				vector<unsigned> answer_vec;
				answer_vec.push_back(index_of_kb[q_entity]);
				answer_vec.push_back(index_of_kb[rel1]);
				answer_vec.push_back(index_of_kb[rel2]);
				double score = scoreFunc(f_q, answer_vec, Ws);
				if (pq.empty() < 10){
					pq.push(std::move(make_tuple(score, rel1, rel2)));
				}
				else if (get<0>(pq.top()) < score){
					pq.pop();
					pq.push(std::move(make_tuple(score, rel1, rel2)));
				}
			}
		}
	}
	unsigned start_index = index_of_kb.size();
	while (!pq.empty()){
		auto e = pq.top();
		pq.pop();
		string rel1 = get<1>(e);
		string rel2 = get<2>(e);

		for (auto & meditor_node : graph[q_entity][rel1]){
			
			for (auto answer_node : graph[meditor_node][rel2]){
				vector<unsigned> answer_vec;
				answer_vec.push_back(index_of_kb[q_entity]);
				answer_vec.push_back(index_of_kb[rel1]);
				answer_vec.push_back(index_of_kb[rel2]);
				answer_vec.push_back(index_of_kb[answer_node]);
				// add subgraph
				unordered_set<unsigned> subgraph_set;
				for (auto & item : graph[answer_node]){
					double prob = min(1.0, 100.0 / graph[answer_node].size());
					if (distribution(generator) <= prob){
						subgraph_set.insert(start_index + index_of_kb[item.first]); // relation linking to answer node
						for (auto & o : item.second)
							subgraph_set.insert(start_index + index_of_kb[o]);
					}
				}
				//cout << "Element number of subgraph = " << subgraph_set.size() << endl;
				copy(subgraph_set.begin(), subgraph_set.end(), back_inserter(answer_vec));
				auto score = scoreFunc(f_q, answer_vec, Ws);
				answers.push_back(std::move(make_pair(score, std::move(AnswerInfo{ answer_node, q_entity, 2}))));
			}
		}
	}
	//sort(answers.begin(), answers.end(), [](const pair<double, string> &lhs, const pair<double, string>&rhs){return lhs.first > rhs.first; });
}
예제 #9
0
 size_type size() const  {
     return pa.size();
 }