def update_cost(node1: Node, node2: Node):
    """
    Update cost for tree edit distance.
    If both are leaf node, calculate string edit distance between two labels (special token '<leaf>' will be ignored).
    If one of them is leaf node, cost is length of string in leaf node + 1.
    If neither are leaf node, cost is 0 if label1 is same with label2 othewise 1
    """
    label1 = node1.label
    label2 = node2.label
    label1_leaf = "<leaf>" in label1
    label2_leaf = "<leaf>" in label2
    if label1_leaf and label2_leaf:
        return edit_distance(label1.replace("<leaf>", ""), label2.replace("<leaf>", ""))
    elif not label1_leaf and label2_leaf:
        return 1 + len(label2.replace("<leaf>", ""))
    elif label1_leaf and not label2_leaf:
        return 1 + len(label1.replace("<leaf>", ""))
    else:
        return int(label1 != label2)

    Update cost for tree edit distance.
    If both are leaf node, calculate string edit distance between two labels (special token '<leaf>' will be ignored).
    If one of them is leaf node, cost is length of string in leaf node + 1.
    If neither are leaf node, cost is 0 if label1 is same with label2 othewise 1
    
vlmeval/dataset/utils/ccocr_evaluator/kie_evaluator.py