void multithreaded_segment( void * args) { string sentence; vector<string> result; Dispatcher * dispatcher = (Dispatcher *)args; void * model = dispatcher->model(); while (true) { int ret = dispatcher->next(sentence); if (ret < 0) break; result.clear(); segmentor_segment(model, sentence, result); dispatcher->output(result); } return; }
void multithreaded_ltp( void * args) { string sentence; Dispatcher * dispatcher = (Dispatcher *)args; LTP * engine = dispatcher->get_engine(); while (true) { int ret = dispatcher->next(sentence); if (ret < 0) break; XML4NLP xml4nlp; xml4nlp.CreateDOMFromString(sentence); if(type == "ws"){ engine->wordseg(xml4nlp); } else if(type == "pos"){ engine->postag(xml4nlp); } else if(type == "ner"){ engine->ner(xml4nlp); } else if(type == "dp"){ engine->parser(xml4nlp); } else if(type == "srl"){ engine->srl(xml4nlp); } else { engine->srl(xml4nlp); } string result; vector<string> words; xml4nlp.GetWordsFromSentence(words, 0); size_t ii = 0; for (; ii < words.size() - 1; ++ii) result += words[ii] + " "; result += words[ii]; // xml4nlp.SaveDOM(result); xml4nlp.ClearDOM(); dispatcher->output(ret, result); } return; }
void multithreaded_ltp( void * args) { string sentence; Dispatcher * dispatcher = (Dispatcher *)args; LTP * engine = dispatcher->get_engine(); while (true) { int ret = dispatcher->next(sentence); if (ret < 0) break; XML4NLP xml4nlp; xml4nlp.CreateDOMFromString(sentence); if(type == "ws"){ engine->wordseg(xml4nlp); } else if(type == "pos"){ engine->postag(xml4nlp); } else if(type == "ner"){ engine->ner(xml4nlp); } else if(type == "dp"){ engine->parser(xml4nlp); } else if(type == "srl"){ engine->srl(xml4nlp); } else { engine->srl(xml4nlp); } string result; xml4nlp.SaveDOM(result); xml4nlp.ClearDOM(); dispatcher->output(ret, result); } return; }
void multithreaded_recognize( void * args) { std::vector<std::string> words; std::vector<std::string> postags; std::vector<std::string> tags; Dispatcher * dispatcher = (Dispatcher *)args; void * model = dispatcher->get_engine(); std::string buffer; std::string token; while (true) { int ret = dispatcher->next(buffer); if (ret < 0) break; std::stringstream S(buffer); words.clear(); postags.clear(); while (S >> token) { size_t npos = token.find_last_of("_"); words.push_back(token.substr(0, npos)); postags.push_back(token.substr(npos+ 1)); } tags.clear(); ner_recognize(model, words, postags, tags); std::string output; S.clear(); S.str(""); for (size_t i = 0; i < tags.size(); ++ i) { if (i > 0) { S << "\t"; } S << words[i] << "/" << postags[i] << "#" << tags[i]; } dispatcher->output(ret, S.str()); } return; }
void multithreaded_ltp( void * args) { std::string sentence; Dispatcher * dispatcher = (Dispatcher *)args; LTP* engine = (LTP*)dispatcher->get_engine(); while (true) { int ret = dispatcher->next(sentence); if (ret < 0) break; XML4NLP xml4nlp; xml4nlp.CreateDOMFromString(sentence); if (type == "sp") { engine->splitSentence_dummy(xml4nlp); } else if(type == LTP_SERVICE_NAME_SEGMENT) { engine->wordseg(xml4nlp); } else if(type == LTP_SERVICE_NAME_POSTAG) { engine->postag(xml4nlp); } else if(type == LTP_SERVICE_NAME_NER) { engine->ner(xml4nlp); } else if(type == LTP_SERVICE_NAME_DEPPARSE) { engine->parser(xml4nlp); } else if(type == LTP_SERVICE_NAME_SRL) { engine->srl(xml4nlp); } else { engine->srl(xml4nlp); } std::string result; xml4nlp.SaveDOM(result); xml4nlp.ClearDOM(); dispatcher->output(ret, result); } return; }