Пример #1
0
int segmentor_segment(void * segmentor,
        const std::string & str,
        std::vector<std::string> & words) {
    // std::cout << "input str = " << str << std::endl;
    SegmentorWrapper * wrapper = 0;
    wrapper = reinterpret_cast<SegmentorWrapper *>(segmentor);
    return wrapper->segment(str.c_str(), words);
}
Пример #2
0
void * segmentor_create_segmentor(const char * path, const char * lexicon_file) {
    SegmentorWrapper * wrapper = new SegmentorWrapper();

    if (!wrapper->load(path, lexicon_file)) {
        return 0;
    }

    return reinterpret_cast<void *>(wrapper);
}
Пример #3
0
int segmentor_customized_segment(void * segmentor,
                                 const std::string & str,
                                 std::vector<std::string> & words) {
  if (str.empty()) {
    return 0;
  }
  SegmentorWrapper * wrapper = reinterpret_cast<SegmentorWrapper*>(segmentor);
  return wrapper->customized_segment(str, words);
}
Пример #4
0
int segmentor_customized_segment_online(void * parser,
                      const char * model_path,
                      const char * lexicon_path,
                      const std::string & line,
                      std::vector<std::string> & words) {
  if (line.empty()) {
    return 0;
  }

  SegmentorWrapper * wrapper = 0;
  wrapper = reinterpret_cast<SegmentorWrapper *>(parser);
  return wrapper->customized_segment(model_path, lexicon_path, line.c_str(), words);
}
Пример #5
0
void * segmentor_create_customized_segmentor(const char * baseline_model_path,
                                  const char * model_path,
                                  const char * lexicon_path) {
  SegmentorWrapper * wrapper = new SegmentorWrapper();

  if (!wrapper->load_baseline(baseline_model_path)) {
    delete wrapper;
    return 0;
  }

  if (!wrapper->load_customized(model_path, lexicon_path)) {
    delete wrapper;
    return 0;
  }

  return reinterpret_cast<void *>(wrapper);
}