Skip to content

Commit

Permalink
support multiple last stage
Browse files Browse the repository at this point in the history
  • Loading branch information
liu946 committed Dec 15, 2017
1 parent e31e337 commit 5432d23
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
23 changes: 14 additions & 9 deletions src/console/ltp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,22 @@ int main(int argc, char *argv[]) {
}
}

std::string last_stage = LTP_SERVICE_NAME_DEFAULT;
std::string last_stage = "all";
if (vm.count("last-stage")) {
last_stage = vm["last-stage"].as<std::string>();
if (last_stage != LTP_SERVICE_NAME_SEGMENT
&& last_stage != LTP_SERVICE_NAME_POSTAG
&& last_stage != LTP_SERVICE_NAME_NER
&& last_stage != LTP_SERVICE_NAME_DEPPARSE
&& last_stage != LTP_SERVICE_NAME_SRL
&& last_stage != LTP_SERVICE_NAME_ALL) {
std::cerr << "Unknown stage name:" << last_stage << ", reset to '" LTP_SERVICE_NAME_DEFAULT "'" << std::endl;
last_stage = LTP_SERVICE_NAME_DEFAULT;
vector<string> stages = ltp::strutils::split_by_sep(last_stage, "|");

for (int j = 0; j < stages.size(); ++j) {
if (stages[j] != LTP_SERVICE_NAME_SEGMENT
&& stages[j] != LTP_SERVICE_NAME_POSTAG
&& stages[j] != LTP_SERVICE_NAME_NER
&& stages[j] != LTP_SERVICE_NAME_DEPPARSE
&& stages[j] != LTP_SERVICE_NAME_SRL
&& stages[j] != "all") {
std::cerr << "Unknown stage name:" << last_stage << ", reset to 'all'" << std::endl;
last_stage = "all";
break;
}
}
}

Expand Down
30 changes: 17 additions & 13 deletions src/ltp/Ltp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <ctime>
#include <map>
#include <string>
#include <utils/strutils.hpp>

#include "xml4nlp/Xml4nlp.h"
#include "splitsnt/SplitSentence.h"
Expand Down Expand Up @@ -50,19 +51,22 @@ bool LTP::load(const std::string& last_stage,
const std::string& srl_model_file) {

size_t target_mask = 0;
if (last_stage == LTP_SERVICE_NAME_SEGMENT) {
target_mask = kActiveSegmentor;
} else if (last_stage == LTP_SERVICE_NAME_POSTAG) {
target_mask = (kActiveSegmentor|kActivePostagger);
} else if (last_stage == LTP_SERVICE_NAME_NER) {
target_mask = (kActiveSegmentor|kActivePostagger|kActiveNER);
} else if (last_stage == LTP_SERVICE_NAME_DEPPARSE) {
target_mask = (kActiveSegmentor|kActivePostagger|kActiveParser);
} else if (last_stage == LTP_SERVICE_NAME_SRL) {
target_mask = (kActiveSegmentor|kActivePostagger|kActiveParser|kActiveSRL);
} else if (last_stage == "all") {
target_mask =
(kActiveSegmentor|kActivePostagger|kActiveNER|kActiveParser|kActiveSRL);
vector<string> stages = ltp::strutils::split_by_sep(last_stage, "|");
for (int j = 0; j < stages.size(); ++j) {
if (stages[j] == LTP_SERVICE_NAME_SEGMENT) {
target_mask |= kActiveSegmentor;
} else if (stages[j] == LTP_SERVICE_NAME_POSTAG) {
target_mask |= (kActiveSegmentor | kActivePostagger);
} else if (stages[j] == LTP_SERVICE_NAME_NER) {
target_mask |= (kActiveSegmentor | kActivePostagger | kActiveNER);
} else if (stages[j] == LTP_SERVICE_NAME_DEPPARSE) {
target_mask |= (kActiveSegmentor | kActivePostagger | kActiveParser);
} else if (stages[j] == LTP_SERVICE_NAME_SRL) {
target_mask |= (kActiveSegmentor | kActivePostagger | kActiveParser | kActiveSRL);
} else if (stages[j] == "all") {
target_mask |=
(kActiveSegmentor | kActivePostagger | kActiveNER | kActiveParser | kActiveSRL);
}
}

size_t loaded_mask = 0;
Expand Down
21 changes: 13 additions & 8 deletions src/server/ltp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,19 @@ int main(int argc, char *argv[]) {
std::string last_stage = "all";
if (vm.count("last-stage")) {
last_stage = vm["last-stage"].as<std::string>();
if (last_stage != LTP_SERVICE_NAME_SEGMENT
&& last_stage != LTP_SERVICE_NAME_POSTAG
&& last_stage != LTP_SERVICE_NAME_NER
&& last_stage != LTP_SERVICE_NAME_DEPPARSE
&& last_stage != LTP_SERVICE_NAME_SRL
&& last_stage != "all") {
std::cerr << "Unknown stage name:" << last_stage << ", reset to 'all'" << std::endl;
last_stage = "all";
vector<string> stages = ltp::strutils::split_by_sep(last_stage, "|");

for (int j = 0; j < stages.size(); ++j) {
if (stages[j] != LTP_SERVICE_NAME_SEGMENT
&& stages[j] != LTP_SERVICE_NAME_POSTAG
&& stages[j] != LTP_SERVICE_NAME_NER
&& stages[j] != LTP_SERVICE_NAME_DEPPARSE
&& stages[j] != LTP_SERVICE_NAME_SRL
&& stages[j] != "all") {
std::cerr << "Unknown stage name:" << last_stage << ", reset to 'all'" << std::endl;
last_stage = "all";
break;
}
}
}

Expand Down

0 comments on commit 5432d23

Please sign in to comment.