Skip to content

Commit

Permalink
add test directories and move src/test to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneplus committed Mar 21, 2013
1 parent 8e26576 commit 9d00e5c
Show file tree
Hide file tree
Showing 14 changed files with 56,899 additions and 31,351 deletions.
43 changes: 31 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
PROJECT ("LTP - Language Technology Platform")
cmake_minimum_required (VERSION 2.8.0)
project ("LTP - Language Technology Platform")

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
# project attributes section
# -- config cmake modules path
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
SET(SOURCE ${PROJECT_SOURCE_DIR}/src)
SET(THIRDPARTY ${PROJECT_SOURCE_DIR}/thirdparty)
# -- config output directories
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set (LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
set (INCLUDE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/include)

SET(CONFIGURE_DIR ${PROJECT_SOURCE_DIR}/conf)
SET(DATA_DIR ${PROJECT_SOURCE_DIR}/ltp_data)
# -- config source directories
set (SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
set (THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/thirdparty)

ADD_SUBDIRECTORY(thirdparty)
ADD_SUBDIRECTORY(src)
# -- config resource directories
set (CONFIGURE_DIR ${PROJECT_SOURCE_DIR}/conf)
set (DATA_DIR ${PROJECT_SOURCE_DIR}/ltp_data)

# --- GENERATE CONFIGURE FILE AUTOMATICALLY ---
CONFIGURE_FILE(
# compiling section
# -- compile shipped libraries
add_subdirectory (thirdparty)

# -- compile source code
add_subdirectory (src)

# testing section
# -- generate configure file for ltp_test
configure_file (
${CONFIGURE_DIR}/ltp_all_modules.conf.in
${EXECUTABLE_OUTPUT_PATH}/ltp_all_modules.conf)

# enable test
enable_testing()

# compile testing
add_subdirectory (test)
38 changes: 19 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
SET(util_dir ${SOURCE}/__util/)
SET(xml4nlp_dir ${SOURCE}/__xml4nlp/)
SET(crfwordseg_dir ${SOURCE}/_crfwordsegment/)
SET(svmtagger_dir ${SOURCE}/_svmtagger/)
SET(splitsnt_dir ${SOURCE}/_split_sentence/)
SET(ner_dir ${SOURCE}/_ner/)
SET(gparser_dir ${SOURCE}/_gparser)
SET(srl_dir ${SOURCE}/_srl/)
SET(ltp_dll_dir ${SOURCE}/__ltp_dll/)
set (util_DIR ${SOURCE_DIR}/__util/)
set (xml4nlp_DIR ${SOURCE_DIR}/__xml4nlp/)
set (crfwordseg_DIR ${SOURCE_DIR}/_crfwordsegment/)
set (svmtagger_DIR ${SOURCE_DIR}/_svmtagger/)
set (splitsnt_DIR ${SOURCE_DIR}/_split_sentence/)
set (ner_DIR ${SOURCE_DIR}/_ner/)
set (gparser_DIR ${SOURCE_DIR}/_gparser)
set (srl_DIR ${SOURCE_DIR}/_srl/)
set (ltp_dll_DIR ${SOURCE_DIR}/__ltp_dll/)

ADD_SUBDIRECTORY("__util")
ADD_SUBDIRECTORY("__xml4nlp")
ADD_SUBDIRECTORY("_split_sentence")
ADD_SUBDIRECTORY("_crfwordsegment")
ADD_SUBDIRECTORY("_svmtagger")
ADD_SUBDIRECTORY("_ner")
ADD_SUBDIRECTORY("_gparser")
ADD_SUBDIRECTORY("_srl")
add_subdirectory ("__util")
add_subdirectory ("__xml4nlp")
add_subdirectory ("_split_sentence")
add_subdirectory ("_crfwordsegment")
add_subdirectory ("_svmtagger")
add_subdirectory ("_ner")
add_subdirectory ("_gparser")
add_subdirectory ("_srl")

ADD_SUBDIRECTORY("__ltp_dll")
add_subdirectory ("__ltp_dll")

ADD_SUBDIRECTORY("test")
#add_subdirectory ("test")
24 changes: 12 additions & 12 deletions src/__ltp_dll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
INCLUDE_DIRECTORIES(./
${xml4nlp_dir}
${util_dir}
${crfwordseg_dir}
${svmtagger_dir}
${gparser_dir}
${ner_dir}
${srl_dir}
${splitsnt_dir}
${THIRDPARTY}/tinyxml)
include_directories (./
${xml4nlp_DIR}
${util_DIR}
${crfwordseg_DIR}
${svmtagger_DIR}
${gparser_DIR}
${ner_DIR}
${srl_DIR}
${splitsnt_DIR}
${THIRDPARTY_DIR}/tinyxml)

SET(ltp_source
SET(ltp_SRC
Ltp.cpp
Ltp.h
LTPOption.h
LTPResource.cpp
LTPResource.h)

ADD_LIBRARY(ltp ${ltp_source})
ADD_LIBRARY(ltp ${ltp_SRC})
4 changes: 2 additions & 2 deletions src/__xml4nlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INCLUDE_DIRECTORIES(./
${util_dir}
${THIRDPARTY}/tinyxml)
${util_DIR}
${THIRDPARTY_DIR}/tinyxml)

SET(xml4nlp_source
Xml4nlp.h
Expand Down
21 changes: 12 additions & 9 deletions src/_crfwordsegment/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
MESSAGE(STATUS ${THIRDPARTY})

SET(CMAKE_CXX_FLAGS "-DHAVE_CONFIG_H")
SET(crfwordseg_source
set (CMAKE_CXX_FLAGS "-DHAVE_CONFIG_H")
set (crfwordseg_source
CRFSegEngine.cpp
CRFSegEngine.h
CRFWS.cpp
Expand All @@ -16,11 +14,16 @@ SET(crfwordseg_source
SegEngine.cpp
SegEngine.h)

INCLUDE_DIRECTORIES(
include_directories (
./
${THIRDPARTY}/crfpp/
${util_dir}/)
${THIRDPARTY_DIR}/crfpp/
${util_DIR}/)

add_library (crfwordseg ${crfwordseg_source})

ADD_LIBRARY(crfwordseg ${crfwordseg_source})
target_link_libraries (crfwordseg util crfpp)

TARGET_LINK_LIBRARIES(crfwordseg util crfpp)
configure_file (
CRFWS_DLL.h
${INCLUDE_OUTPUT_PATH}/ltp/CRFWS_DLL.h
@ONLY)
12 changes: 8 additions & 4 deletions src/_gparser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INCLUDE_DIRECTORIES(./
${util_dir})
include_directories (./
${util_DIR})

SET(gparser_source
set (gparser_SRC
Alphabet.cpp
Alphabet.h
CONLLReader.cpp
Expand Down Expand Up @@ -42,6 +42,10 @@ SET(gparser_source
ParserOptions.cpp
ParserOptions.h)

ADD_LIBRARY(gparser ${gparser_source})
add_library (gparser ${gparser_SRC})

configure_file (
gparser_dll.h
${INCLUDE_OUTPUT_PATH}/ltp/gparser_dll.h)

TARGET_LINK_LIBRARIES(gparser util)
14 changes: 9 additions & 5 deletions src/_ner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
INCLUDE_DIRECTORIES(
include_directories (
./
${THIRDPARTY}/boost/include
${THIRDPARTY}/maxent)
${THIRDPARTY_DIR}/boost/include
${THIRDPARTY_DIR}/maxent)

SET(ner_source
set (ner_SRC
Dictionary.cpp
Dictionary.h
InitDic.cpp
Expand All @@ -22,4 +22,8 @@ SET(ner_source
RuleNErecog.cpp
RuleNErecog.h)

ADD_LIBRARY(ner ${ner_source})
add_library (ner ${ner_SRC})

configure_file (
NER_DLL.h
${INCLUDE_OUTPUT_PATH}/ltp/NER_DLL.h)
16 changes: 12 additions & 4 deletions src/_srl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
INCLUDE_DIRECTORIES(. ${util_dir} ${THIRDPARTY}/boost/include ${THIRDPARTY}/maxent)
include_directories (
.
${util_DIR}
${THIRDPARTY_DIR}/boost/include
${THIRDPARTY_DIR}/maxent)

SET(srl_source
set (srl_SRC
Configuration.cpp
Configuration.h
ConstVar.h
Expand All @@ -25,6 +29,10 @@ SET(srl_source
SRL_DLL_x.cpp
tree.hh)

ADD_LIBRARY(srl ${srl_source})
add_library (srl ${srl_SRC})

TARGET_LINK_LIBRARIES(srl util maxent)
target_link_libraries (srl util maxent)

configure_file (
SRL_DLL.h
${INCLUDE_OUTPUT_PATH}/ltp/SRL_DLL.h)
12 changes: 9 additions & 3 deletions src/_svmtagger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
INCLUDE_DIRECTORIES(./ ${util_dir} ${THIRDPARTY}/boost/include)
include_directories (./
${util_DIR}
${THIRDPARTY_DIR}/boost/include)

SET(postagger_source
set (postagger_SRC
common.cpp
common.h
dict.cpp
Expand All @@ -25,4 +27,8 @@ SET(postagger_source
weight.cpp
weight.h)

ADD_LIBRARY(postagger ${postagger_source})
add_library (postagger ${postagger_SRC})

configure_file (
svmtagger_dll.h
${INCLUDE_OUTPUT_PATH}/ltp/svmtagger_dll.h)
59 changes: 59 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
include_directories (./
${SOURCE_DIR}/__util
${SOURCE_DIR}/__xml4nlp
${SOURCE_DIR}/_split_sentence
${SOURCE_DIR}/_crfwordsegment
${SOURCE_DIR}/_svmtagger
${SOURCE_DIR}/_ner
${SOURCE_DIR}/_gparser
${SOURCE_DIR}/_srl
${SOURCE_DIR}/__ltp_dll
${THIRDPARTY_DIR}/crfpp
${THIRDPARTY_DIR}/maxent
${THIRDPARTY_DIR}/tinyxml)

set (ltp_test_SRC ltp_test.cpp)
set (ltp_test_xml_SRC ltp_test_xml.cpp)

add_executable (ltp_test ${ltp_test_SRC})
add_executable (ltp_test_xml ${ltp_test_xml_SRC})

link_directories ( ${LIBRARY_OUTPUT_PATH} )

target_link_libraries (ltp_test
maxent
crfpp
util
ltp
splitsnt
crfwordseg
postagger
gparser
ner
srl
xml4nlp
dl
pthread
boost_regex)

target_link_libraries (ltp_test_xml
maxent
crfpp
util
ltp
splitsnt
crfwordseg
postagger
gparser
ner
srl
xml4nlp
dl
pthread
boost_regex)

#add_test (NAME ltp_test
# COMMAND "${CMAKE_COMMAND}"
# -DTEST_PROG=${EXECUTABLE_TEST_OUTPUT}
# -P ${CMAKE_MODULE_PATH}/LtpDiff.cmake)

71 changes: 71 additions & 0 deletions test/ltp_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Defines the entry point for the console application.
//

#include <stdlib.h>
#include <iostream>

#include "Xml4nlp.h"
#include "Ltp.h"

using namespace std;

static XML4NLP xml4nlp;
static LTP ltp(xml4nlp);

int main(int argc, char *argv[])
{
if (argc != 3)
{
cerr << "Usage: ./ltp_test <type> <test_file>" << endl;
exit(1);
}

cout << "Begin ..." << endl;
string sentence;
string type(argv[1]);
ifstream in(argv[2]);
ofstream log_file("test.log");

if (!in.is_open())
{
cerr << "Cann't open file!" << endl;
exit(1);
}

while(in >> sentence){
cout << "Input sentence is: " << sentence << endl;

xml4nlp.CreateDOMFromString(sentence);
if(type == "ws"){
ltp.crfWordSeg();
int wordNum = xml4nlp.CountWordInDocument();
for (int i = 0; i < wordNum; ++i)
{
const char* word = xml4nlp.GetWord(i);
if (word != NULL)
{
log_file << word << " ";
}
}
} else if(type == "pos"){
ltp.postag();
} else if(type == "ner"){
ltp.ner();
} else if(type == "dp"){
ltp.gparser();
} else if(type == "srl"){
ltp.srl();
} else {
ltp.srl();
}

string result;
xml4nlp.SaveDOM(result);

cout << "Result is: " << result << endl;
xml4nlp.ClearDOM();
}

return 0;
}

Loading

0 comments on commit 9d00e5c

Please sign in to comment.