import pandas as pd
import argparse

def convert_to_para(csv_path, pred_output, gold_output):
    """
    将CSV转换为para格式文件
    """
    # 读取CSV
    df = pd.read_csv(csv_path)
    
    # 生成预测para文件
    with open(pred_output, 'w', encoding='utf-8') as f:
        for idx, row in df.iterrows():
            line = f"{idx+1}\t{row['错误内容']}\t{row['语法结果']}\n"
            f.write(line)
    
    # 生成金标para文件
    with open(gold_output, 'w', encoding='utf-8') as f:
        for idx, row in df.iterrows():
            line = f"{idx+1}\t{row['错误内容']}\t{row['正确内容']}\n"
            f.write(line)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='将CSV转换为para格式')
    parser.add_argument('csv_file', help='输入的CSV文件路径')
    parser.add_argument('pred_output', help='预测结果para文件输出路径')
    parser.add_argument('gold_output', help='标准答案para文件输出路径')
    
    args = parser.parse_args()
    
    convert_to_para(args.csv_file, args.pred_output, args.gold_output)


# python convert_to_para.py /nfs/zhanghanhaodi/HHDZ_projects/full_book_evaluate/merged_data.csv pred.para gold.para