Skip to content

Commit

Permalink
fix windows bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneplus committed Jul 21, 2013
1 parent 97cdc0f commit 9e285f0
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 98 deletions.
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
##############################################################
# CMake Project Wrapper Makefile #
##############################################################

SHELL := /bin/bash
RM := rm -rf

all: ./build/Makefile
@ $(MAKE) -C build

./build/Makefile:
@ (cd build >/dev/null 2>&1 && cmake ..)

distclean:
@- (cd build >/dev/null 2>&1 && cmake .. >/dev/null 2>&1)
@- $(MAKE) --silent -C build clean || true
@- $(RM) ./build/Makefile
@- $(RM) ./build/src
@- $(RM) ./build/test
@- $(RM) ./build/CMake*
@- $(RM) ./build/cmake.*
@- $(RM) ./build/*.cmake
@- $(RM) ./build/*.txt
@- $(RM) ./docs/*.html
@- $(RM) ./docs/*.css
@- $(RM) ./docs/*.png
@- $(RM) ./docs/*.jpg
@- $(RM) ./docs/*.gif
@- $(RM) ./docs/*.tiff
@- $(RM) ./docs/*.php
@- $(RM) ./docs/search
@- $(RM) ./docs/installdox


ifeq ($(findstring distclean,$(MAKECMDGOALS)),)

$(MAKECMDGOALS): ./build/Makefile
@ $(MAKE) -C build $(MAKECMDGOALS)

endif
1 change: 1 addition & 0 deletions cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ MACRO (CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
CHECK_INCLUDE_FILES ("${USE_INCLUDES};${FILE}" ${VARIABLE})
IF (${VARIABLE})
SET (USE_INCLUDES ${USE_INCLUDES} ${FILE})
ADD_DEFINITIONS( -D${VARIABLE} )
ENDIF (${VARIABLE})
ENDMACRO (CHECK_INCLUDE_FILE_CONCAT)

98 changes: 9 additions & 89 deletions src/__ltp_dll/Ltp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const unsigned int LTP::DO_PARSER = 1 << 4;
const unsigned int LTP::DO_SRL = 1 << 6;

// create a platform
LTP::LTP(XML4NLP &xml4nlp) :
m_ltpResource(),
m_ltpOption(),
LTP::LTP(XML4NLP &xml4nlp) :
m_ltpResource(),
m_ltpOption(),
m_xml4nlp(xml4nlp) {
ReadConfFile();
}
Expand Down Expand Up @@ -134,7 +134,7 @@ int LTP::ReadConfFile(const char * config_file) {
return 0;
}

// If you do NOT split sentence explicitly,
// If you do NOT split sentence explicitly,
// this will be called according to dependencies among modules
int LTP::splitSentence_dummy() {
if ( m_xml4nlp.QueryNote(NOTE_SENT) ) {
Expand All @@ -155,7 +155,7 @@ int LTP::splitSentence_dummy() {
m_xml4nlp.GetParagraph(i, para);
if (0 == SplitSentence( para, vecSentences )) {
ERROR_LOG("in LTP::splitsent, failed to split sentence");
return -1;
return -1;
}
// dummy
// vecSentences.push_back(para);
Expand All @@ -175,7 +175,7 @@ int LTP::wordseg() {
return 0;
}

//
//
if (0 != splitSentence_dummy()) {
ERROR_LOG("in LTP::wordseg, failed to perform split sentence preprocess.");
return -1;
Expand Down Expand Up @@ -261,7 +261,7 @@ int LTP::postag() {
}

if (m_xml4nlp.SetPOSsToSentence(vecPOS, i) != 0) {
ERROR_LOG("in LTP::postag, failed to write postag result to xml");
ERROR_LOG("in LTP::postag, failed to write postag result to xml");
return -1;
}
}
Expand Down Expand Up @@ -295,8 +295,8 @@ int LTP::ner() {
return -1;
}

NER_SetOption(m_ltpOption.neOpt.isEntity,
m_ltpOption.neOpt.isTime,
NER_SetOption(m_ltpOption.neOpt.isEntity,
m_ltpOption.neOpt.isTime,
m_ltpOption.neOpt.isNum);

int stnsNum = m_xml4nlp.CountSentenceInDocument();
Expand Down Expand Up @@ -469,83 +469,3 @@ int LTP::srl() {
return 0;
}

#ifdef _WIN32

int LTP::main2(const char *cszFileName, const char *cszSaveFileName, unsigned int flag)
{
if (flag & DO_XML)
{
if (CreateDOMFromXml(cszFileName) != 0) return -11;
}
else
{
if (CreateDOMFromTxt(cszFileName) != 0) return -12;
}

if (flag & DO_SPLITSENTENCE) {
if (splitSentence() != 0) return -1;
}
/*
if (flag & DO_IRLAS) {
if (postag() != 0) return -2;
}
*/
if (flag & DO_NER) {
if (ner() != 0) return -3;
}
/*
if (flag & DO_WSD) {
if (wsd() != 0) return -4;
}
*/
if (flag & DO_PARSER) {
if (gparser() != 0) return -5;
}
if (flag & DO_SRL) {
if (srl() != 0) return -6;
}
if (SaveDOM(cszSaveFileName) != 0) return -10;

