コード例 #1
0
ファイル: Server.cpp プロジェクト: edouard-lopez/sinoparserd
/**** uri: /change_script?str=*
 *
 */
static void http_change_script_callback(struct evhttp_request *request, void *data) {

    //parse uri
    struct evkeyvalq params_get;
    PARSE_URI(request, params_get);
    SinoparserServer* serv = (SinoparserServer*) data;


    //get "str"
    char const *str;
    PARAM_GET_STR(str, &params_get, "str", true);
    serv->parser.change_text((char*)str);
    serv->parser.parse_against_index(serv->db.mandarin_words);
    std::string change_script = serv->parser.change_script();

    //prepare output
    struct evbuffer *buffer = evbuffer_new();
 
    output_xml_header(buffer);
    change_script_output_xml(change_script, buffer);
    output_xml_footer(buffer);


    //send
    evhttp_add_header(request->output_headers, "Content-Type", "TEXT/XML; charset=UTF8");

    evhttp_send_reply(request, HTTP_OK, "", buffer);

}
コード例 #2
0
ファイル: Server.cpp プロジェクト: Tatoeba/sinoparserd
/**** uri: /all?str=*
 *
 */
static void http_all_callback(struct evhttp_request *request, void *data) {

    //parse uri
    struct evkeyvalq params_get;
    PARSE_URI(request, params_get);
    SinoparserServer* serv = (SinoparserServer*) data;


    //get "str"
    char const *str;
    PARAM_GET_STR(str, &params_get, "str", true);
    serv->parser.change_text((char*)str);
    serv->parser.parse_against_index(serv->db.mandarin_words);

    std::string guess_script = ""; 
    bool script = serv->parser.guess_script();
    if (script == TRADITIONAL_SCRIPT) {
        guess_script = "traditional_script";
    }  else if (script == SIMPLIFIED_SCRIPT) {
        guess_script = "simplified_script";
    }

    //prepare output
    struct evbuffer *buffer = evbuffer_new();
 
    output_xml_header(buffer);
        guess_script_output_xml(guess_script, buffer);
        romanization_output_xml(serv->parser.romanize(), buffer);
        change_script_output_xml(serv->parser.change_script(), buffer);
    output_xml_footer(buffer);


    //send
    evhttp_add_header(request->output_headers, "Content-Type", "TEXT/XML; charset=UTF8");

    evhttp_send_reply(request, HTTP_OK, "", buffer);

    evhttp_clear_headers(&params_get);
    evbuffer_free(buffer);
}