mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
rename
This commit is contained in:
parent
49b0b7ddde
commit
470bded7de
@ -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)
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <memory.h>
|
||||
#include <str_functs.hpp>
|
||||
#include <logger.hpp>
|
||||
#include "Limonp/str_functs.hpp"
|
||||
#include "Limonp/logger.hpp"
|
||||
#include "globals.h"
|
||||
#include "TransCode.hpp"
|
||||
#include "ISegment.hpp"
|
||||
|
@ -78,6 +78,18 @@ namespace Limonp
|
||||
}
|
||||
return true;
|
||||
}
|
||||
uint insert(const char* tb_name, const char* keys, const vector<string>& 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))
|
@ -19,7 +19,10 @@
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <sys/types.h>
|
||||
#include <map_functs.hpp>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include "std_outbound.hpp"
|
||||
#include "map_functs.hpp"
|
||||
|
||||
#define print(x) cout<<(x)<<endl
|
||||
|
||||
@ -52,6 +55,7 @@ namespace Limonp
|
||||
{
|
||||
int size = 256;
|
||||
va_list ap;
|
||||
res.clear();
|
||||
while (1) {
|
||||
res.resize(size);
|
||||
va_start(ap, fmt);
|
||||
@ -116,128 +120,7 @@ namespace Limonp
|
||||
return res;
|
||||
}
|
||||
|
||||
template<class T1, class T2>
|
||||
ostream& operator << (ostream& os, const pair<T1, T2>& pr)
|
||||
{
|
||||
os << pr.first << ":" << pr.second ;
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ostream& operator << (ostream& os, const vector<T>& vec)
|
||||
{
|
||||
if(vec.empty())
|
||||
{
|
||||
return os << "[]";
|
||||
}
|
||||
os<<"[\""<<vec[0];
|
||||
for(uint i = 1; i < vec.size(); i++)
|
||||
{
|
||||
os<<"\", \""<<vec[i];
|
||||
}
|
||||
os<<"\"]";
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
string& operator << (string& str, const T& obj)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << obj; // call ostream& operator << (ostream& os,
|
||||
return str = ss.str();
|
||||
}
|
||||
|
||||
template<class T1, class T2>
|
||||
ostream& operator << (ostream& os, const map<T1, T2>& mp)
|
||||
{
|
||||
if(mp.empty())
|
||||
{
|
||||
os<<"{}";
|
||||
return os;
|
||||
}
|
||||
os<<'{';
|
||||
typename map<T1, T2>::const_iterator it = mp.begin();
|
||||
os<<*it;
|
||||
it++;
|
||||
while(it != mp.end())
|
||||
{
|
||||
os<<", "<<*it;
|
||||
it++;
|
||||
}
|
||||
os<<'}';
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
//template<class T1, class T2>
|
||||
// string& operator << (string& str, const map<T1, T2>& mp)
|
||||
// {
|
||||
// if(mp.empty())
|
||||
// {
|
||||
// str = "{}";
|
||||
// return str;
|
||||
// }
|
||||
// stringstream ss;
|
||||
// ss<<'{';
|
||||
// typename map<T1, T2>::const_iterator it = mp.begin();
|
||||
// ss<<*it;
|
||||
// it++;
|
||||
// while(it != mp.end())
|
||||
// {
|
||||
// ss<<", "<<*it;
|
||||
// it++;
|
||||
// }
|
||||
// ss<<'}';
|
||||
// str = ss.str();
|
||||
// return str;
|
||||
// }
|
||||
|
||||
template<class T1, class T2>
|
||||
ostream& operator << (ostream& os, const HashMap<T1, T2>& mp)
|
||||
{
|
||||
if(mp.empty())
|
||||
{
|
||||
return os << "{}";
|
||||
}
|
||||
os<<'{';
|
||||
typename map<T1, T2>::const_iterator it = mp.begin();
|
||||
os<<*it;
|
||||
it++;
|
||||
while(it != mp.end())
|
||||
{
|
||||
os<<", "<<*it++;
|
||||
}
|
||||
return os<<'}';
|
||||
}
|
||||
|
||||
//template<class T>
|
||||
// string& operator << (string& str, const set<T>& st)
|
||||
// {
|
||||
// stringstream ss;
|
||||
// ss << st;
|
||||
// return str = ss.str();
|
||||
// }
|
||||
|
||||
template<class T>
|
||||
ostream& operator << (ostream& os, const set<T>& st)
|
||||
{
|
||||
if(st.empty())
|
||||
{
|
||||
os << "{}";
|
||||
return os;
|
||||
}
|
||||
os<<'{';
|
||||
typename set<T>::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<string>& res, const string& pattern)
|
||||
{
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <logger.hpp>
|
||||
#include "Limonp/logger.hpp"
|
||||
#include "Trie.h"
|
||||
#include "globals.h"
|
||||
#include "ISegment.hpp"
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "MPSegment.h"
|
||||
#include "HMMSegment.h"
|
||||
#include <str_functs.hpp>
|
||||
#include "Limonp/str_functs.hpp"
|
||||
|
||||
namespace CppJieba
|
||||
{
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include "globals.h"
|
||||
#include "ISegment.hpp"
|
||||
#include "ChineseFilter.hpp"
|
||||
#include <str_functs.hpp>
|
||||
#include <logger.hpp>
|
||||
#include "Limonp/str_functs.hpp"
|
||||
#include "Limonp/logger.hpp"
|
||||
|
||||
namespace CppJieba
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
#include "globals.h"
|
||||
#include <str_functs.hpp>
|
||||
#include "Limonp/str_functs.hpp"
|
||||
|
||||
namespace CppJieba
|
||||
{
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include <stdint.h>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <str_functs.hpp>
|
||||
#include <logger.hpp>
|
||||
#include "Limonp/str_functs.hpp"
|
||||
#include "Limonp/logger.hpp"
|
||||
#include "TransCode.hpp"
|
||||
#include "globals.h"
|
||||
#include "structs.h"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <ArgvContext.hpp>
|
||||
#include "Limonp/ArgvContext.hpp"
|
||||
#include "MPSegment.h"
|
||||
#include "HMMSegment.h"
|
||||
#include "MixSegment.h"
|
||||
|
@ -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 $@.$$$$
|
60
test/segment.cpp
Normal file
60
test/segment.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <CppJieba/Limonp/ArgvContext.hpp>
|
||||
#include <CppJieba/MPSegment.h>
|
||||
#include <CppJieba/HMMSegment.h>
|
||||
#include <CppJieba/MixSegment.h>
|
||||
|
||||
using namespace CppJieba;
|
||||
|
||||
void cut(const ISegment * seg, const char * const filePath)
|
||||
{
|
||||
ifstream ifile(filePath);
|
||||
vector<string> res;
|
||||
string line;
|
||||
while(getline(ifile, line))
|
||||
{
|
||||
if(!line.empty())
|
||||
{
|
||||
res.clear();
|
||||
seg->cut(line, res);
|
||||
cout<<join(res.begin(), res.end(),"/")<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
//demo
|
||||
{
|
||||
HMMSegment seg;
|
||||
if(!seg.init("../dicts/jieba.dict.utf8"))
|
||||
{
|
||||
cout<<"seg init failed."<<endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cut(&seg, "testlines.utf8");
|
||||
seg.dispose();
|
||||
}
|
||||
{
|
||||
MixSegment seg;
|
||||
if(!seg.init("../dicts/jieba.dict.utf8", "../dicts/hmm_model.utf8"))
|
||||
{
|
||||
cout<<"seg init failed."<<endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cut(&seg, "testlines.utf8");
|
||||
seg.dispose();
|
||||
}
|
||||
{
|
||||
MPSegment seg;
|
||||
if(!seg.init("../dicts/jieba.dict.utf8"))
|
||||
{
|
||||
cout<<"seg init failed."<<endl;
|
||||
return false;
|
||||
}
|
||||
cut(&seg, "testlines.utf8");
|
||||
seg.dispose();
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
63
test/server.cpp
Normal file
63
test/server.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <ArgvContext.hpp>
|
||||
#include <Daemon.h>
|
||||
#include <ServerFrame.h>
|
||||
#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<string> 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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user