Skip to content

Commit

Permalink
Merge pull request HIT-SCIR#81 from ruoshui1126/personal
Browse files Browse the repository at this point in the history
test output directory
  • Loading branch information
Oneplus committed Nov 12, 2014
2 parents 12ce192 + a0732ef commit bb6d225
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 84 deletions.
45 changes: 45 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#################################################
# Example for call LTP libraries under UNIX #
#################################################
cc=g++
ccflags=-O2
all: cws \
pos \
par \
ner \
srl

cws: cws.cpp
${cc} ${ccflags} -o cws cws.cpp -I./ \
-I../include/ \
-I../thirdparty/boost/include \
-L../lib/ -lsegmentor -lboost_regex

pos: pos.cpp
${cc} ${ccflags} -o pos pos.cpp -I./ \
-I../include/ \
-L../lib/ -lpostagger

ner: ner.cpp
${cc} ${ccflags} -o ner ner.cpp -I./ \
-I../include \
-L../lib/ -lner

par: par.cpp
${cc} ${ccflags} -o par par.cpp -I./ \
-I../include \
-L../lib -lparser

srl: srl.cpp
${cc} ${ccflags} -o srl srl.cpp -I./ \
-I../include \
-L../lib -lsrl

.PHONY: clean

clean:
rm cws
rm pos
rm ner
rm par
rm srl
Binary file added examples/cws
Binary file not shown.
2 changes: 1 addition & 1 deletion test/cws.cpp → examples/cws.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>
#include <string>
#include "segment_dll.h"
#include "ltp/segment_dll.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
Expand Down
Binary file added examples/ner
Binary file not shown.
2 changes: 1 addition & 1 deletion test/ner.cpp → examples/ner.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <iostream>
#include <vector>

#include "ner_dll.h"
#include "ltp/ner_dll.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
Expand Down
Binary file added examples/par
Binary file not shown.
2 changes: 1 addition & 1 deletion test/par.cpp → examples/par.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <iostream>
#include <vector>

#include "parser_dll.h"
#include "ltp/parser_dll.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
Expand Down
Binary file added examples/pos
Binary file not shown.
2 changes: 1 addition & 1 deletion test/pos.cpp → examples/pos.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <iostream>
#include <vector>

#include "postag_dll.h"
#include "ltp/postag_dll.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
Expand Down
Binary file added examples/srl
Binary file not shown.
2 changes: 1 addition & 1 deletion test/srl.cpp → examples/srl.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <iostream>
#include <vector>

