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
|
||||
*swp
|
||||
*.out
|
||||
@ -8,4 +7,3 @@ tags
|
||||
log
|
||||
main
|
||||
cmlib.a
|
||||
demo
|
||||
|
@ -28,21 +28,24 @@ SRCLIB = $(SRCDIR)/libcppjieba.a
|
||||
.PHONY: clean $(SRCLIB)
|
||||
|
||||
# Main Targets
|
||||
all: demo
|
||||
all: keywordext_demo segment_demo
|
||||
|
||||
# This is a suffix rule
|
||||
#.c.o:
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $<
|
||||
|
||||
demo: $(OBJS) $(SRCLIB)
|
||||
keywordext_demo: keywordext_demo.o $(SRCLIB)
|
||||
$(DOLINK) -o $@ $^
|
||||
|
||||
segment_demo: segment_demo.o $(SRCLIB)
|
||||
$(DOLINK) -o $@ $^
|
||||
|
||||
$(SRCLIB):
|
||||
cd $(SRCDIR) && $(MAKE)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.ut *.d demo
|
||||
rm -f *.o *.ut *.d keywordext_demo segment_demo
|
||||
cd $(SRCDIR) && make clean
|
||||
|
||||
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