Skip to content

Commit

Permalink
Merge pull request HIT-SCIR#272 from HIT-SCIR/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
liu946 authored Dec 17, 2017
2 parents f44254e + 93b33d7 commit 5ed1662
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
1 change: 1 addition & 0 deletions doc/ltpserver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ LTP Server在轻量级服务器程序mongoose基础上开发。在编译LTP源

其中较为重要的参数包括:

- last-stage: 特别的,可以使用 "|" 来分割多个最终目标。例如需要ner和parser就设置为 "ner|dp"。
- port:指定LTP server监听的端口
- threads:指定LTP server运行的线程数,线程数影响并发的处理能力
- log-level:指定日志级别,TRACE级别最低,显示日志信息最详细。INFO级别最高,显示日志最粗略。WARN与ERROR级日志默认显示。
Expand Down
2 changes: 2 additions & 0 deletions doc/ltptest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Pipeline与last-stage参数

默认情况下,LTP将进行至语义角色标注的分析。但是,对于一部分用户,某些分析并不必要。举例来讲,如果用户只需进行词性标注,则ltp_test的pipeline分析只需进行到pos,`last-stage`用来指明分析的最后状态。同时,如果`last-stage`指定为pos,句法分析、命名实体识别和语义角色标注的模型将不被加载。

注: last-stage: 特别的,可以使用 "|" 来分割多个最终目标。例如需要ner和parser就设置为 "ner|dp"。
.. _xxxcmdline-reference-label:

xxx_cmdline
Expand Down
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 5ed1662

Please sign in to comment.