Пример #1
0
def filter_paths(log, allowed_paths, positive=True):
    """
    Filter a log_skeleton on a specified list of paths

    Parameters
    ---------------
    log
        Log object
    allowed_paths
        Allowed/forbidden paths
    positive
        Parameter that says whether the paths
        should be kept/removed

    Returns
    ----------------
    filtered_log
        Filtered log_skeleton object
    """
    if check_is_dataframe(log):
        from pm4py.algo.filtering.pandas.paths import paths_filter
        return paths_filter.apply(log, allowed_paths, parameters={paths_filter.Parameters.POSITIVE: positive})
    else:
        from pm4py.algo.filtering.log.paths import paths_filter
        return paths_filter.apply(log, allowed_paths, parameters={paths_filter.Parameters.POSITIVE: positive})
Пример #2
0
def filter_directly_follows_relation(log: Union[EventLog, pd.DataFrame], relations: List[str], retain: bool = True) -> \
        Union[EventLog, pd.DataFrame]:
    """
    Retain traces that contain any of the specified 'directly follows' relations.
    For example, if relations == [('a','b'),('a','c')] and log [<a,b,c>,<a,c,b>,<a,d,b>]
    the resulting log will contain traces describing [<a,b,c>,<a,c,b>].

    Parameters
    ---------------
    log
        Log object
    relations
        List of activity name pairs, which are allowed/forbidden paths
    retain
        Parameter that says whether the paths
        should be kept/removed

    Returns
    ----------------
    filtered_log
        Filtered log object
    """
    if type(log) not in [pd.DataFrame, EventLog, EventStream]:
        raise Exception(
            "the method can be applied only to a traditional event log!")

    parameters = get_properties(log)
    if check_is_pandas_dataframe(log):
        from pm4py.algo.filtering.pandas.paths import paths_filter
        parameters[paths_filter.Parameters.POSITIVE] = retain
        return paths_filter.apply(log, relations, parameters=parameters)
    else:
        from pm4py.algo.filtering.log.paths import paths_filter
        parameters[paths_filter.Parameters.POSITIVE] = retain
        return paths_filter.apply(log, relations, parameters=parameters)
Пример #3
0
def filter_directly_follows_relation(log, relations, retain=True):
    """
    Retain traces that contain any of the specified 'directly follows' relations.
    For example, if relations == [('a','b'),('a','c')] and log [<a,b,c>,<a,c,b>,<a,d,b>]
    the resulting log will contain traces describing [<a,b,c>,<a,c,b>].

    Parameters
    ---------------
    log
        Log object
    relations
        List of activity name pairs, which are allowed/forbidden paths
    retain
        Parameter that says whether the paths
        should be kept/removed

    Returns
    ----------------
    filtered_log
        Filtered log object
    """
    if check_is_dataframe(log):
        from pm4py.algo.filtering.pandas.paths import paths_filter
        return paths_filter.apply(
            log,
            relations,
            parameters={paths_filter.Parameters.POSITIVE: retain})
    else:
        from pm4py.algo.filtering.log.paths import paths_filter
        return paths_filter.apply(
            log,
            relations,
            parameters={paths_filter.Parameters.POSITIVE: retain})
Пример #4
0
 def test_filtering_paths(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     input_log = os.path.join(INPUT_DATA_DIR, "running-example.csv")
     dataframe = csv_import_adapter.import_dataframe_from_path(input_log, sep=',')
     df3 = paths_filter.apply(dataframe, [("examine casually", "check ticket")], {"positive": False})
     del df3
     df3 = paths_filter.apply(dataframe, [("examine casually", "check ticket")], {"positive": True})
     del df3
Пример #5
0
 def test_filtering_paths(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     input_log = os.path.join(INPUT_DATA_DIR, "running-example.csv")
     dataframe = pd.read_csv(input_log)
     dataframe = dataframe_utils.convert_timestamp_columns_in_df(dataframe)
     df3 = paths_filter.apply(dataframe, [("examine casually", "check ticket")],
                              {paths_filter.Parameters.POSITIVE: False})
     del df3
     df3 = paths_filter.apply(dataframe, [("examine casually", "check ticket")],
                              {paths_filter.Parameters.POSITIVE: True})
     del df3
Пример #6
0
def apply(dataframe, filter, parameters=None):
    """

    :param dataframe:
    :param filter:
    :param parameters:
    :return:
    """
    if parameters is None:
        parameters = {}

    parameters[constants.PARAMETER_CONSTANT_ATTRIBUTE_KEY] = filter[1][0]
    parameters["positive"] = True

    paths_to_filter = []

    for p in filter[1][1]:
        paths_to_filter.append(p.split("@@"))

    return paths_filter.apply(dataframe,
                              paths_to_filter,
                              parameters=parameters)