18#define RESERVE_FIELDS 16
23 size_t eol_pos = buf.find_first_of(
"\r\n");
24 size_t pos = 0, sep_pos = buf.find(sep, pos+1);
26 while (string::npos != sep_pos)
28 push_back(buf.substr(pos, sep_pos - pos));
30 sep_pos = buf.find(sep, pos);
34 push_back(buf.substr(pos, sep_pos - pos));
87 throw logic_error(
"Can't parse ID field \"" + line[0] +
"\" in line \"" + line.
write() +
"\"");
93 throw logic_error(
"Can't parse FORM field \"" + line[1] +
"\" in line \"" + line.
write() +
"\"");
99 throw logic_error(
"Can't parse LEMMA field \"" + line[2] +
"\" in line \"" + line.
write() +
"\"");
105 throw logic_error(
"Can't parse UPOS field \"" + line[3] +
"\" in line \"" + line.
write() +
"\"");
111 throw logic_error(
"Can't parse XPOS field \"" + line[4] +
"\" in line \"" + line.
write() +
"\"");
117 throw logic_error(
"Can't parse FEATS field \"" + line[5] +
"\" in line \"" + line.
write() +
"\"");
121 _head = (line[6] ==
"_") ?
idx_t(std::numeric_limits<idx_t::base_int_t>::max()) :
idx_t(line[6]);
126 throw logic_error(
"Can't parse DEPREL field \"" + line[7] +
"\" in line \"" + line.
write() +
"\"");
132 throw logic_error(
"Can't parse DEPS field \"" + line[8] +
"\" in line \"" + line.
write() +
"\"");
138 throw logic_error(
"Can't parse MISC field \"" + line[9] +
"\" in line \"" + line.
write() +
"\"");
151 for (
const string& f : l)
153 size_t pos = f.find(
'=');
154 if (string::npos == pos)
156 throw logic_error(
"Wrong format of FEAT field: \"" + s +
"\"");
159 string k = f.substr(0, pos);
160 string v = f.substr(pos + 1);
181 for (
const string& f : l)
183 size_t pos = f.find(
':');
184 if (string::npos == pos)
186 throw logic_error(
"Wrong format of DEPS field: \"" + s +
"\"");
191 string deprel = f.substr(pos + 1);
207 for (
const string& f : l)
216 size_t pos = f.find(
'=');
217 if (string::npos == pos)
220 if (string::npos == pos)
223 std::cerr <<
"Wrong format of MISC field: \"" << s <<
"\"" << std::endl;
227 string k = f.substr(0, pos);
228 string v = f.substr(pos + 1);
238 if (!raw &&
"_" == s)
270 if (
_deps.size() == 0)
276 l.reserve(
_deps.size());
278 for (
auto& d :
_deps)
280 l.push_back(d.serialize());
288 if (
_misc.size() == 0)
294 l.reserve(
_misc.size());
296 for (
auto& kv :
_misc)
321 string serialized_values;
325 if (serialized_values.size() > 0)
327 serialized_values += string(
",");
330 serialized_values += s;
333 return _key +
"=" + serialized_values;
bool parse_deps(const std::string &s)
bool is_empty_line() const
std::string serialize_string(const std::string &s) const
std::map< std::string, std::string > _misc
std::vector< dep_t > _deps
const idx_t & head() const
const std::string & deprel() const
virtual std::string write(char sep='\t') const
bool is_comment_line() const
bool parse_misc(const std::string &s)
bool parse_string_field(const std::string &s, std::string &out, bool raw=false)
std::string serialize_misc() const
std::string serialize_feats() const
std::map< std::string, std::set< std::string > > _feats
void init_impl(const Line &line)
static bool parse_feats(const std::string &s, std::map< std::string, std::set< std::string > > &_feats)
std::string serialize_deps() const
virtual void read(const std::string &buf, char sep='\t')
virtual std::string write(char sep='\t') const
std::string serialize() const
std::string serialize() const
std::set< std::string > _values
bool parse(const std::string &s)
std::string serialize() const