mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
init demos
This commit is contained in:
parent
35647189a6
commit
023cb964ed
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
*tmp*
|
|
||||||
tags
|
tags
|
||||||
*swp
|
*swp
|
||||||
*.out
|
*.out
|
||||||
@ -8,4 +7,3 @@ tags
|
|||||||
log
|
log
|
||||||
main
|
main
|
||||||
cmlib.a
|
cmlib.a
|
||||||
demo
|
|
||||||
|
@ -28,21 +28,24 @@ SRCLIB = $(SRCDIR)/libcppjieba.a
|
|||||||
.PHONY: clean $(SRCLIB)
|
.PHONY: clean $(SRCLIB)
|
||||||
|
|
||||||
# Main Targets
|
# Main Targets
|
||||||
all: demo
|
all: keywordext_demo segment_demo
|
||||||
|
|
||||||
# This is a suffix rule
|
# This is a suffix rule
|
||||||
#.c.o:
|
#.c.o:
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
$(CXX) -c $(CXXFLAGS) $<
|
$(CXX) -c $(CXXFLAGS) $<
|
||||||
|
|
||||||
demo: $(OBJS) $(SRCLIB)
|
keywordext_demo: keywordext_demo.o $(SRCLIB)
|
||||||
|
$(DOLINK) -o $@ $^
|
||||||
|
|
||||||
|
segment_demo: segment_demo.o $(SRCLIB)
|
||||||
$(DOLINK) -o $@ $^
|
$(DOLINK) -o $@ $^
|
||||||
|
|
||||||
$(SRCLIB):
|
$(SRCLIB):
|
||||||
cd $(SRCDIR) && $(MAKE)
|
cd $(SRCDIR) && $(MAKE)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.ut *.d demo
|
rm -f *.o *.ut *.d keywordext_demo segment_demo
|
||||||
cd $(SRCDIR) && make clean
|
cd $(SRCDIR) && make clean
|
||||||
|
|
||||||
sinclude $(SOURCES:.cpp=.d)
|
sinclude $(SOURCES:.cpp=.d)
|
||||||
|
43
demo/segment_demo.cpp
Normal file
43
demo/segment_demo.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include "../src/headers.h"
|
||||||
|
|
||||||
|
using namespace CppJieba;
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
if(argc < 2)
|
||||||
|
{
|
||||||
|
cerr<<"usage: "<<argv[0]<<" filename"<<endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Segment seg;
|
||||||
|
if(!seg.init())
|
||||||
|
{
|
||||||
|
cerr<<"seg init failed."<<endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!seg.loadSegDict("../dicts/jieba.dict.gbk"))
|
||||||
|
{
|
||||||
|
cerr<<"seg loadDict failed."<<endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ifstream ifile(argv[1]);
|
||||||
|
vector<string> res;
|
||||||
|
string line;
|
||||||
|
while(getline(ifile, line))
|
||||||
|
{
|
||||||
|
res.clear();
|
||||||
|
if(!line.empty())
|
||||||
|
{
|
||||||
|
seg.cutDAG(line, res);
|
||||||
|
cout<<line<<"\n"<<joinStr(res,"/")<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
seg.dispose();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user