mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add debug and release in makefile
This commit is contained in:
parent
b2775888d1
commit
7e1186a4ba
2
demo.cpp
2
demo.cpp
@ -23,7 +23,7 @@ int main(int argc, char ** argv)
|
|||||||
cerr<<"1"<<endl;
|
cerr<<"1"<<endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ifstream ifile("dress.gbk");
|
ifstream ifile(argv[1]);
|
||||||
vector<string> res;
|
vector<string> res;
|
||||||
string line;
|
string line;
|
||||||
while(getline(ifile, line))
|
while(getline(ifile, line))
|
||||||
|
@ -136,10 +136,14 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
|
|
||||||
_sortWLIDF(wordInfos);
|
_sortWLIDF(wordInfos);
|
||||||
//LogDebug(string_format("calc weight & sorted:%s",joinWordInfos(wordInfos).c_str()));
|
#ifdef DEBUG
|
||||||
|
LogDebug(string_format("calc weight & sorted:%s",joinWordInfos(wordInfos).c_str()));
|
||||||
|
#endif
|
||||||
|
|
||||||
_prioritizeSubWords(wordInfos);
|
_prioritizeSubWords(wordInfos);
|
||||||
//LogDebug(string_format("_prioritizeSubWords res:%s", joinWordInfos(wordInfos).c_str()));
|
#ifdef DEBUG
|
||||||
|
LogDebug(string_format("_prioritizeSubWords res:%s", joinWordInfos(wordInfos).c_str()));
|
||||||
|
#endif
|
||||||
//extract TopN
|
//extract TopN
|
||||||
for(uint i = 0; i < topN && i < wordInfos.size(); i++)
|
for(uint i = 0; i < topN && i < wordInfos.size(); i++)
|
||||||
{
|
{
|
||||||
@ -150,7 +154,9 @@ namespace CppJieba
|
|||||||
|
|
||||||
bool KeyWordExt::extract(const string& title, vector<string>& keywords, uint topN)
|
bool KeyWordExt::extract(const string& title, vector<string>& keywords, uint topN)
|
||||||
{
|
{
|
||||||
//LogDebug(string_format("title:[%s]",title.c_str()));
|
#ifdef DEBUG
|
||||||
|
LogDebug(string_format("title:[%s]",title.c_str()));
|
||||||
|
#endif
|
||||||
|
|
||||||
bool retFlag;
|
bool retFlag;
|
||||||
vector<string> words;
|
vector<string> words;
|
||||||
@ -160,7 +166,9 @@ namespace CppJieba
|
|||||||
LogError(string_format("cutDAG(%s) failed.", title.c_str()));
|
LogError(string_format("cutDAG(%s) failed.", title.c_str()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//LogDebug(string_format("cutDAG result:[%s]", joinStr(words, ",").c_str()));
|
#ifdef DEBUG
|
||||||
|
LogDebug(string_format("cutDAG result:[%s]", joinStr(words, ",").c_str()));
|
||||||
|
#endif
|
||||||
|
|
||||||
retFlag = _filter(words);
|
retFlag = _filter(words);
|
||||||
if(!retFlag)
|
if(!retFlag)
|
||||||
@ -168,7 +176,9 @@ namespace CppJieba
|
|||||||
LogError("_filter failed.");
|
LogError("_filter failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//LogDebug(string_format("_filter res:[%s]", joinStr(words, ",").c_str()));
|
#ifdef DEBUG
|
||||||
|
LogDebug(string_format("_filter res:[%s]", joinStr(words, ",").c_str()));
|
||||||
|
#endif
|
||||||
|
|
||||||
retFlag = _extractTopN(words, keywords, topN);
|
retFlag = _extractTopN(words, keywords, topN);
|
||||||
if(!retFlag)
|
if(!retFlag)
|
||||||
@ -178,7 +188,9 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
//LogDebug("_extractTopN finished.");
|
//LogDebug("_extractTopN finished.");
|
||||||
|
|
||||||
//LogDebug(string_format("ext res:[%s]", joinStr(keywords, ",").c_str()));
|
#ifdef DEBUG
|
||||||
|
LogDebug(string_format("ext res:[%s]", joinStr(keywords, ",").c_str()));
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +309,6 @@ namespace CppJieba
|
|||||||
{
|
{
|
||||||
if(subs.end() != subs.find(*it))
|
if(subs.end() != subs.find(*it))
|
||||||
{
|
{
|
||||||
//LogDebug(string_format("_filterSubstr filter [%s].", it->c_str()));
|
|
||||||
it = strs.erase(it);
|
it = strs.erase(it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
52
src/Makefile
52
src/Makefile
@ -1,20 +1,32 @@
|
|||||||
CC = g++
|
|
||||||
CCOPT = -Wall -c
|
CXX := g++
|
||||||
LINK = g++
|
LD := g++
|
||||||
LINKOPT =
|
AR := ar rc
|
||||||
PACKA = ar
|
|
||||||
PACKAOPT = rc
|
INCS := -I. -I./cppcommon
|
||||||
DOLINK = $(LINK) $(LINKOPT) -o $@ $^
|
|
||||||
DOPACK = $(PACKA) $(PACKAOPT) $@
|
DEBUG_CXXFLAGS := -g -DDEBUG
|
||||||
|
RELEASE_CXXFLAGS := -Wall
|
||||||
|
|
||||||
|
ifeq (YES, ${DEBUG})
|
||||||
|
CXXFLAGS := ${DEBUG_CXXFLAGS}
|
||||||
|
LDFLAGS := ${DEBUG_LDFLAGS}
|
||||||
|
else
|
||||||
|
CXXFLAGS := ${RELEASE_CXXFLAGS}
|
||||||
|
LDFLAGS := ${RELEASE_LDFLAGS}
|
||||||
|
endif
|
||||||
|
|
||||||
|
DOLINK := $(LD) $(LDFLAGS) -o $@ $^
|
||||||
|
DOPACK := $(AR)
|
||||||
SOURCES := $(wildcard *.cpp)
|
SOURCES := $(wildcard *.cpp)
|
||||||
OBJS := $(patsubst %.cpp,%.o,$(SOURCES))
|
OBJS := $(patsubst %.cpp,%.o,$(SOURCES))
|
||||||
|
|
||||||
CMDIR = ./cppcommon
|
CMDIR := ./cppcommon
|
||||||
CMLIB = $(CMDIR)/libcm.a
|
CMLIB := $(CMDIR)/libcm.a
|
||||||
|
|
||||||
TMPDIR = ./cppjiebatmp
|
TMPDIR := ./cppjiebatmp
|
||||||
|
|
||||||
LIBA = libcppjieba.a
|
LIBA := libcppjieba.a
|
||||||
|
|
||||||
# remove the objs after compilation
|
# remove the objs after compilation
|
||||||
.INTERMEDIATE:
|
.INTERMEDIATE:
|
||||||
@ -25,11 +37,11 @@ all: $(LIBA)
|
|||||||
# This is a suffix rule
|
# This is a suffix rule
|
||||||
#.c.o:
|
#.c.o:
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
$(CC) $(CCOPT) $<
|
$(CXX) -c $(CXXFLAGS) $<
|
||||||
|
|
||||||
$(LIBA): $(TMPDIR) $(OBJS) $(CMLIB)
|
${LIBA}: $(TMPDIR) $(OBJS) $(CMLIB)
|
||||||
cp $(CMLIB) $(TMPDIR) && cd $(TMPDIR) && ar x `basename $(CMLIB)`
|
cp $(CMLIB) $(TMPDIR) && cd $(TMPDIR) && ar x `basename $(CMLIB)`
|
||||||
$(DOPACK) $(OBJS) $(TMPDIR)/*.o
|
$(DOPACK) $@ $(OBJS) $(TMPDIR)/*.o
|
||||||
rm -rf $(TMPDIR)
|
rm -rf $(TMPDIR)
|
||||||
|
|
||||||
$(TMPDIR):
|
$(TMPDIR):
|
||||||
@ -40,16 +52,16 @@ $(CMLIB):
|
|||||||
|
|
||||||
#unit test
|
#unit test
|
||||||
Trie.ut: Trie.cpp Trie.h globals.h TransCode.cpp TransCode.h $(CMLIB)
|
Trie.ut: Trie.cpp Trie.h globals.h TransCode.cpp TransCode.h $(CMLIB)
|
||||||
$(CC) -o $@ Trie.cpp TransCode.cpp -DTRIE_UT $(CMLIB)
|
$(CXX) -o $@ Trie.cpp TransCode.cpp -DTRIE_UT $(CMLIB)
|
||||||
|
|
||||||
Segment.ut: Segment.cpp Trie.cpp Segment.h Trie.h globals.h $(CMLIB)
|
Segment.ut: Segment.cpp Trie.cpp Segment.h Trie.h globals.h $(CMLIB)
|
||||||
$(CC) -o $@ Segment.cpp Trie.cpp TransCode.cpp -DSEGMENT_UT $(CMLIB)
|
$(CXX) -o $@ Segment.cpp Trie.cpp TransCode.cpp -DSEGMENT_UT $(CMLIB)
|
||||||
|
|
||||||
KeyWordExt.ut: KeyWordExt.cpp KeyWordExt.h Segment.h Trie.h globals.h TransCode.cpp TransCode.h $(CMLIB)
|
KeyWordExt.ut: KeyWordExt.cpp KeyWordExt.h Segment.h Trie.h globals.h TransCode.cpp TransCode.h $(CMLIB)
|
||||||
$(CC) -o $@ KeyWordExt.cpp Segment.cpp Trie.cpp TransCode.cpp -DKEYWORDEXT_UT $(CMLIB)
|
$(CXX) -o $@ KeyWordExt.cpp Segment.cpp Trie.cpp TransCode.cpp -DKEYWORDEXT_UT $(CMLIB)
|
||||||
|
|
||||||
TransCode.ut: TransCode.cpp TransCode.h globals.h $(CMLIB)
|
TransCode.ut: TransCode.cpp TransCode.h globals.h $(CMLIB)
|
||||||
$(CC) -o $@ TransCode.cpp -DCPPJIEBA_TRANSCODE_UT $(CMLIB)
|
$(CXX) -o $@ TransCode.cpp -DCPPJIEBA_TRANSCODE_UT $(CMLIB)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.d *.ut $(LIBA)
|
rm -f *.o *.d *.ut $(LIBA)
|
||||||
@ -59,6 +71,6 @@ clean:
|
|||||||
sinclude $(SOURCES:.cpp=.d)
|
sinclude $(SOURCES:.cpp=.d)
|
||||||
%.d:%.cpp
|
%.d:%.cpp
|
||||||
@set -e; rm -f $@; \
|
@set -e; rm -f $@; \
|
||||||
$(CC) -MM $< > $@.$$$$; \
|
$(CXX) -MM $< > $@.$$$$; \
|
||||||
sed 's,\($*\).o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
sed 's,\($*\).o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
||||||
rm -f $@.$$$$
|
rm -f $@.$$$$
|
||||||
|
Loading…
x
Reference in New Issue
Block a user