LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
segmentation_impl.h
Go to the documentation of this file.
1// Copyright 2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifndef DEEPLIMA_SEGMENTATION_IMPL_H
7#define DEEPLIMA_SEGMENTATION_IMPL_H
8
10
12
17
18// #include "config.h"
19
20#include "utf8_reader.h"
21#include "char_ngram_encoder.h"
24
25
26namespace deeplima
27{
28namespace segmentation
29{
30
32{
33public:
34 typedef std::function < bool (uint8_t* buffer,
35 int32_t& read,
36 int32_t max) > read_callback_t;
37
38 virtual void parse_from_stream(const read_callback_t fn) = 0;
39 virtual void register_handler(const segmentation_callback_t fn) = 0;
41 virtual void finalize() = 0;
42
46 virtual bool predicts_mwt() const { return false; }
47
48 virtual ~ISegmentation() { }
49};
50
51namespace eigen_impl
52{
55}
56
57namespace impl
58{
60
64
70{
71public:
72
74
75 // SegmentationImpl(
76 // const std::vector<ngram_descr_t>& ngram_descr,
77 // size_t threads,
78 // size_t buffer_size_per_thread
79 // );
80
81 virtual ~SegmentationImpl() = default;
82
83 virtual void load(const std::string& fn);
84
85 void init(size_t threads, size_t buffer_size_per_thread);
86
87 virtual void parse_from_stream(const read_callback_t fn) override;
88
89 virtual void register_handler(const segmentation_callback_t fn) override;
90
92 virtual void finalize() override;
93
98 virtual bool predicts_mwt() const override
99 {
100 const auto& dicts = this->get_output_str_dicts();
101 return !dicts.empty() && dicts[0].size() > size_t(segm_tag_t::max_segm_tag);
102 }
103
104protected:
105
106 void vectorize_timepoint(uint64_t timepoint);
107
108 void increment_timepoint(uint64_t& timepoint);
109
110 void send_results(int32_t slot_idx);
111
112 void send_next_results();
113
114 void acquire_slot();
115
116 void handle_timepoint();
117
118 void no_more_data();
119
120protected:
121 std::vector<uint8_t> m_char_len;
122
125
128
131
134};
135
136} // namespace impl
137} // namespace segmentation
138} // namespace deeplima
139
140#endif
Handles multithreading.
virtual void finalize()=0
Cleanup all remaining locks if any.
virtual void register_handler(const segmentation_callback_t fn)=0
std::function< bool(uint8_t *buffer, int32_t &read, int32_t max) > read_callback_t
virtual void parse_from_stream(const read_callback_t fn)=0
virtual bool predicts_mwt() const
Whether this segmenter predicts multiword-token surfaces (sets the token_flags_t::multiword flag).
The implementation of the segmenter, a SegmentationClassifier, itself a RnnSequenceClassifier.
virtual void parse_from_stream(const read_callback_t fn) override
virtual bool predicts_mwt() const override
MWT-aware iff the model has more than the base segmentation tag classes (i.e.
virtual void register_handler(const segmentation_callback_t fn) override
virtual void finalize() override
Cleanup all remaining locks if any.
void init(size_t threads, size_t buffer_size_per_thread)
virtual void load(const std::string &fn)
DictEmbdVectorizer< EmbdUInt64FloatHolder, EmbdUInt64Float, eigen_wrp::EigenMatrixXf > EmbdVectorizer
impl::SegmentationInferenceWrapper< BiRnnEigenInferenceForSegmentation > Model
CharNgramEncoder< Utf8Reader<> > CharNgramEncoderFromUtf8
std::function< void(const std::vector< token_pos > &tokens, uint32_t len) > segmentation_callback_t