def to_evaluation_format(interprets):
    """
    Converts interpretations to the proper format for evaluation scripts.

    :param interprets: interpretations of all queries {qid: [{men:en, ..}, ..], ..}
    :return: string, each line is in the format of "qid confidence_score   en1 en2 ... "
    """
    out_str = ""
    for qid, q_interprets in sorted(interprets.items(), key=lambda item: item[0]):
        unique_interprets = set()
        for interpret in q_interprets:
            if len(interpret) == 0:
                continue
            unique_interprets.add(tuple(sorted(set(interpret.values()))))

        for interpret in unique_interprets:
            # For the sake of code readability, we set the confidence score to 1,
            # but it can be set to the average score of entities (in the interpretation set).
            conf_score = "1"
            out_str += qid + "\t" + conf_score + "\t" + "\t".join(interpret) + "\n"
    return out_str