#include "SRL_DLL.h"
#include "ltp/SRL_DLL.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
Expand Down
62 changes: 34 additions & 28 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include_directories (./
${SOURCE_DIR}/__util
${SOURCE_DIR}/utils
${SOURCE_DIR}/__xml4nlp
${SOURCE_DIR}/_split_sentence
${SOURCE_DIR}/segmentor
Expand All @@ -21,21 +22,6 @@ set (multi_ltp_test_SRC multi_ltp_test.cpp

link_directories ( ${LIBRARY_OUTPUT_PATH} )

add_executable (ltp_test ${ltp_test_SRC})
add_executable (cws cws.cpp)
add_executable (cws_cmdline cws_cmdline.cpp)
add_executable (multi_cws_cmdline multi_cws_cmdline.cpp
${THIRDPARTY_DIR}/tinythreadpp/tinythread.cpp)
add_executable (pos pos.cpp)
add_executable (pos_cmdline pos.cpp)
add_executable (multi_pos_cmdline multi_pos_cmdline.cpp
${THIRDPARTY_DIR}/tinythreadpp/tinythread.cpp)
add_executable (ner ner.cpp)
add_executable (par par.cpp)
add_executable (srl srl.cpp)
#add_executable (ltp_test_xml ${ltp_test_xml_SRC})
#add_executable (ltp_test2 ${ltp_test2_SRC})

set (ltp_test_LIBS
maxent_static_lib
util_static_lib
Expand All @@ -48,27 +34,47 @@ ner_static_lib
srl_static_lib
xml4nlp
boost_regex_static_lib)
add_executable (ltp_test ${ltp_test_SRC})
target_link_libraries (ltp_test ${ltp_test_LIBS})

if (NOT WIN32)
set (ltp_test_LIBS ${ltp_test_LIBS} pthread)
endif()
add_executable (cws_cmdline cws_cmdline.cpp)
target_link_libraries (cws_cmdline segmentor_static_lib
boost_regex_static_lib)
set_target_properties(cws_cmdline PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/exmaples/)

target_link_libraries (ltp_test ${ltp_test_LIBS})
target_link_libraries (cws segmentor_static_lib boost_regex_static_lib)
target_link_libraries (cws_cmdline segmentor_static_lib boost_regex_static_lib)
target_link_libraries (multi_cws_cmdline segmentor_static_lib boost_regex_static_lib pthread)
target_link_libraries (pos postagger_static_lib)
add_executable (pos_cmdline pos_cmdline.cpp)
target_link_libraries (pos_cmdline postagger_static_lib)
target_link_libraries (multi_pos_cmdline postagger_static_lib pthread)
target_link_libraries (ner ner_static_lib)
target_link_libraries (par parser_static_lib)
target_link_libraries (srl srl_static_lib)
set_target_properties(pos_cmdline PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/exmaples/)

add_executable (par_cmdline par_cmdline.cpp)
target_link_libraries (par_cmdline parser_static_lib)
set_target_properties(par_cmdline PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/exmaples/)
#add_executable (ltp_test_xml ${ltp_test_xml_SRC})
#add_executable (ltp_test2 ${ltp_test2_SRC})

#
# multithreaded ltp test is not supported in Windows
#
if (NOT WIN32)
if (UNIX)
add_executable (multi_ltp_test ${multi_ltp_test_SRC})
target_link_libraries (multi_ltp_test ${ltp_test_LIBS} pthread)

add_executable (multi_cws_cmdline multi_cws_cmdline.cpp
${THIRDPARTY_DIR}/tinythreadpp/tinythread.cpp)
target_link_libraries (multi_cws_cmdline segmentor_static_lib
boost_regex_static_lib
pthread)
set_target_properties(multi_cws_cmdline PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/exmaples/)

add_executable (multi_pos_cmdline multi_pos_cmdline.cpp
${THIRDPARTY_DIR}/tinythreadpp/tinythread.cpp)
target_link_libraries (multi_pos_cmdline postagger_static_lib pthread)
set_target_properties(multi_pos_cmdline PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/exmaples/)
endif()

#target_link_libraries (ltp_test2
Expand Down
13 changes: 3 additions & 10 deletions test/cws_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@
#include <iostream>
#include <ctime>
#include <string>
#include <sys/time.h>
#include <sys/types.h>
#include "time.hpp"
#include "segment_dll.h"

double get_time(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + (tv.tv_usec / 1000000.0);
}

int main(int argc, char * argv[]) {
if (argc < 2) {
std::cerr << "cws [model path] [lexicon_file]" << std::endl;
Expand All @@ -44,7 +37,7 @@ int main(int argc, char * argv[]) {
std::string sentence;

std::cerr << "TRACE: Model is loaded" << std::endl;
double tm = get_time();
double tm = ltp::utility::get_time();

while (std::getline(std::cin, sentence, '\n')) {
words.clear();
Expand All @@ -59,7 +52,7 @@ int main(int argc, char * argv[]) {

segmentor_release_segmentor(engine);

tm = get_time() - tm;
tm = ltp::utility::get_time() - tm;
std::cerr << "TRACE: cws-tm-consume "
<< tm
<< " seconds."
Expand Down
14 changes: 4 additions & 10 deletions test/multi_cws_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <list>
#include <sys/time.h>
#include <sys/types.h>
#include "time.hpp"
#include <cstdlib>

#include "tinythread.h"
Expand All @@ -30,12 +30,6 @@ using namespace tthread;

const int MAX_LEN = 1024;

double get_time(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + (tv.tv_usec / 1000000.0);
}

class Dispatcher {
public:
Dispatcher( void * model ) {
Expand Down Expand Up @@ -124,7 +118,7 @@ int main(int argc, char ** argv) {

Dispatcher* dispatcher = new Dispatcher( engine );

double tm = get_time();
double tm = ltp::utility::get_time();
list<thread *> thread_list;
for (int i = 0; i < num_threads; ++ i) {
thread* t = new thread( multithreaded_segment, (void *)dispatcher );
Expand All @@ -138,7 +132,7 @@ int main(int argc, char ** argv) {
delete t;
}

tm = get_time() - tm;
tm = ltp::utility::get_time() - tm;
std::cerr << "TRACE: consume "
<< tm
<< " seconds."
Expand Down
13 changes: 3 additions & 10 deletions test/multi_pos_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#include <ctime>
#include <vector>
#include <list>
#include <sys/time.h>
#include <sys/types.h>
#include "time.hpp"

#include "tinythread.h"
#include "fast_mutex.h"
Expand All @@ -29,12 +28,6 @@ using namespace tthread;

const int MAX_LEN = 1024;

double get_time(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + (tv.tv_usec / 1000000.0);
}

class Dispatcher {
public:
Dispatcher( void * model ) {
Expand Down Expand Up @@ -121,7 +114,7 @@ int main(int argc, char ** argv) {

Dispatcher * dispatcher = new Dispatcher( engine );

double tm = get_time();
double tm = ltp::utility::get_time();
list<thread *> thread_list;
for (int i = 0; i < num_threads; ++ i) {
thread * t = new thread( multithreaded_postag, (void *)dispatcher );
Expand All @@ -135,7 +128,7 @@ int main(int argc, char ** argv) {
delete t;
}

tm = get_time() - tm;
tm = ltp::utility::get_time() - tm;
std::cerr << "TRACE: consume "
<< tm
<< " seconds."
Expand Down
15 changes: 4 additions & 11 deletions test/par_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
#include <ctime>
#include <cstring>
#include <string>
#include <sys/time.h>
#include <sys/types.h>
#include "ltp/parser_dll.h"

double get_time(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + (tv.tv_usec / 1000000.0);
}
#include "time.hpp"
#include "parser_dll.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
Expand All @@ -32,7 +25,7 @@ int main(int argc, char * argv[]) {
std::vector<std::string> deprels;

std::cerr << "TRACE: Model is loaded" << std::endl;
double tm = get_time();
double tm = ltp::utility::get_time();

while (std::getline(std::cin, line, '\n')) {
if (line.size() == 0) { continue; }
Expand All @@ -58,7 +51,7 @@ int main(int argc, char * argv[]) {

parser_release_parser(engine);

tm = get_time() - tm;
tm = ltp::utility::get_time() - tm;
std::cerr << "TRACE: par-tm-consume "
<< tm
<< " seconds."
Expand Down
13 changes: 3 additions & 10 deletions test/pos_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@
#include <ctime>
#include <cstring>
#include <string>
#include <sys/time.h>
#include <sys/types.h>
#include "time.hpp"
#include "postag_dll.h"

double get_time(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + (tv.tv_usec / 1000000.0);
}

int main(int argc, char * argv[]) {
if (argc < 2 || (0 == strcmp(argv[1], "-h"))) {
std::cerr << "Example: ./pos_cmdline [model path]" << std::endl;
Expand All @@ -48,7 +41,7 @@ int main(int argc, char * argv[]) {
std::vector<std::string> postags;

std::cerr << "TRACE: Model is loaded" << std::endl;
double tm = get_time();
double tm = ltp::utility::get_time();

while (std::getline(std::cin, line, '\n')) {
std::stringstream S(line);
Expand All @@ -71,7 +64,7 @@ int main(int argc, char * argv[]) {

postagger_release_postagger(engine);

tm = get_time() - tm;
tm = ltp::utility::get_time() - tm;
std::cerr << "TRACE: pos-tm-consume "
<< tm
<< " seconds."
Expand Down

0 comments on commit bb6d225

Please sign in to comment.