mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
remove src/segment and mv server.cpp into server/server.cpp and modify readme.md
This commit is contained in:
parent
94ae4bdd6f
commit
f8487fd9cf
@ -5,15 +5,15 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
|
|||||||
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||||
set (CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "default install path" FORCE )
|
set (CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "default install path" FORCE )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
ADD_DEFINITIONS(-O3 -Wall -g)
|
ADD_DEFINITIONS(-O3 -Wall -g)
|
||||||
IF (DEFINED ENC)
|
IF (DEFINED ENC)
|
||||||
ADD_DEFINITIONS(-DCPPJIEBA_${ENC})
|
ADD_DEFINITIONS(-DCPPJIEBA_${ENC})
|
||||||
ENDIF()
|
ENDIF()
|
||||||
#ADD_DEFINITIONS(-DNO_FILTER)
|
|
||||||
ADD_SUBDIRECTORY(src)
|
|
||||||
ADD_SUBDIRECTORY(dict)
|
|
||||||
|
|
||||||
IF("${CMAKE_SYSTEM}" MATCHES "Linux")
|
IF("${CMAKE_SYSTEM}" MATCHES "Linux")
|
||||||
|
ADD_SUBDIRECTORY(server)
|
||||||
|
ADD_SUBDIRECTORY(dict)
|
||||||
ADD_SUBDIRECTORY(script)
|
ADD_SUBDIRECTORY(script)
|
||||||
ADD_SUBDIRECTORY(conf)
|
ADD_SUBDIRECTORY(conf)
|
||||||
endif()
|
endif()
|
||||||
|
@ -47,7 +47,7 @@ make test
|
|||||||
|
|
||||||
```
|
```
|
||||||
#Usage: /etc/init.d/cjserver {start|stop|restart|force-reload}
|
#Usage: /etc/init.d/cjserver {start|stop|restart|force-reload}
|
||||||
/etc/init.d/cjserver.start
|
/etc/init.d/cjserver.start >> /dev/null 2>&1
|
||||||
/etc/init.d/cjserver.stop
|
/etc/init.d/cjserver.stop
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1,2 +1 @@
|
|||||||
INSTALL(PROGRAMS cjserver.start cjserver.stop DESTINATION /etc/init.d/)
|
INSTALL(PROGRAMS cjserver.start cjserver.stop DESTINATION /etc/init.d/)
|
||||||
INSTALL(PROGRAMS cjseg.sh DESTINATION bin)
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
if [ $# -lt 1 ]; then
|
|
||||||
echo "usage: $0 <file>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
cjsegment --dictpath /usr/share/CppJieba/dict/jieba.dict.utf8 --modelpath /usr/share/CppJieba/dict/hmm_model.utf8 $1
|
|
@ -1,12 +1,9 @@
|
|||||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src)
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src)
|
||||||
|
|
||||||
ADD_EXECUTABLE(cjsegment segment.cpp)
|
|
||||||
ADD_EXECUTABLE(cjserver server.cpp)
|
ADD_EXECUTABLE(cjserver server.cpp)
|
||||||
TARGET_LINK_LIBRARIES(cjserver pthread)
|
TARGET_LINK_LIBRARIES(cjserver pthread)
|
||||||
|
|
||||||
INSTALL(TARGETS cjsegment RUNTIME DESTINATION bin)
|
|
||||||
INSTALL(TARGETS cjserver RUNTIME DESTINATION bin)
|
INSTALL(TARGETS cjserver RUNTIME DESTINATION bin)
|
||||||
|
|
114
src/segment.cpp
114
src/segment.cpp
@ -1,114 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstdio>
|
|
||||||
#include "Limonp/ArgvContext.hpp"
|
|
||||||
#include "MPSegment.hpp"
|
|
||||||
#include "HMMSegment.hpp"
|
|
||||||
#include "MixSegment.hpp"
|
|
||||||
#include "FullSegment.hpp"
|
|
||||||
#include "QuerySegment.hpp"
|
|
||||||
|
|
||||||
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())
|
|
||||||
{
|
|
||||||
cout << line << endl;
|
|
||||||
res.clear();
|
|
||||||
if(!seg->cut(line, res))
|
|
||||||
{
|
|
||||||
LogError("seg cut failed.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print(join(res.begin(), res.end(), "/"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char ** argv)
|
|
||||||
{
|
|
||||||
if(argc < 2)
|
|
||||||
{
|
|
||||||
cout<<"usage: \n\t"<<argv[0]<<" [options] <filename>\n"
|
|
||||||
<<"options:\n"
|
|
||||||
<<"\t--algorithm\tSupported methods are [cutDAG, cutHMM, cutFull, cutQuery, cutMix] for now. \n\t\t\tIf not specified, the default is cutMix\n"
|
|
||||||
<<"\t--dictpath\tsee example\n"
|
|
||||||
<<"\t--modelpath\tsee example\n"
|
|
||||||
<<"\t--maxlen\tspecify the granularity of cut used in cutQuery. \n\t\t\tIf not specified, the default is 3\n"
|
|
||||||
<<"example:\n"
|
|
||||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --dictpath ../dict/jieba.dict.utf8 --algorithm cutDAG\n"
|
|
||||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --dictpath ../dict/jieba.dict.utf8 --algorithm cutFull\n"
|
|
||||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --modelpath ../dict/hmm_model.utf8 --algorithm cutHMM\n"
|
|
||||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --dictpath ../dict/jieba.dict.utf8 --modelpath ../dict/hmm_model.utf8 --algorithm cutMix\n"
|
|
||||||
<<"\t"<<argv[0]<<" ../test/testdata/testlines.utf8 --dictpath ../dict/jieba.dict.utf8 --modelpath ../dict/hmm_model.utf8 --algorithm cutQuery --maxlen 3\n"
|
|
||||||
<<endl;
|
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
ArgvContext arg(argc, argv);
|
|
||||||
string dictPath = arg["--dictpath"];
|
|
||||||
string modelPath = arg["--modelpath"];
|
|
||||||
string algorithm = arg["--algorithm"];
|
|
||||||
int maxLen = atoi(arg["--maxlen"] == "" ? arg["--maxlen"].c_str() : "3");
|
|
||||||
|
|
||||||
if("cutHMM" == algorithm)
|
|
||||||
{
|
|
||||||
HMMSegment seg(modelPath.c_str());
|
|
||||||
if(!seg)
|
|
||||||
{
|
|
||||||
cout<<"seg init failed."<<endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
cut(&seg, arg[1].c_str());
|
|
||||||
}
|
|
||||||
else if("cutDAG" == algorithm)
|
|
||||||
{
|
|
||||||
MPSegment seg(dictPath.c_str());
|
|
||||||
if(!seg)
|
|
||||||
{
|
|
||||||
cout<<"seg init failed."<<endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
cut(&seg, arg[1].c_str());
|
|
||||||
}
|
|
||||||
else if ("cutFull" == algorithm)
|
|
||||||
{
|
|
||||||
FullSegment seg(dictPath.c_str());
|
|
||||||
if (!seg)
|
|
||||||
{
|
|
||||||
cout << "seg init failed" << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
cut(&seg, arg[1].c_str());
|
|
||||||
}
|
|
||||||
else if ("cutQuery" == algorithm)
|
|
||||||
{
|
|
||||||
QuerySegment seg(dictPath.c_str(), modelPath.c_str(), maxLen);
|
|
||||||
if (!seg)
|
|
||||||
{
|
|
||||||
cout << "seg init failed" << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
cut(&seg, arg[1].c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MixSegment seg(dictPath.c_str(), modelPath.c_str());
|
|
||||||
if(!seg)
|
|
||||||
{
|
|
||||||
cout<<"seg init failed."<<endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
cut(&seg, arg[1].c_str());
|
|
||||||
}
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user