6#ifndef DEEPLIMA_SEGMENTATION_IMPL_CHAR_NGRAM_ENCODER_H
7#define DEEPLIMA_SEGMENTATION_IMPL_CHAR_NGRAM_ENCODER_H
30#define ONE_POS_MASK(BITS_PER_POS, VAR_TYPE) \
31 ( (BITS_PER_POS == sizeof(VAR_TYPE) * 8) ? ~((VAR_TYPE)(0)) : ((1 << BITS_PER_POS) - 1) )
33template <
class StreamDecoder>
50 void init(
const std::vector<ngram_descr_t>& ngram_descr)
59 StreamDecoder::reset();
81 return StreamDecoder::get_len(idx);
97 return StreamDecoder::bits_per_position(
m_ngram_descr[idx].m_type) != 1;
100 inline uint8_t
warmup(
const uint8_t* str, int32_t* pos, int32_t len)
103 uint8_t char_len = StreamDecoder::parse(str, pos, len);
106 throw std::runtime_error(
"Something wrong with stream decoder.");
137 typename StreamDecoder::buffer_t one_pos_mask
138 =
ONE_POS_MASK(StreamDecoder::bits_per_position(nd.
m_type),
typename StreamDecoder::buffer_t);
144 typename StreamDecoder::buffer_t mask = 0;
146 for (
size_t j = 0; j < nd.
m_length; j++)
148 mask = (mask << StreamDecoder::bits_per_position(nd.
m_type)) | one_pos_mask;
153 mask <<= StreamDecoder::bits_per_position(nd.
m_type);
173 std::vector<typename StreamDecoder::buffer_t>
m_mask;
#define ONE_POS_MASK(BITS_PER_POS, VAR_TYPE)
std::vector< typename StreamDecoder::buffer_t > m_mask
uint8_t m_chars_to_consume
uint8_t get_len(uint8_t idx) const
std::vector< uint8_t > m_shift
void init(const std::vector< ngram_descr_t > &ngram_descr)
CharNgramEncoder(const std::vector< ngram_descr_t > &ngram_descr)
std::vector< ngram_descr_t > m_ngram_descr
bool ready_to_generate() const
uint8_t get_lookahead() const
uint64_t get_feat(size_t idx) const
bool allow_unk(uint8_t idx) const
uint8_t warmup(const uint8_t *str, int32_t *pos, int32_t len)