22 assert(m_upos_dict.has(upos));
23 size_t upos_id = m_upos_dict.get_id(upos);
28 for (
const auto& kv : feats )
30 const string& feat_name = kv.first;
31 assert(kv.second.size() == 1);
32 assert(m_feat_dict.has(feat_name));
33 size_t feat_id = m_feat_dict.get_id(feat_name);
35 const auto it = feats2mask.find(feat_id);
36 assert(feats2mask.end() != it);
37 size_t mask_id = it->second;
41 const string& feat_value = *(kv.second.begin());
42 size_t value_id =
m_feats[feat_id].get_id(feat_value);
43 v.
append(value_id << offset);
49 assert(upos == decoded_upos);
58 return m_upos_dict.get_key(upos_id);
66morph_model_t::dict_t::dict_t(
const string& str)
68 istringstream iss(str);
78morph_model_t::dict_t morph_model_t::dict_t::from_string(
const string& str)
84string morph_model_t::dict_t::to_string()
const
88 oss << m_id2key.size();
89 for (
const string& v : m_id2key)
91 assert(string::npos == v.find(
' '));
92 assert(string::npos == v.find(
'\n'));
101 istringstream iss(str);
112 throw std::runtime_error(
"morph_model_t: t should not be empty here.");
114 m_upos_dict = morph_model_t::dict_t::from_string(t);
123 throw std::runtime_error(
"morph_model_t: t should not be empty here.");
125 m_feat_dict = morph_model_t::dict_t::from_string(t);
139 istringstream temp_iss(t);
141 while (temp_iss >> v)
156 std::istringstream temp_iss(t);
158 while (temp_iss >> v)
160 if (v < 0 || v > std::numeric_limits<uint8_t>::max())
162 throw std::runtime_error(
"morph_model_t: invalid value for v.");
164 uint8_t ui = uint8_t(v);
178 istringstream temp_iss(t);
181 while (temp_iss >> p)
183 string::size_type i = p.find(
'_');
184 if (string::npos == i)
186 throw std::runtime_error(
"_ has not been found in p.");
189 istringstream p_iss(p);
194 throw std::runtime_error(
"morph_model_t: a not found in mask.");
199 }
while (!t.empty());
211 m_feats[
m_feats.size() - 1] = morph_model_t::dict_t::from_string(t);
218 std::ostringstream oss;
220 oss << m_upos_dict.to_string() << std::endl;
221 oss << m_feat_dict.to_string() << std::endl;
225 for (
size_t i = 0; i <
m_masks.size(); ++i)
236 for (
size_t i = 0; i <
m_offset.size(); ++i)
250 for (
const auto& kv : m)
256 oss << kv.first <<
"_" << kv.second;
266 oss << d.to_string() << endl;
276 std::vector<std::string> out_strings;
280 for (
size_t feat_idx = 1; feat_idx <
m_feats.size(); ++feat_idx)
283 out_strings.emplace_back(
m_feats[feat_idx].get_key(feat_val));
286 std::ostringstream oss;
287 for (
size_t i = 0; i < out_strings.size(); ++i)
289 oss <<
" " << out_strings[i];
Encoding on one 64 bits integer of the set of morphological features for one token.
void append(feat_base_t val)
const std::string & decode_upos_to_str(const morph_feats_t &feats) const
std::vector< std::map< size_t, size_t > > m_feats2mask
morph_feats_t convert(const std::string &upos, const std::map< std::string, std::set< std::string > > &feats) const
std::vector< uint8_t > m_offset
std::string to_string() const
feat_base_t decode_feat(const morph_feats_t &feats, size_t feat_id) const
feat_base_t decode_upos(const morph_feats_t &feats) const
size_t get_feats_count() const
std::vector< feat_base_t > m_masks
std::vector< dict_t > m_feats