def hierarchical_redundancy(rdf, fix=False):
    """Check for and optionally remove extraneous skos:broader relations.

    :param Graph rdf: An rdflib.graph.Graph object.
    :param bool fix: Fix the problem by removing skos:broader relations between
        concepts that are otherwise connected by skos:broaderTransitive.
    """
    for conc, parent1 in rdf.subject_objects(SKOS.broader):
        for parent2 in rdf.objects(conc, SKOS.broader):
            if parent1 == parent2:
                continue  # must be different
            if parent2 in rdf.transitive_objects(parent1, SKOS.broader):
                if fix:
                    logging.warning(
                        "Eliminating redundant hierarchical relationship: "
                        "%s skos:broader %s",
                        conc, parent2)
                    rdf.remove((conc, SKOS.broader, parent2))
                    rdf.remove((conc, SKOS.broaderTransitive, parent2))
                    rdf.remove((parent2, SKOS.narrower, conc))
                    rdf.remove((parent2, SKOS.narrowerTransitive, conc))
                else:
                    logging.warning(
                        "Redundant hierarchical relationship "
                        "%s skos:broader %s found, but not eliminated "
                        "because eliminate_redundancy is not set",
                        conc, parent2)