init demos

This commit is contained in:
gwdwyy 2013-08-02 21:36:22 +08:00
parent 35647189a6
commit 023cb964ed
4 changed files with 49 additions and 5 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -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
View 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;
}