Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
    if (argc != 4)
    {
        cerr << "Usage: ./ltp_test <type> <test_file> <result_file>" << endl;
        exit(1);
    }

    string type(argv[1]);
    string in_file(argv[2]);
    string res_file(argv[3]);

    xml4nlp.CreateDOMFromFile(in_file.c_str());

    if (type == "ws") {
        ltp.crfWordSeg(xml4nlp);
    } else if(type == "pos"){
        ltp.postag(xml4nlp);
    } else if(type == "ner"){
        ltp.ner(xml4nlp);
    } else if(type == "dp"){
        ltp.gparser(xml4nlp);
    } else if(type == "srl"){
        ltp.srl(xml4nlp);
    } else {
        ltp.srl(xml4nlp);
    }

    string result;
    xml4nlp.SaveDOM(result);

    ofstream out(res_file.c_str());
    out << result << endl;
    cerr << "Results saved to " << res_file << endl;

    xml4nlp.ClearDOM();

    return 0;
}