from Scripts.Libs.Utils.dataframe_interaction import get_raw_from_dataframe
from Scripts.Libs.CleaningPipeline.special_token import SpecialToken
import pandas as pd

class BPE_corpus():

    def __init__(self, output_path :str):
        self.output_handler = open(output_path, "w")

    def close(self):
        # add corpus end before closing
        self.output_handler.write(SpecialToken.CORPUS_END.value)
        self.output_handler.close()
        
    def write_from_str(self, output: str):
        if output == '':
            return
        self.output_handler.write(output)

    def write_from_df(self, df: pd.DataFrame):
        self.write_from_str(get_raw_from_dataframe(df))