Skip to content

Commit

Permalink
Merge branch 'ltp-new-framework' of github.com:HIT-SCIR/ltp into ltp-…
Browse files Browse the repository at this point in the history
…new-framework
  • Loading branch information
Oneplus committed Sep 1, 2013
2 parents a1b3ef8 + 9c50e9b commit 83b46b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/server/ltp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Ltp.h"

#include "codecs.hpp"
#include "logging.hpp"

#if !defined(LISTENING_PORT)
#define LISTENING_PORT "12345"
Expand Down Expand Up @@ -78,36 +79,61 @@ static int Service(struct mg_connection *conn) {
buffer[len] = 0;
str_post_data += buffer;
}
cout << str_post_data.size() << " " << str_post_data << endl;

TRACE_LOG("CDATA: %s", str_post_data.c_str());
TRACE_LOG("CDATA length: %d", str_post_data.size());

sentence = new char[str_post_data.size() + 1];
mg_get_var(str_post_data.c_str(), str_post_data.size(), "s", sentence, str_post_data.size());
mg_get_var(str_post_data.c_str(), str_post_data.size(), "t", type, sizeof(type) - 1);
mg_get_var(str_post_data.c_str(), str_post_data.size(), "x", xml, sizeof(xml) - 1);

mg_get_var(str_post_data.c_str(),
str_post_data.size(),
"s",
sentence,
str_post_data.size());

mg_get_var(str_post_data.c_str(),
str_post_data.size(),
"t",
type,
sizeof(type) - 1);

mg_get_var(str_post_data.c_str(),
str_post_data.size(),
"x",
xml,
sizeof(xml) - 1);

// std::cerr << "sentence: " << sentence << std::endl;
// std::cerr << "type : " << type << std::endl;
// std::cerr << "xml : " << xml << std::endl;
// std::cerr << "validation check" << std::endl;

string strSentence = sentence;
delete []sentence;

/*
* validation check
*/
if (strcmp(sentence, "") == 0 || !isclear(strSentence)) {
if (strlen(sentence) == 0 || !isclear(strSentence)) {
// std::cerr << "Failed validation check" << std::endl;
WARNING_LOG("Failed string validation check");
return 0;
}

if(strcmp(type, "") == 0) {
if(strlen(type) == 0) {
str_type = "";
} else {
str_type = type;
}

if(strcmp(xml, "") == 0) {
if(strlen(xml) == 0) {
str_xml = "";
} else {
str_xml = xml;
}

cout << "Input sentence is: " << strSentence << endl;
delete []sentence;

TRACE_LOG("Input sentence is: %s", strSentence.c_str());

if(str_xml == "y"){
xml4nlp.LoadXMLFromString(strSentence);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/codecs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ inline bool isclear(const std::string & s, int encoding=UTF8) {
return false;
}
}

return true;
} else if (encoding == GBK) {
return true;
} else {
Expand Down

0 comments on commit 83b46b8

Please sign in to comment.