6#ifndef CONLLU_TREEBANK_H
7#define CONLLU_TREEBANK_H
66 void load(
const std::string& fn);
100 token_t(
size_t line_idx,
size_t pos, uint16_t len=0)
123 word_t(
size_t line_idx,
size_t token_idx)
138 void load(
const std::string& fn);
139 void load(std::istream& input);
168 inline const std::vector<word_t>&
words()
const
186 assert(line_idx <
m_lines.size());
191 void rebuild_structure(
size_t num_sentences,
size_t num_tokens,
size_t num_words);
213 : m_it(it), m_line(line)
216 inline bool eos()
const
221 inline bool is_word()
const
226 inline const std::string& form()
const
228 return m_line.
form();
232 struct iterator_struct
237 : m_it(it), m_data(
data) { }
239 iterator_struct(
const iterator_struct& it)
240 : m_it(it.m_it), m_data(it.m_data) { }
242 inline const token_struct operator*()
const
244 return token_struct(m_it, m_data.
get_line(m_it->m_line_idx));
247 inline bool operator==(
const iterator_struct& other)
249 return m_it == other.m_it;
252 inline bool operator!=(
const iterator_struct& other)
254 return m_it != other.m_it;
257 inline iterator_struct operator++(
int)
259 iterator_struct rv = *
this;
274 assert(
nullptr !=
m_data);
280 assert(
nullptr !=
m_data);
286 assert(
nullptr !=
m_data);
292 assert(
nullptr !=
m_data);
309 : m_it(it), m_line(line)
312 inline bool eos()
const
317 inline bool is_word()
const
322 inline const std::string& form()
const
324 if (
"_" == m_line.
form())
326 return m_line.
lemma();
328 return m_line.
form();
331 inline const std::string& upos()
const
333 return m_line.
upos();
336 inline const std::string& xpos()
const
338 return m_line.
xpos();
341 inline const std::string& deprel()
const
346 inline const idx_t& head()
const
348 return m_line.
head();
351 inline const idx_t& idx()
const
356 inline const std::map<std::string, std::set<std::string>>& feats()
const
358 return m_line.
feats();
380 return m_it == other.m_it;
385 return m_it != other.m_it;
405 assert(
nullptr !=
m_data);
411 assert(
nullptr !=
m_data);
417 assert(
nullptr !=
m_data);
423 assert(
nullptr !=
m_data);
439 assert(
nullptr !=
m_data);
445 assert(
nullptr !=
m_data);
451 assert(
nullptr !=
m_data);
460 bool parse_ud_file_name(
const std::string& fn, std::map<std::string, std::string>& fields);
464 struct AnnotatedDocument
475 throw std::runtime_error(std::string(
"Error: treebank cannot load path "+path));
484 return it->second.doc;
486 throw std::runtime_error(std::string(
"Error: treebank does not have a ")+name+
" part");
494 return it->second.annot;
496 throw std::runtime_error(std::string(
"Error: treebank does not have a ")+name+
" part");
500 bool load(
const std::string& path);
502 std::map<std::string, AnnotatedDocument>
m_parts;
std::vector< CoNLLULine > m_lines
const std::vector< word_t > & words() const
const std::vector< word_t > & get_words() const
size_t get_num_sentences() const
std::vector< token_t > m_tokens
void load(const std::string &fn)
tokens_const_iterator tokens_end() const
words_const_iterator words_begin() const
const std::vector< token_t > & get_tokens() const
bool test_structure() const
void rebuild_structure(size_t num_sentences, size_t num_tokens, size_t num_words)
const CoNLLULine & get_line(size_t line_idx) const
std::vector< Sentence > m_sentences
const Sentence & get_sentence(size_t idx) const
std::vector< word_t >::const_iterator words_const_iterator
words_const_iterator words_end() const
std::vector< token_t >::const_iterator tokens_const_iterator
std::vector< word_t > m_words
tokens_const_iterator tokens_begin() const
virtual const_iterator end() const
virtual const_iterator begin() const
virtual size_t size() const
BoundedWordLevelAdapter(const Annotation *p, size_t first_word_idx, size_t len)
const std::map< std::string, std::set< std::string > > & feats() const
const idx_t & head() const
const std::string & deprel() const
const std::string & form() const
const std::string & lemma() const
const idx_t & idx() const
const std::string & upos() const
const std::string & xpos() const
std::string m_original_text
void load(const std::string &fn)
const std::wstring & get_text() const
const std::string & get_original_text() const
size_t m_first_token_line
size_t calc_num_of_words(const Annotation &annot) const
size_t get_first_word_idx() const
const Word & get_word(size_t idx) const
const Word & get_word(idx_t id) const
TokenLevelAdapter(const Annotation *p)
const_iterator end() const
iterator_struct const_iterator
const Annotation & data() const
const Annotation * m_data
const_iterator begin() const
const Document & get_doc(const std::string &name) const
Treebank(const std::string &path)
std::map< std::string, AnnotatedDocument > m_parts
const Annotation & get_annot(const std::string &name) const
bool load(const std::string &path)
virtual size_t size() const
WordLevelAdapter(const Annotation *p)
const Annotation * m_data
const Annotation & data() const
virtual const_iterator begin() const
virtual const_iterator end() const
iterator_struct const_iterator
bool parse_ud_file_name(const std::string &fn, map< string, string > &fields)
token_t(size_t line_idx, size_t pos, uint16_t len=0)
bool is_multiword() const
token_t::token_flags_t m_flags
word_t(size_t line_idx, size_t token_idx)
iterator_struct(const iterator_struct &it)
bool operator!=(const iterator_struct &other)
iterator_struct operator++(int)
const Annotation & m_data
Annotation::words_const_iterator m_it
const word_struct operator*() const
bool operator==(const iterator_struct &other)
iterator_struct(Annotation::words_const_iterator it, const Annotation &data)
bool is_multiword() const
bool is_real_word() const