return 0;
}

// Need to split sentence explicitly.
int LTP::splitSentence() {
if ( m_xml4nlp.QueryNote(NOTE_SENT) ) return 0;

int paraNum = m_xml4nlp.CountParagraphInDocument();

if (paraNum == 0)
{
cerr << "There is no paragraph in doc," << endl
<< "you may have loaded a blank file or have not loaded a file yet" << endl;
return -1;
}

for (int i = 0; i < paraNum; ++i)
{
vector<string> vecSentences;
string para;
m_xml4nlp.GetParagraph(i, para);
if (0 == SplitSentence( para, vecSentences )) return -1; // func SplitSentence's return val is vecSentence.size()
//vecSentences.push_back(para);
if (0 != m_xml4nlp.SetSentencesToParagraph(vecSentences, i)) return -1;
}

m_xml4nlp.SetNote(NOTE_SENT);
return 0;
}

void SplitWordPOS(const vector<string> &vecWordPOS, vector<string> &vecWord,
vector<string> &vecPOS)
{
vector< pair<string, string> > vecPair;
convert_to_pair(vecWordPOS, vecPair);
for (int i=0; i<vecPair.size(); ++i)
{
vecWord.push_back(vecPair[i].first);
vecPOS.push_back(vecPair[i].second);
}
}

#endif
9 changes: 2 additions & 7 deletions src/__ltp_dll/Ltp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ class LTP {
LTP(const char * cfg_file, XML4NLP & xml4nlp);
~LTP();

int CreateDOMFromTxt(const char *cszTxtFileName);
int CreateDOMFromTxt(const char *cszTxtFileName);
int CreateDOMFromXml(const char *cszXmlFileName);
int SaveDOM(const char *cszSaveFileName);

#ifdef _WIN32
int main2(const char *cszFileName, const char *cszSaveFileName, unsigned int flag);
int splitSentence();
#endif
int SaveDOM(const char *cszSaveFileName);

int wordseg();
int postag();
Expand Down
3 changes: 2 additions & 1 deletion src/_ner/NBestHMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ NewPath CNBestHMM::InsertPathToTop(PathNode *prePtr,
int state,
int &curPathNum)
{
NewPath returnPath(NULL, NULL);
NewPath returnPath(reinterpret_cast<PathNode *>(NULL),
reinterpret_cast<PathNode *>(NULL));

if(newLast != NULL && curPathNum >= MAX_N && newLast->accuProb < weight)
return returnPath;
Expand Down
3 changes: 3 additions & 0 deletions src/_srl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ configure_file (

link_directories (${LIBRARY_OUTPUT_PATH})

# Training suite is not supported in windows
if (NOT WIN32)
set (SRLExtract_SRC SRLExtract.cpp Corpus.cpp)
add_executable (SRLExtract ${SRLExtract_SRC})
target_link_libraries (SRLExtract srl)
Expand All @@ -53,3 +55,4 @@ set_target_properties (SRLGetInstance
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${TOOLS_DIR}/train/)

endif()
2 changes: 2 additions & 0 deletions src/segmentor/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class Instance {

features.zero();
predicted_features.zero();

return 0;
}
public:
std::vector< std::string > raw_forms;
Expand Down
4 changes: 3 additions & 1 deletion thirdparty/maxent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ set (maxent_exe_SRC
f77_dummy_main.cpp
${GETOPT_FILES})


# Training suite is not supported in windows
if (NOT WIN32)
add_executable (maxent_exe ${maxent_exe_SRC})
set_target_properties (maxent_exe
PROPERTIES
OUTPUT_NAME maxent
RUNTIME_OUTPUT_DIRECTORY ${TOOLS_DIR}/train/)
target_link_libraries (maxent_exe maxent_lib z m)
endif ()

0 comments on commit 9e285f0

Please sign in to comment.