Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
endyul committed Jun 9, 2017
1 parent 65b0adc commit be879c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/ner/ner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const std::string NamedEntityRecognizer::model_header = "otner";
const std::string NamedEntityRecognizer::delimiter = "-";

NamedEntityRecognizer::NamedEntityRecognizer(): model(0), glob_con(0) {}
NamedEntityRecognizer::~NamedEntityRecognizer() { if (model) { delete model; model = 0; } }
NamedEntityRecognizer::~NamedEntityRecognizer() {
if (model) { delete model; model = 0; }
if (glob_con) { delete glob_con; glob_con = 0; }
}

void NamedEntityRecognizer::build_glob_tran_cons(
const std::unordered_set<std::string>& ne_types) {
Expand Down
1 change: 0 additions & 1 deletion src/ner/ner_frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ NamedEntityRecognizerFrontend::NamedEntityRecognizerFrontend(
}

NamedEntityRecognizerFrontend::~NamedEntityRecognizerFrontend() {
if (glob_con) { delete glob_con; glob_con = 0; }

for (size_t i = 0; i < train_dat.size(); ++ i) {
if (train_dat[i]) { delete train_dat[i]; train_dat[i] = 0; }
Expand Down
12 changes: 11 additions & 1 deletion src/server/ltp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) {
if (vm.count("parser-model")) {
parser_model= vm["parser-model"].as<std::string>();
}
INFO_LOG("parser model after vm :\"%s\"", parser_model.c_str());
//INFO_LOG("parser model after vm :\"%s\"", parser_model.c_str());
std::string srl_model= "ltp_data/pisrl.model";
if (vm.count("srl-model")) {
srl_model = vm["srl-model"].as<std::string>();
Expand Down Expand Up @@ -428,12 +428,14 @@ static int Service(struct mg_connection *conn) {
if (strlen(sentence) == 0) {
WARNING_LOG("Input sentence is empty");
ErrorResponse(conn, kEmptyStringError);
delete[] sentence;
return 0;
}

if (!isclear(strSentence)) {
WARNING_LOG("Failed string validation check");
ErrorResponse(conn, kEncodingError);
delete[] sentence;
return 0;
}

Expand Down Expand Up @@ -464,6 +466,7 @@ static int Service(struct mg_connection *conn) {
if(str_xml == "y") {
if (-1 == xml4nlp.LoadXMLFromString(strSentence)) {
ErrorResponse(conn, kXmlParseError);
delete[] sentence;
return 0;
}
// move sentence validation check into each module
Expand All @@ -475,37 +478,43 @@ static int Service(struct mg_connection *conn) {
int ret = engine->wordseg(xml4nlp);
if (0 != ret) {
ErrorResponse(conn, static_cast<ErrorCodes>(ret));
delete[] sentence;
return 0;
}
} else if (str_type == LTP_SERVICE_NAME_POSTAG){
int ret = engine->postag(xml4nlp);
if (0 != ret) {
ErrorResponse(conn, static_cast<ErrorCodes>(ret));
delete[] sentence;
return 0;
}
} else if (str_type == LTP_SERVICE_NAME_NER) {
int ret = engine->ner(xml4nlp);
if (0 != ret) {
ErrorResponse(conn, static_cast<ErrorCodes>(ret));
delete[] sentence;
return 0;
}
} else if (str_type == LTP_SERVICE_NAME_DEPPARSE){
int ret = engine->parser(xml4nlp);
if (0 != ret) {
ErrorResponse(conn, static_cast<ErrorCodes>(ret));
delete[] sentence;
return 0;
}
} else if (str_type == LTP_SERVICE_NAME_SRL){ // srl
int ret = engine->srl(xml4nlp);
if (0 != ret) {
ErrorResponse(conn, static_cast<ErrorCodes>(ret));
delete[] sentence;
return 0;
}
} else { // all
str_type = LTP_SERVICE_NAME_ALL;
int ret = engine->srl(xml4nlp);
if (0 != ret) {
ErrorResponse(conn, static_cast<ErrorCodes>(ret));
delete[] sentence;
return 0;
}
}
Expand All @@ -524,6 +533,7 @@ static int Service(struct mg_connection *conn) {
mg_printf(conn, "%s", strResult.c_str());

xml4nlp.ClearDOM();
delete[] sentence;
}
return 1;
}
Expand Down

0 comments on commit be879c9

Please sign in to comment.