Source code for pie_extended.pipeline.formatters.proto

from typing import List, Callable, Dict


[docs] class Formatter: # Default is TSV """ The CSV formatter necessarily starts with form in its header. """ format_line: Callable[[Dict[str, str]], List[str]] def __init__(self, tasks: List[str]): self.tasks: List[str] = tasks # With post-processing, the order of the dictionary cannot be trusted: columns are taken by name self.format_line = self.format_line_3_6
[docs] def format_line_3_6(self, annotation: Dict[str, str]) -> List[str]: """ Format the tags """ return [annotation["form"]] + [annotation[task] for task in self.tasks]
[docs] def write_line(self, formatted): return "\t".join(formatted) + "\r\n"
[docs] def get_headers(self): return ["token"] + self.tasks
[docs] def write_headers(self)-> str: """ Format the headers """ return self.write_line(self.get_headers())