# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/04_DatasetConstruction.ipynb (unless otherwise specified).

__all__ = ['makeEditOpsFile', 'DATA_SMALL_METHODS_TRAIN_BUGGY', 'DATA_SMALL_METHODS_TRAIN_FIXED',
           'DATA_SMALL_METHODS_VALID_BUGGY', 'DATA_SMALL_METHODS_VALID_FIXED', 'DATA_SMALL_METHODS_TEST_BUGGY',
           'DATA_SMALL_METHODS_TEST_FIXED', 'DATA_SMALL_OPS_GENERAL_BASIC_TRAIN', 'DATA_SMALL_OPS_GENERAL_BASIC_VALID',
           'DATA_SMALL_OPS_GENERAL_STRICT_TRAIN', 'DATA_SMALL_OPS_GENERAL_STRICT_VALID',
           'DATA_SMALL_OPS_GENERAL_LOOSE_TRAIN', 'DATA_SMALL_OPS_GENERAL_LOOSE_VALID',
           'DATA_SMALL_OPS_TYPED_BASIC_TRAIN', 'DATA_SMALL_OPS_TYPED_BASIC_VALID', 'DATA_SMALL_OPS_TYPED_STRICT_TRAIN',
           'DATA_SMALL_OPS_TYPED_STRICT_VALID', 'DATA_SMALL_OPS_TYPED_LOOSE_TRAIN', 'DATA_SMALL_OPS_TYPED_LOOSE_VALID']

# Cell
#hide
from typing import Callable, List
from copy import deepcopy

import sys
sys.path.append("..")

from .EditOperations import *
from .CondenseEditOperations import *
from .IOUtils import *

# Cell
def makeEditOpsFile(
    abstractSourceFile: str,
    abstractTargetFile: str,
    editOpsFile: str,
    condenser: Callable[[List[EditOperation]], List[CompoundOperation]],
    form: str = "general"
) -> None:
    """
    Determines the list of CompoundEditOperations between abstract methods given in `abstractSourceFile` and
    `abstractTargetFile`, then writes those operations in machine format to the given `editOpsFile`. The form of the
    written machine string is determined by `form`, and defaults to `"general"`. The conversion process is done with
    the given `condenser` function, which should be a function provided in the `CondenseEditOperations` module.
    """

    # get the abstract methods
    sourceMethods = readAbstractMethodsFromFile(abstractSourceFile)
    targetMethods = readAbstractMethodsFromFile(abstractTargetFile)

    # make sure the number of abstract methods in both files are equal
    if len(sourceMethods) != len(targetMethods):
        raise ValueError("makeEditOpsFile: number of methods differ in source and target files!")

    # determine edit operations
    operations = []
    for sourceMethod, targetMethod in zip(sourceMethods, targetMethods):
        operations.append(condenser(sourceMethod.getEditOperationsTo(targetMethod)))

    # write the edit operations to the file
    writeCompoundOperationsToFile(editOpsFile, operations, form)

# Cell
# abstract method files
DATA_SMALL_METHODS_TRAIN_BUGGY = "../data/small/abstract_methods/train_buggy.txt"
DATA_SMALL_METHODS_TRAIN_FIXED = "../data/small/abstract_methods/train_fixed.txt"

DATA_SMALL_METHODS_VALID_BUGGY = "../data/small/abstract_methods/valid_buggy.txt"
DATA_SMALL_METHODS_VALID_FIXED = "../data/small/abstract_methods/valid_fixed.txt"

DATA_SMALL_METHODS_TEST_BUGGY  = "../data/small/abstract_methods/test_buggy.txt"
DATA_SMALL_METHODS_TEST_FIXED  = "../data/small/abstract_methods/test_fixed.txt"

# Cell
# edit operation files -- general form
DATA_SMALL_OPS_GENERAL_BASIC_TRAIN =  "../data/small/edit_ops/general/basic/train.txt"
DATA_SMALL_OPS_GENERAL_BASIC_VALID =  "../data/small/edit_ops/general/basic/valid.txt"

DATA_SMALL_OPS_GENERAL_STRICT_TRAIN = "../data/small/edit_ops/general/strict/train.txt"
DATA_SMALL_OPS_GENERAL_STRICT_VALID = "../data/small/edit_ops/general/strict/valid.txt"

DATA_SMALL_OPS_GENERAL_LOOSE_TRAIN =  "../data/small/edit_ops/general/loose/train.txt"
DATA_SMALL_OPS_GENERAL_LOOSE_VALID =  "../data/small/edit_ops/general/loose/valid.txt"

# edit operation files -- typed form
DATA_SMALL_OPS_TYPED_BASIC_TRAIN =  "../data/small/edit_ops/typed/basic/train.txt"
DATA_SMALL_OPS_TYPED_BASIC_VALID =  "../data/small/edit_ops/typed/basic/valid.txt"

DATA_SMALL_OPS_TYPED_STRICT_TRAIN = "../data/small/edit_ops/typed/strict/train.txt"
DATA_SMALL_OPS_TYPED_STRICT_VALID = "../data/small/edit_ops/typed/strict/valid.txt"

DATA_SMALL_OPS_TYPED_LOOSE_TRAIN =  "../data/small/edit_ops/typed/loose/train.txt"
DATA_SMALL_OPS_TYPED_LOOSE_VALID =  "../data/small/edit_ops/typed/loose/valid.txt"