Ejemplo n.º 1
0
def get_act_correspondence(activities, parameters=None):
    """
    Gets an encoding for each activity

    Parameters
    --------------
    activities
        Activities of the two languages
    parameters
        Parameters

    Returns
    -------------
    encoding
        Encoding into hex characters
    """
    if parameters is None:
        parameters = {}

    shared_obj = SharedObj()
    ret = {}
    for act in activities:
        get_new_char(act, shared_obj)
        ret[act] = shared_obj.mapping_dictio[act]

    return ret
Ejemplo n.º 2
0
def form_encoding_dictio_from_log(log, parameters=None):
    """
    Forms the encoding dictionary from the current log

    Parameters
    -------------
    log
        Event log
    parameters
        Parameters of the algorithm

    Returns
    -------------
    encoding_dictio
        Encoding dictionary
    """
    if parameters is None:
        parameters = {}

    activity_key = parameters[
        PARAMETER_CONSTANT_ACTIVITY_KEY] if PARAMETER_CONSTANT_ACTIVITY_KEY in parameters else xes.DEFAULT_NAME_KEY

    shared_obj = SharedObj()

    activities = attributes_get.get_attribute_values(log,
                                                     activity_key,
                                                     parameters=parameters)

    mapping = {}

    for act in activities:
        get_new_char(act, shared_obj)
        mapping[act] = shared_obj.mapping_dictio[act]

    return mapping
Ejemplo n.º 3
0
def pt_to_regex(tree, rec_depth=0, shared_obj=None, parameters=None):
    """
    Transforms a process tree to a regular expression

    NB: The conversion is not yet working with trees containing an AND and/or an OR operator!

    Parameters
    ------------
    tree
        Process tree
    parameters
        Possible parameters of the algorithm
    """
    if parameters is None:
        parameters = {}

    if shared_obj is None:
        shared_obj = SharedObj()

    stru = ""

    if tree.operator is not None:
        contains_tau = len(list(child for child in tree.children if child.operator is None and child.label is None)) > 0
        children_rep = []
        for child in tree.children:
            rep, shared_obj = pt_to_regex(child, rec_depth=rec_depth + 1, shared_obj=shared_obj, parameters=parameters)
            children_rep.append(rep)
        if tree.operator == pt_operator.Operator.SEQUENCE:
            children_rep = [x for x in children_rep if not x is None]
            stru = "(" + "".join(children_rep) + ")"
        elif tree.operator == pt_operator.Operator.XOR:
            children_rep = [x for x in children_rep if not x is None]
            stru = "(" + "|".join(children_rep) + ")"
            if contains_tau:
                stru = "(" + stru + "?)"
        elif tree.operator == pt_operator.Operator.LOOP:
            children_rep = [x for x in children_rep if not x is None]
            if len(children_rep) == 1:
                stru = "(" + children_rep[0] + ")+"
            else:
                stru = "(" + "".join(children_rep) + ")*" + children_rep[0]
        elif tree.operator == pt_operator.Operator.PARALLEL:
            raise Exception("the conversion is not yet working with trees containing an AND and/or an OR operator!")
        elif tree.operator == pt_operator.Operator.OR:
            raise Exception("the conversion is not yet working with trees containing an AND and/or an OR operator!")

    elif tree.label is not None:
        if tree.label not in shared_obj.mapping_dictio:
            get_new_char(tree.label, shared_obj)
        stru = shared_obj.mapping_dictio[tree.label]
    elif tree.label is None:
        return None, shared_obj

    if rec_depth == 0:
        ret = "^" + stru + "$", shared_obj.mapping_dictio
        # print(ret)
        return ret

    return stru, shared_obj
Ejemplo n.º 4
0
def form_encoding_dictio_from_two_logs(log1: EventLog, log2: EventLog, parameters: Optional[Dict[str, Any]] = None) -> \
Dict[str, str]:
    """
    Forms the encoding dictionary from a couple of logs

    Parameters
    ----------------
    log1
        First log
    log2
        Second log
    parameters
        Parameters of the algorithm

    Returns
    ----------------
    encoding_dictio
        Encoding dictionary
    """
    from pm4py.statistics.attributes.log import get as attributes_get

    if parameters is None:
        parameters = {}

    activity_key = parameters[
        PARAMETER_CONSTANT_ACTIVITY_KEY] if PARAMETER_CONSTANT_ACTIVITY_KEY in parameters else xes.DEFAULT_NAME_KEY

    shared_obj = SharedObj()

    activities_log_1 = attributes_get.get_attribute_values(
        log1, activity_key, parameters=parameters)
    activities_log_2 = attributes_get.get_attribute_values(
        log2, activity_key, parameters=parameters)

    mapping = {}

    for act in activities_log_1:
        if act not in mapping:
            get_new_char(act, shared_obj)
            mapping[act] = shared_obj.mapping_dictio[act]

    for act in activities_log_2:
        if act not in mapping:
            get_new_char(act, shared_obj)
            mapping[act] = shared_obj.mapping_dictio[act]

    return mapping