def filter_relation(relation, relation_type, relation_subtype, entity_ids):
    """
    Function to filter a relation for given: type, subtype and entitiy ids.

    Args:
        relation (dict): dictionary representing a relation.
        relation_type (str): relation type.
        relation_subtype (str): relation subtype.
        entity_ids (set): entitiy ids.

    Returns:
        bool: True is a relation match the filter, False otherwise.
    """
    return (
        relation['relation_type'] == relation_type
        and relation['relation_subtype'] == relation_subtype and
        (relation['source'] in entity_ids or relation['target'] in entity_ids)
    )