Esempio n. 1
0
int main(void)
{
    ScopedLogMessage msg("msg>", "msg start", "msg end");
    Functors<std::string, std::string, std::string, int> functors(msg);
    functors.connect("hello", [&](std::string nick, int age)
    {
        std::cout << "print hello, " << nick << ", R U" << age << "years old?" << std::endl;
        return "print hello";
    });
    //functors.connect("shit", shit);
    //functors.connect("world", world());
    //std::cout << functors.emit("hello") << std::endl;
    //std::cout << functors.emit("shit") << std::endl;
    //std::cout << functors.emit("world") << std::endl;
    return 0;
}
Esempio n. 2
0
std::string tokenpaths::create_analysis(const unsigned char& toa,const std::string& target_language){
	std::map<std::string,std::string> related_functors;
	std::map<std::string,std::map<std::string,std::string> > functors_of_words;

	unsigned int nr_of_analyses=valid_paths.size();
	if(nr_of_analyses==0&&toa==HI_MORPHOLOGY){
		logger::singleton()==NULL?(void)0:logger::singleton()->log(0,"There is 1 analysis.");
	}
	else{
		logger::singleton()==NULL?(void)0:logger::singleton()->log(0,"There are "+std::to_string(nr_of_analyses)+" analyses.");
	}
	std::string analysis="{\"analyses\":[";
	if(nr_of_analyses==0){
		analysis+="{";
		std::map<std::string,std::vector<lexicon> > words_analyses=lexer::words_analyses();
		if(toa&HI_MORPHOLOGY){
			analysis+="\"morphology\":[";
			for(auto&& word_analyses:words_analyses){
				analysis+=morphology(word_analyses.second);
			}
			if(analysis.back()==',') analysis.pop_back();
			analysis+="],";
		}
		if(toa&HI_SYNTAX){
			analysis+="\"syntax\":[";
			analysis+="],";
		}
		if(toa&HI_SEMANTICS){
			std::string semantic_analysis="\"semantics\":[";
			std::vector<std::string> word_forms=lexer::word_forms();
			unsigned int id_index=0;
			for(auto&& word_form:word_forms){
				auto&& word_analyses=words_analyses.find(word_form);
				related_functors.clear();
				semantic_analysis+=semantics(word_analyses->second,related_functors,id_index,target_language);
				functors_of_words.insert(std::make_pair(word_analyses->first,related_functors));
			}
			if(semantic_analysis.back()==',') semantic_analysis.pop_back();
			semantic_analysis+="],";
			std::string functor_analysis="\"functors\":[";
			std::string related_semantics="\"related semantics\":[";
			functor_analysis+=functors(functors_of_words,words_analyses,id_index,related_semantics);
			if(functor_analysis.back()==',') functor_analysis.pop_back();
			functor_analysis+="],";
			if(related_semantics.back()==',') related_semantics.pop_back();
			related_semantics+="],";
			analysis+=semantic_analysis;
			analysis+=related_semantics;
			analysis+=functor_analysis;
		}
		if(invalid_path_errors.empty()==false){
			analysis+="\"errors\":[";
			unsigned int id=0;
			for(auto&& error:invalid_path_errors){
				analysis+="{\"tokenpath id\":\""+std::to_string(++id)+"\",\"messages\":["+error+"]},";
			}
			if(analysis.back()==',') analysis.pop_back();
			analysis+="]";
		}
		if(analysis.back()==',') analysis.pop_back();
		analysis+="}";
	}
	else{
		for(unsigned int i=0;i<nr_of_analyses;++i){
			related_functors.clear();
			analysis+="{";
			if(toa&HI_MORPHOLOGY){
				analysis+="\"morphology\":["+morphology(valid_paths.at(i));
				if(analysis.back()==',') analysis.pop_back();
				analysis+="],";
			}
			if(toa&HI_SYNTAX){
				analysis+="\"syntax\":[";
				analysis+=syntax(valid_parse_trees.at(i));
				analysis+="],";
			}
			if(toa&HI_SEMANTICS){
				analysis+="\"semantics\":["+valid_graphs.at(i)->transcript(related_functors,target_language);
				if(analysis.back()==',') analysis.pop_back();
				analysis+="],";
				analysis+="\"functors\":[";
				for(auto&& functor:related_functors){
					analysis+="{";
					analysis+="\"functor id\":\""+functor.first+"\",";
					analysis+="\"definition\":\""+functor.second+"\"";
					analysis+="},";
				}
				if(analysis.back()==',') analysis.pop_back();
				analysis+="]";
			}
			if(analysis.back()==',') analysis.pop_back();
			analysis+="},";
		}
		if(analysis.back()==',') analysis.pop_back();
	}
	analysis+="]}";
	return analysis;
}