|
|
|
@ -16,23 +16,23 @@ class Writer:
|
|
|
|
|
@staticmethod
|
|
|
|
|
def make_output_writer(args, num_components, colocation_ids, word_renderer):
|
|
|
|
|
params = Writer.other_params(args)
|
|
|
|
|
return Writer(args.out, num_components, OutFormatter(colocation_ids, word_renderer), args.collocation_sentence_map_dest, params)
|
|
|
|
|
return Writer(args.out, num_components, OutFormatter(colocation_ids, word_renderer), args.collocation_sentence_map_dest, params, args.separator)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def make_output_no_stat_writer(args, num_components, colocation_ids, word_renderer):
|
|
|
|
|
params = Writer.other_params(args)
|
|
|
|
|
return Writer(args.out_no_stat, num_components, OutNoStatFormatter(colocation_ids, word_renderer), args.collocation_sentence_map_dest, params)
|
|
|
|
|
return Writer(args.out_no_stat, num_components, OutNoStatFormatter(colocation_ids, word_renderer), args.collocation_sentence_map_dest, params, args.separator)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def make_all_writer(args, num_components, colocation_ids, word_renderer):
|
|
|
|
|
return Writer(args.all, num_components, AllFormatter(colocation_ids, word_renderer), args.collocation_sentence_map_dest, None)
|
|
|
|
|
return Writer(args.all, num_components, AllFormatter(colocation_ids, word_renderer), args.collocation_sentence_map_dest, None, args.separator)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def make_stats_writer(args, num_components, colocation_ids, word_renderer):
|
|
|
|
|
params = Writer.other_params(args)
|
|
|
|
|
return Writer(args.stats, num_components, StatsFormatter(colocation_ids, word_renderer), args.collocation_sentence_map_dest, params)
|
|
|
|
|
return Writer(args.stats, num_components, StatsFormatter(colocation_ids, word_renderer), args.collocation_sentence_map_dest, params, args.separator)
|
|
|
|
|
|
|
|
|
|
def __init__(self, file_out, num_components, formatter, collocation_sentence_map_dest, params):
|
|
|
|
|
def __init__(self, file_out, num_components, formatter, collocation_sentence_map_dest, params, separator):
|
|
|
|
|
# TODO FIX THIS
|
|
|
|
|
self.collocation_sentence_map_dest = collocation_sentence_map_dest
|
|
|
|
|
if params is None:
|
|
|
|
@ -49,6 +49,7 @@ class Writer:
|
|
|
|
|
self.num_components = num_components
|
|
|
|
|
self.output_file = file_out
|
|
|
|
|
self.formatter = formatter
|
|
|
|
|
self.separator = separator
|
|
|
|
|
|
|
|
|
|
def header(self):
|
|
|
|
|
repeating_cols = self.formatter.header_repeat()
|
|
|
|
@ -78,7 +79,7 @@ class Writer:
|
|
|
|
|
return sorted(rows, key=key, reverse=self.sort_order)
|
|
|
|
|
|
|
|
|
|
def write_header(self, file_handler):
|
|
|
|
|
file_handler.write(",".join(self.header()) + "\n")
|
|
|
|
|
file_handler.write(self.separator.join(self.header()) + "\n")
|
|
|
|
|
|
|
|
|
|
def write_out_worker(self, file_handler, structure, colocation_ids, col_sent_map):
|
|
|
|
|
rows = []
|
|
|
|
@ -99,12 +100,16 @@ class Writer:
|
|
|
|
|
for words in match.matches:
|
|
|
|
|
to_write = []
|
|
|
|
|
|
|
|
|
|
for idx, _comp in enumerate(components):
|
|
|
|
|
idx = str(idx + 1)
|
|
|
|
|
if idx not in words:
|
|
|
|
|
idx = 1
|
|
|
|
|
for _comp in components:
|
|
|
|
|
if _comp.idx == '#':
|
|
|
|
|
continue
|
|
|
|
|
idx_s = str(idx)
|
|
|
|
|
idx += 1
|
|
|
|
|
if idx_s not in words:
|
|
|
|
|
to_write.extend([""] * self.formatter.length())
|
|
|
|
|
else:
|
|
|
|
|
to_write.extend(self.formatter.content_repeat(words, match.representations, idx, structure.id))
|
|
|
|
|
to_write.extend(self.formatter.content_repeat(words, match.representations, idx_s, structure.id))
|
|
|
|
|
|
|
|
|
|
# make them equal size
|
|
|
|
|
to_write.extend([""] * (self.num_components * self.formatter.length() - len(to_write)))
|
|
|
|
@ -121,7 +126,7 @@ class Writer:
|
|
|
|
|
|
|
|
|
|
if rows != []:
|
|
|
|
|
rows = self.sorted_rows(rows)
|
|
|
|
|
file_handler.write("\n".join([",".join(row) for row in rows]) + "\n")
|
|
|
|
|
file_handler.write("\n".join([self.separator.join(row) for row in rows]) + "\n")
|
|
|
|
|
file_handler.flush()
|
|
|
|
|
|
|
|
|
|
def write_out(self, structures, colocation_ids):
|
|
|
|
|