def scope_match_normalized(gold_inst, system_inst):
    """Given a gold NegationInstance and matched system NegationInstance, calcuate the overlap of scopes
    between them, normalizing by scope length.

    Args:
        gold_inst: The gold NegationInstance.
        system_inst: The system NegationInstance.

    Returns: A triple consisting of 
      1) scope precision, defined as num_matched_tokens / len(system_inst.scope);
      2) scope recall, defined as num_matched_tokens / len(gold_inst.scope);
      3) scope F1.
    """
    # Count tokens that match up between scopes
    num_matched_tokens = 0
    for token1 in gold_inst.scope:
        for token2 in system_inst.scope:
            if token1 == token2: # matching by position and word form
                num_matched_tokens += 1


    # Determine precision and recall for this scope
    if len(gold_inst.scope) == 0 and len(system_inst.scope) == 0:
        precision = 1.0
        recall = 1.0
    elif len(gold_inst.scope) == 0 and len(system_inst.scope) > 0:
        precision = 0.0
        recall = 1.0
    elif len(gold_inst.scope) > 0 and len(system_inst.scope) == 0:
        precision = 1.0
        recall = 0.0
    else:
        precision = num_matched_tokens / len(system_inst.scope)
        recall = num_matched_tokens / len(gold_inst.scope)
            
    f1 = 2*precision*recall/(precision+recall) if precision+recall else 0.0

    return precision, recall, f1