From 470bded7de87e5c1977dd244491f98c8bf38d1c5 Mon Sep 17 00:00:00 2001 From: wyy Date: Sun, 3 Nov 2013 20:25:30 -0800 Subject: [PATCH] rename --- CMakeLists.txt | 4 +- src/HMMSegment.h | 4 +- src/{husky => Husky}/CMakeLists.txt | 0 src/{husky => Husky}/Daemon.cpp | 0 src/{husky => Husky}/Daemon.h | 0 src/{husky => Husky}/HttpReqInfo.hpp | 0 src/{husky => Husky}/ServerFrame.cpp | 0 src/{husky => Husky}/ServerFrame.h | 0 src/{husky => Husky}/ThreadManager.hpp | 0 src/{husky => Husky}/globals.h | 0 src/{limonp => Limonp}/ArgvContext.hpp | 0 src/{limonp => Limonp}/CMakeLists.txt | 0 src/{limonp => Limonp}/MysqlClient.hpp | 12 +++ src/{limonp => Limonp}/cast_functs.hpp | 0 src/{limonp => Limonp}/config.hpp | 0 src/{limonp => Limonp}/io_functs.hpp | 0 src/{limonp => Limonp}/logger.hpp | 0 src/{limonp => Limonp}/macro_def.hpp | 0 src/{limonp => Limonp}/map_functs.hpp | 0 src/{limonp => Limonp}/str_functs.hpp | 127 +------------------------ src/MPSegment.h | 2 +- src/MixSegment.h | 2 +- src/SegmentBase.hpp | 4 +- src/TransCode.hpp | 2 +- src/Trie.h | 4 +- src/segment.cpp | 2 +- test/Makefile | 54 ----------- test/segment.cpp | 60 ++++++++++++ test/server.cpp | 63 ++++++++++++ 29 files changed, 152 insertions(+), 188 deletions(-) rename src/{husky => Husky}/CMakeLists.txt (100%) rename src/{husky => Husky}/Daemon.cpp (100%) rename src/{husky => Husky}/Daemon.h (100%) rename src/{husky => Husky}/HttpReqInfo.hpp (100%) rename src/{husky => Husky}/ServerFrame.cpp (100%) rename src/{husky => Husky}/ServerFrame.h (100%) rename src/{husky => Husky}/ThreadManager.hpp (100%) rename src/{husky => Husky}/globals.h (100%) rename src/{limonp => Limonp}/ArgvContext.hpp (100%) rename src/{limonp => Limonp}/CMakeLists.txt (100%) rename src/{limonp => Limonp}/MysqlClient.hpp (88%) rename src/{limonp => Limonp}/cast_functs.hpp (100%) rename src/{limonp => Limonp}/config.hpp (100%) rename src/{limonp => Limonp}/io_functs.hpp (100%) rename src/{limonp => Limonp}/logger.hpp (100%) rename src/{limonp => Limonp}/macro_def.hpp (100%) rename src/{limonp => Limonp}/map_functs.hpp (100%) rename src/{limonp => Limonp}/str_functs.hpp (66%) delete mode 100644 test/Makefile create mode 100644 test/segment.cpp create mode 100644 test/server.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 544fe84..ee6b75a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ PROJECT(CPPJIEBA) ADD_SUBDIRECTORY(src) -ADD_SUBDIRECTORY(src/husky) -ADD_SUBDIRECTORY(src/limonp) +ADD_SUBDIRECTORY(src/Husky) +ADD_SUBDIRECTORY(src/Limonp) diff --git a/src/HMMSegment.h b/src/HMMSegment.h index 3691a37..a71081e 100644 --- a/src/HMMSegment.h +++ b/src/HMMSegment.h @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include "Limonp/str_functs.hpp" +#include "Limonp/logger.hpp" #include "globals.h" #include "TransCode.hpp" #include "ISegment.hpp" diff --git a/src/husky/CMakeLists.txt b/src/Husky/CMakeLists.txt similarity index 100% rename from src/husky/CMakeLists.txt rename to src/Husky/CMakeLists.txt diff --git a/src/husky/Daemon.cpp b/src/Husky/Daemon.cpp similarity index 100% rename from src/husky/Daemon.cpp rename to src/Husky/Daemon.cpp diff --git a/src/husky/Daemon.h b/src/Husky/Daemon.h similarity index 100% rename from src/husky/Daemon.h rename to src/Husky/Daemon.h diff --git a/src/husky/HttpReqInfo.hpp b/src/Husky/HttpReqInfo.hpp similarity index 100% rename from src/husky/HttpReqInfo.hpp rename to src/Husky/HttpReqInfo.hpp diff --git a/src/husky/ServerFrame.cpp b/src/Husky/ServerFrame.cpp similarity index 100% rename from src/husky/ServerFrame.cpp rename to src/Husky/ServerFrame.cpp diff --git a/src/husky/ServerFrame.h b/src/Husky/ServerFrame.h similarity index 100% rename from src/husky/ServerFrame.h rename to src/Husky/ServerFrame.h diff --git a/src/husky/ThreadManager.hpp b/src/Husky/ThreadManager.hpp similarity index 100% rename from src/husky/ThreadManager.hpp rename to src/Husky/ThreadManager.hpp diff --git a/src/husky/globals.h b/src/Husky/globals.h similarity index 100% rename from src/husky/globals.h rename to src/Husky/globals.h diff --git a/src/limonp/ArgvContext.hpp b/src/Limonp/ArgvContext.hpp similarity index 100% rename from src/limonp/ArgvContext.hpp rename to src/Limonp/ArgvContext.hpp diff --git a/src/limonp/CMakeLists.txt b/src/Limonp/CMakeLists.txt similarity index 100% rename from src/limonp/CMakeLists.txt rename to src/Limonp/CMakeLists.txt diff --git a/src/limonp/MysqlClient.hpp b/src/Limonp/MysqlClient.hpp similarity index 88% rename from src/limonp/MysqlClient.hpp rename to src/Limonp/MysqlClient.hpp index 0b7da93..8e9d620 100644 --- a/src/limonp/MysqlClient.hpp +++ b/src/Limonp/MysqlClient.hpp @@ -78,6 +78,18 @@ namespace Limonp } return true; } + uint insert(const char* tb_name, const char* keys, const vector& vals) + { + uint retn = 0; + string sql; + for(uint i = 0; i < vals.size(); i ++) + { + sql.clear(); + string_format(sql, "insert into %s (%s) values %s", tb_name, keys, vals[i].c_str()); + retn += executeSql(sql.c_str()); + } + return retn; + } bool select(const char* sql, RowsType& rows) { if(!executeSql(sql)) diff --git a/src/limonp/cast_functs.hpp b/src/Limonp/cast_functs.hpp similarity index 100% rename from src/limonp/cast_functs.hpp rename to src/Limonp/cast_functs.hpp diff --git a/src/limonp/config.hpp b/src/Limonp/config.hpp similarity index 100% rename from src/limonp/config.hpp rename to src/Limonp/config.hpp diff --git a/src/limonp/io_functs.hpp b/src/Limonp/io_functs.hpp similarity index 100% rename from src/limonp/io_functs.hpp rename to src/Limonp/io_functs.hpp diff --git a/src/limonp/logger.hpp b/src/Limonp/logger.hpp similarity index 100% rename from src/limonp/logger.hpp rename to src/Limonp/logger.hpp diff --git a/src/limonp/macro_def.hpp b/src/Limonp/macro_def.hpp similarity index 100% rename from src/limonp/macro_def.hpp rename to src/Limonp/macro_def.hpp diff --git a/src/limonp/map_functs.hpp b/src/Limonp/map_functs.hpp similarity index 100% rename from src/limonp/map_functs.hpp rename to src/Limonp/map_functs.hpp diff --git a/src/limonp/str_functs.hpp b/src/Limonp/str_functs.hpp similarity index 66% rename from src/limonp/str_functs.hpp rename to src/Limonp/str_functs.hpp index e3c87ab..8ad62a3 100644 --- a/src/limonp/str_functs.hpp +++ b/src/Limonp/str_functs.hpp @@ -19,7 +19,10 @@ #include #include #include -#include +#include +#include +#include "std_outbound.hpp" +#include "map_functs.hpp" #define print(x) cout<<(x)< - ostream& operator << (ostream& os, const pair& pr) - { - os << pr.first << ":" << pr.second ; - return os; - } - - template - ostream& operator << (ostream& os, const vector& vec) - { - if(vec.empty()) - { - return os << "[]"; - } - os<<"[\""< - string& operator << (string& str, const T& obj) - { - stringstream ss; - ss << obj; // call ostream& operator << (ostream& os, - return str = ss.str(); - } - - template - ostream& operator << (ostream& os, const map& mp) - { - if(mp.empty()) - { - os<<"{}"; - return os; - } - os<<'{'; - typename map::const_iterator it = mp.begin(); - os<<*it; - it++; - while(it != mp.end()) - { - os<<", "<<*it; - it++; - } - os<<'}'; - return os; - } - //template - // string& operator << (string& str, const map& mp) - // { - // if(mp.empty()) - // { - // str = "{}"; - // return str; - // } - // stringstream ss; - // ss<<'{'; - // typename map::const_iterator it = mp.begin(); - // ss<<*it; - // it++; - // while(it != mp.end()) - // { - // ss<<", "<<*it; - // it++; - // } - // ss<<'}'; - // str = ss.str(); - // return str; - // } - - template - ostream& operator << (ostream& os, const HashMap& mp) - { - if(mp.empty()) - { - return os << "{}"; - } - os<<'{'; - typename map::const_iterator it = mp.begin(); - os<<*it; - it++; - while(it != mp.end()) - { - os<<", "<<*it++; - } - return os<<'}'; - } - - //template - // string& operator << (string& str, const set& st) - // { - // stringstream ss; - // ss << st; - // return str = ss.str(); - // } - - template - ostream& operator << (ostream& os, const set& st) - { - if(st.empty()) - { - os << "{}"; - return os; - } - os<<'{'; - typename set::const_iterator it = st.begin(); - os<<*it; - it++; - while(it != st.end()) - { - os<<", "<<*it; - it++; - } - os<<'}'; - return os; - } - inline bool splitStr(const string& src, vector& res, const string& pattern) { if(src.empty()) diff --git a/src/MPSegment.h b/src/MPSegment.h index 769743d..a3eaae3 100644 --- a/src/MPSegment.h +++ b/src/MPSegment.h @@ -7,7 +7,7 @@ #include #include -#include +#include "Limonp/logger.hpp" #include "Trie.h" #include "globals.h" #include "ISegment.hpp" diff --git a/src/MixSegment.h b/src/MixSegment.h index e85d0e8..079db3f 100644 --- a/src/MixSegment.h +++ b/src/MixSegment.h @@ -3,7 +3,7 @@ #include "MPSegment.h" #include "HMMSegment.h" -#include +#include "Limonp/str_functs.hpp" namespace CppJieba { diff --git a/src/SegmentBase.hpp b/src/SegmentBase.hpp index 17a7130..b082f56 100644 --- a/src/SegmentBase.hpp +++ b/src/SegmentBase.hpp @@ -4,8 +4,8 @@ #include "globals.h" #include "ISegment.hpp" #include "ChineseFilter.hpp" -#include -#include +#include "Limonp/str_functs.hpp" +#include "Limonp/logger.hpp" namespace CppJieba { diff --git a/src/TransCode.hpp b/src/TransCode.hpp index e49c84d..febe3a4 100644 --- a/src/TransCode.hpp +++ b/src/TransCode.hpp @@ -7,7 +7,7 @@ #include "globals.h" -#include +#include "Limonp/str_functs.hpp" namespace CppJieba { diff --git a/src/Trie.h b/src/Trie.h index 25689be..0fa54e1 100644 --- a/src/Trie.h +++ b/src/Trie.h @@ -12,8 +12,8 @@ #include #include #include -#include -#include +#include "Limonp/str_functs.hpp" +#include "Limonp/logger.hpp" #include "TransCode.hpp" #include "globals.h" #include "structs.h" diff --git a/src/segment.cpp b/src/segment.cpp index 406231c..fbd367d 100644 --- a/src/segment.cpp +++ b/src/segment.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include "Limonp/ArgvContext.hpp" #include "MPSegment.h" #include "HMMSegment.h" #include "MixSegment.h" diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index a7d4434..0000000 --- a/test/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -CXX := g++ -LD := g++ -AR := ar rc - -INCS := -I../cppjieba/ - -DEBUG_CXXFLAGS := -g -Wall -DDEBUG -DUT $(INCS) - -CXXFLAGS := ${DEBUG_CXXFLAGS} -LDFLAGS := ${DEBUG_LDFLAGS} - -DOLINK := $(LD) $(LDFLAGS) -DOPACK := $(AR) -SOURCES := $(wildcard *.cpp) -OBJS := $(patsubst %.cpp,%.o,$(SOURCES)) -UTS := $(patsubst %.cpp,%.ut,$(SOURCES)) - -CPPJIEBADIR = ../cppjieba -LIBCPPJIEBA = $(CPPJIEBADIR)/libcppjieba.a - -CPPCOMMONDIR = ../cppcommon -LIBCPPCM = $(CPPCOMMONDIR)/libcm.a - -LIBA := $(LIBCPPJIEBA) $(LIBCPPCM) -# remove the objs after compilation -.PHONY: clean $(LIBA) - -# Main Targets -all: $(UTS) - -# This is a suffix rule -#.c.o: -%.o: %.cpp - $(CXX) -c $(CXXFLAGS) $< -%.ut: %.o $(LIBA) - $(CXX) $(CXXFLAGS) -o $@ $^ - -$(LIBCPPJIEBA): - cd $(CPPJIEBADIR) && $(MAKE) - -$(LIBCPPCM): - cd $(CPPCOMMONDIR) && $(MAKE) - -clean: - rm -f *.o *.ut *.d *.d.* -# cd $(CPPJIEBADIR) && make clean -# cd $(CPPCOMMONDIR) && make clean - -sinclude $(SOURCES:.cpp=.d) -%.d:%.cpp - @set -e; rm -f $@; \ - $(CXX) -MM $< > $@.$$$$; \ - sed 's,\($*\).o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ diff --git a/test/segment.cpp b/test/segment.cpp new file mode 100644 index 0000000..55b1975 --- /dev/null +++ b/test/segment.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include + +using namespace CppJieba; + +void cut(const ISegment * seg, const char * const filePath) +{ + ifstream ifile(filePath); + vector res; + string line; + while(getline(ifile, line)) + { + if(!line.empty()) + { + res.clear(); + seg->cut(line, res); + cout< +#include +#include +#include +#include +#include +#include +#include +#include "MPSegment.h" +#include "HMMSegment.h" +#include "MixSegment.h" + +using namespace Husky; +using namespace CppJieba; + +const char * const DEFAULT_DICTPATH = "../dicts/jieba.dict.utf8"; +const char * const DEFAULT_MODELPATH = "../dicts/hmm_model.utf8"; + +class ServerDemo: public IRequestHandler +{ + public: + ServerDemo(){}; + virtual ~ServerDemo(){}; + virtual bool init(){return _segment.init(DEFAULT_DICTPATH, DEFAULT_MODELPATH);}; + virtual bool dispose(){return _segment.dispose();}; + public: + virtual bool do_GET(const HttpReqInfo& httpReq, string& strSnd) + { + string sentence, tmp; + vector words; + httpReq.GET("key", tmp); + URLDecode(tmp, sentence); + _segment.cut(sentence, words); + strSnd << words; + return true; + } + private: + MixSegment _segment; +}; + +int main(int argc,char* argv[]) +{ + if(argc != 7) + { + printf("usage: %s -n THREAD_NUMBER -p LISTEN_PORT -k start|stop\n",argv[0]); + return -1; + } + ArgvContext arg(argc, argv); + unsigned int port = atoi(arg["-p"].c_str()); + unsigned int threadNum = atoi(arg["-n"].c_str()); + + ServerDemo s; + Daemon daemon(&s); + if(arg["-k"] == "start") + { + return !daemon.Start(port, threadNum); + } + else + { + return !daemon.Stop(); + } +} +