Skip to content

Commit

Permalink
add data example and config example
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneplus committed Sep 1, 2013
1 parent 3d85cef commit a1b3ef8
Show file tree
Hide file tree
Showing 36 changed files with 615 additions and 22,047 deletions.
40 changes: 40 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
all: cws pos par ner multi_cws

cws: cws.cpp
g++ -o cws cws.cpp -I./ \
-I../include/ \
-I../thirdparty/boost/include \
-L../lib/ -lsegmentor -lboost_regex

pos: pos.cpp
g++ -o pos pos.cpp -I./ \
-I../include/ \
-L../lib/ -lpostagger

ner: ner.cpp
g++ -o ner ner.cpp -I./ \
-I../src/ner/ \
-L../lib/ -lner

par: par.cpp
g++ -o par par.cpp -I./ \
-I../src/parser/ \
-L../lib -lparser

multi_cws: multi_cws.cpp
g++ -o multi_cws multi_cws.cpp \
thirdparty/tinythreadpp/tinythread.cpp \
-I./ \
-I../include/ \
-I../thirdparty/boost/include/ \
-I./thirdparty/tinythreadpp/ \
-L../lib/ -lsegmentor -lboost_regex -lpthread

.PHONY: clean

clean:
rm cws
rm pos
rm ner
rm par
rm multi_cws
40 changes: 40 additions & 0 deletions examples/cws.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <string>
#include "segment_dll.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
std::cerr << "cws [model path] [lexicon_file]" << std::endl;
return 1;
}

void * engine = 0;
if (argc == 2) {
engine = segmentor_create_segmentor(argv[1]);
} else if (argc == 3) {
engine = segmentor_create_segmentor(argv[1], argv[2]);
}

if (!engine) {
return -1;
}
std::vector<std::string> words;

const char * suite[2] = {
"What's wrong with you? 别灰心! http://t.cn/zQz0Rn",
"台北真的是天子骄子吗?",};

for (int i = 0; i < 2; ++ i) {
words.clear();
int len = segmentor_segment(engine, suite[i], words);
for (int i = 0; i < len; ++ i) {
std::cout << words[i];
if (i+1 == len) std::cout <<std::endl;
else std::cout<< "|";
}
}

segmentor_release_segmentor(engine);
return 0;
}

43 changes: 43 additions & 0 deletions examples/ner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <vector>

#include "ner_dll.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
std::cerr << "usage: ./ner [model_path]" << std::endl;
return -1;
}

void * engine = ner_create_recognizer(argv[1]);
if (!engine) {
std::cerr << "failed to load model" << std::endl;
return -1;
}

std::vector<std::string> words;
std::vector<std::string> postags;

words.push_back("中国"); postags.push_back("ns");
words.push_back("国际"); postags.push_back("n");
words.push_back("广播"); postags.push_back("n");
words.push_back("电台"); postags.push_back("n");
words.push_back("创办"); postags.push_back("v");
words.push_back(""); postags.push_back("p");
words.push_back("1941年"); postags.push_back("m");
words.push_back("12月"); postags.push_back("m");
words.push_back("3日"); postags.push_back("m");
words.push_back(""); postags.push_back("wp");

std::vector<std::string> tags;

ner_recognize(engine, words, postags, tags);

for (int i = 0; i < tags.size(); ++ i) {
std::cout << words[i] << "\t" << postags[i] << "\t" << tags[i] << std::endl;
}

ner_release_recognizer(engine);
return 0;
}

37 changes: 37 additions & 0 deletions examples/par.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <vector>

#include "parser_dll.h"

int main(int argc, char * argv[]) {
if (argc < 2) {
return -1;
}

void * engine = parser_create_parser(argv[1]);
if (!engine) {
return -1;
}

std::vector<std::string> words;
std::vector<std::string> postags;

words.push_back("一把手"); postags.push_back("n");
words.push_back("亲自"); postags.push_back("d");
words.push_back("过问"); postags.push_back("v");
words.push_back(""); postags.push_back("wp");

std::vector<int> heads;
std::vector<std::string> deprels;

parser_parse(engine, words, postags, heads, deprels);

for (int i = 0; i < heads.size(); ++ i) {
std::cout << words[i] << "\t" << postags[i] << "\t"
<< heads[i] << "\t" << deprels[i] << std::endl;
}

parser_release_parser(engine);
return 0;
}

36 changes: 36 additions & 0 deletions examples/pos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <vector>

#include "postag_dll.h"

int main(int argc, char * argv[]) {
if (argc < 1) {
return -1;
}

void * engine = postagger_create_postagger(argv[1]);
if (!engine) {
return -1;
}

std::vector<std::string> words;

words.push_back("");
words.push_back("");
words.push_back("中国人");

std::vector<std::string> tags;

postagger_postag(engine, words, tags);

for (int i = 0; i < tags.size(); ++ i) {
std::cout << words[i] << "/" << tags[i];
if (i == tags.size() - 1) std::cout << std::endl;
else std::cout << " ";

}

postagger_release_postagger(engine);
return 0;
}

1 change: 1 addition & 0 deletions src/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ void Parser::test() {

ifstream f(test_file);
if (!f) {
ERROR_LOG("Failed to load test file %s", test_file);
return;
}

Expand Down
145 changes: 0 additions & 145 deletions tools/train/README.md

This file was deleted.

Loading

0 comments on commit a1b3ef8

Please sign in to comment.