Skip to content

Commit

Permalink
add length constrain in server
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneplus committed Sep 8, 2013
1 parent 9e598a8 commit 946512e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/server/ltp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,28 @@ static int Service(struct mg_connection *conn) {
// failed the xml validation check
return 0;
}

// guanrante the input sentence is not to long.
int num_para = xml4nlp.CountParagraphInDocument();
bool flag = true;
for (int i = 0; i < num_para; ++ i) {
int num_sent = xml4nlp.CountSentenceInParagraph(i);
for (int j = 0; j < num_sent; ++ j) {
if (length(std::string(xml4nlp.GetSentence(i,j))) > 70) {
flag = false;
}
}
}

if (!flag) {
WARNING_LOG("Input sentence is too long");
return 0;
}
} else {
if (length(strSentence) > 70) {
WARNING_LOG("Input sentence is too long");
return 0;
}
xml4nlp.CreateDOMFromString(strSentence);
}

Expand Down

0 comments on commit 946512e

Please sign in to comment.