from typing import Counter


def predict_license_expression(license_matches):
    """
    Return the best-effort predicted license expression given a list of LicenseMatch
    objects.
    """
    unknown_expressions = ['unknown', 'warranty-disclaimer']
    
    license_expressions = (
        license_match.license_expression for license_match in license_matches
    )
    known_expressions = [
        le for le in license_expressions if le not in unknown_expressions
    ]
    if not known_expressions:
        return "unknown"
    
    license_expressions_counts = dict(Counter(known_expressions).most_common())
    highest_count = list(license_expressions_counts.values())[0]
    
    top_license_expressions = [
        expression
        for expression, count in license_expressions_counts.items()
        if count == highest_count
    ]

    if len(top_license_expressions) == 1:
        return top_license_expressions[0]

    top_license_matches = [
        license_match
        for license_match in license_matches
        if license_match.license_expression in top_license_expressions
    ]

    max_match_length = max([
        license_match.matched_length
        for license_match in top_license_matches
    ])
    license_expression_prediction = next(
        license_match.license_expression
        for license_match in top_license_matches
        if license_match.matched_length is max_match_length
    )
    return license_expression_prediction