def invert_rule_hierarchy(rule_hierarchy):
    """Get inverted rule hierarchy (swapped lhs and rhs)."""
    new_rule_hierarchy = {'rules': {}, 'rule_homomorphisms': {}}
    for graph, rule in rule_hierarchy['rules'].items():
        new_rule_hierarchy['rules'][graph] = rule.get_inverted_rule()
    for (source, target), (lhs_h, p_h, rhs_h) in rule_hierarchy[
        'rule_homomorphisms'].items():
        new_rule_hierarchy['rule_homomorphisms'][source, target
            ] = rhs_h, p_h, lhs_h
    return new_rule_hierarchy
