6#ifndef DEEPLIMA_DUMPER_CONLLU_H
7#define DEEPLIMA_DUMPER_CONLLU_H
60 oss << token.
id <<
"-" << token.
mwt_last <<
"\t"
62 <<
"\t_\t_\t_\t_\t_\t_\t_\t_" << std::endl;
64 oss << token.
id <<
"\t"
66 << token.
lemma <<
"\t"
69 << token.
feats <<
"\t"
73 << token.
misc << std::endl << std::flush;
83 std::string result(s);
84 for (
char& c : result)
86 if (c ==
'\r' || c ==
'\n' || c ==
'\t')
95std::ostream&
operator<< (std::ostream& out,
const std::vector<T>& v)
100 std::copy (v.begin(), v.end(), std::ostream_iterator<T>(out,
", "));
106bool dfs(
int v, std::vector<uint32_t>& heads, std::vector<int>& color,
107 uint32_t& cycle_start, uint32_t& cycle_end)
115 if (u == 0 || u >= heads.size())
122 if (
dfs(u, heads, color, cycle_start, cycle_end))
124 }
else if (color[u] == 1) {
137 uint32_t n = heads.size();
138 std::vector<int> color;
139 uint32_t cycle_start = std::numeric_limits<uint32_t>::max();
140 uint32_t cycle_end = 0;
143 for (uint32_t v = 1; v < n; v++)
145 if (v == root)
continue;
146 if (color[v] == 0 &&
dfs(v, heads, color, cycle_start, cycle_end))
150 if (cycle_start == std::numeric_limits<uint32_t>::max() || cycle_start == root)
159 if (cycle_end > 0 && cycle_end != root && cycle_end < n)
162 heads[cycle_end] = root;
184 virtual void operator()(
const std::vector<deeplima::segmentation::token_pos>& tokens, uint32_t len) = 0;
208 virtual void operator()(
const std::vector<deeplima::segmentation::token_pos>& tokens, uint32_t len)
211 for (
size_t i = 0; i < len; i++)
213 const char* ptoken = tokens[i].m_pch;
214 std::ostringstream s;
221 for (
size_t j = 0; j < tokens[i].m_len; j++)
223 if (*ptoken ==
'\r' || *ptoken ==
'\n' || *ptoken ==
'\t')
233 std::string str = s.str();
234 if (std::string::npos == str.find_first_not_of(
' '))
239 std::cout << str <<
" ";
245 std::cout << std::endl;
263 std::cout << std::endl;
267 virtual void operator()(
const std::vector<deeplima::segmentation::token_pos>& tokens, uint32_t len)
270 for (
size_t i = 0; i < len; i++)
272 const char* ptoken = tokens[i].m_pch;
273 std::ostringstream s;
279 for (
size_t j = 0; j < tokens[i].m_len; j++)
281 if (*ptoken ==
'\r' || *ptoken ==
'\n' || *ptoken ==
'\t')
291 std::string str = s.str();
292 if (std::string::npos == str.find_first_not_of(
' '))
300 if (tokens[i].m_mwt_len > 0 &&
nullptr != tokens[i].m_mwt_surface_pch)
303 const char* psurf = tokens[i].m_mwt_surface_pch;
304 for (
size_t j = 0; j < tokens[i].m_mwt_surface_len; j++)
306 surface += (*psurf ==
'\r' || *psurf ==
'\n' || *psurf ==
'\t') ?
' ' : *psurf;
311 << surface <<
"\t_\t_\t_\t_\t_\t_\t_\t_" << std::endl;
315 std::cout <<
"\t_\t_\t_\t_\t";
318 std::cout <<
"\t_\t_\t_" << std::endl;
327 std::cout << std::endl;
391 const std::vector<std::vector<std::string>> &
getMClasses()
const {
400 void set_classes(
size_t idx,
const std::string& class_name,
const std::vector<std::string>& data)
417 if (feat_name ==
"upos" || feat_name ==
"xpos" || feat_name ==
"eos")
429 std::string feat_str;
433 if (0 != iter.token_class(i))
435 if (!feat_str.empty())
442 feat_str +=
m_classes[i][iter.token_class(i)];
463 std::vector<uint32_t> heads(
m_tokens.size()+1);
465 for (
size_t i = 1; i < heads.size(); i++)
475 for (
size_t i = 1; i < heads.size(); i++)
486 std::cout << std::endl;
490 void operator()(I& iter, uint32_t begin, uint32_t end,
bool hasDeps =
false)
508 const char* ptoken = iter.form();
509 if (std::string(ptoken) ==
"<ROOT>")
515 std::ostringstream s;
523 if (*ptoken ==
'\r' || *ptoken ==
'\n' || *ptoken ==
'\t')
533 std::string str = s.str();
534 if (std::string::npos == str.find_first_not_of(
' '))
547 if (iter.mwt_len() > 0)
586 if ((
m_root == 0) && (iter.head() == 0))
592 else if (iter.head() >= end - begin)
608 else if ((
m_root != 0) && (iter.head() == 0))
625 token.
head = iter.head();
628 token.
deprel = iter.deprel();
void increment_token_counter()
uint64_t get_token_counter() const
virtual void operator()(const std::vector< deeplima::segmentation::token_pos > &tokens, uint32_t len)=0
virtual ~AbstractDumper()
void set_classes(size_t idx, const std::string &class_name, const std::vector< std::string > &data)
const std::vector< std::vector< std::string > > & getMClasses() const
void increment_token_counter()
std::string generate_feats(const I &iter)
std::vector< ConllToken > m_tokens
virtual ~AnalysisToConllU()
size_t m_first_feature_to_print
std::vector< std::string > m_class_names
std::vector< std::vector< std::string > > m_classes
void operator()(I &iter, uint32_t begin, uint32_t end, bool hasDeps=false)
virtual uint64_t get_token_counter() const
uint32_t m_next_token_idx
virtual uint64_t get_token_counter() const =0
virtual ~DumperBase()=default
virtual void operator()(const std::vector< deeplima::segmentation::token_pos > &tokens, uint32_t len)
uint32_t m_next_token_idx
virtual void operator()(const std::vector< deeplima::segmentation::token_pos > &tokens, uint32_t len)
std::string conllu_field(const char *s)
A CoNLL-U field with its tabs and line breaks turned into spaces.
bool dfs(int v, std::vector< uint32_t > &heads, std::vector< int > &color, uint32_t &cycle_start, uint32_t &cycle_end)
std::ostream & operator<<(std::ostream &oss, const ConllToken &token)
bool find_cycle(std::vector< uint32_t > &heads, uint32_t root)
Edit rules for lemmatizing words absent from the lemma dictionary.
ConllToken(const ConllToken &)=default
ConllToken & operator=(const ConllToken &)=default