def entity_similarity(K, R):
    """
    The similarity metric for chains is based on how many common mentions two chains share (Luo, 2005):
    similarity  = 2 * |K intersects R|/ (|K| + |R|)
    :param K: an entity (set of mentions) from the key entities
    :param R: an entity (set of mentions) from the response entities
    :return: similarity  = 2 * |K intersects R|/ (|K| + |R|)
    """
    return 2.0 * len(K.intersection(R)) / (len(K) + len(R))