def compute_files(user1, user2, file_list, dir_pre, start_num):

    """
    Compute the smatch scores for a file list between two users
    Args:
    user1: user 1 name
    user2: user 2 name
    file_list: file list
    dir_pre: the file location prefix
    start_num: the number of restarts in smatch
    Returns:
    smatch f score.

    """
    match_total = 0
    test_total = 0
    gold_total = 0
    for fi in file_list:
        file1 = dir_pre + user1 + "/" + fi + ".txt"
        file2 = dir_pre + user2 + "/" + fi + ".txt"
        if not os.path.exists(file1):
            print("*********Error: ", file1, "does not exist*********", file=ERROR_LOG)
            return -1.00
        if not os.path.exists(file2):
            print("*********Error: ", file2, "does not exist*********", file=ERROR_LOG)
            return -1.00
        try:
            file1_h = open(file1, "r")
            file2_h = open(file2, "r")
        except IOError:
            print("Cannot open the files", file1, file2, file=ERROR_LOG)
            break
        cur_amr1 = smatch.get_amr_line(file1_h)
        cur_amr2 = smatch.get_amr_line(file2_h)
        if cur_amr1 == "":
            print("AMR 1 is empty", file=ERROR_LOG)
            continue
        if cur_amr2 == "":
            print("AMR 2 is empty", file=ERROR_LOG)
            continue
        amr1 = amr.AMR.parse_AMR_line(cur_amr1)
        amr2 = amr.AMR.parse_AMR_line(cur_amr2)
        test_label = "a"
        gold_label = "b"
        amr1.rename_node(test_label)
        amr2.rename_node(gold_label)
        (test_inst, test_rel1, test_rel2) = amr1.get_triples()
        (gold_inst, gold_rel1, gold_rel2) = amr2.get_triples()
        if verbose:
            print("Instance triples of file 1:", len(test_inst), file=DEBUG_LOG)
            print(test_inst, file=DEBUG_LOG)
            print("Attribute triples of file 1:", len(test_rel1), file=DEBUG_LOG)
            print(test_rel1, file=DEBUG_LOG)
            print("Relation triples of file 1:", len(test_rel2), file=DEBUG_LOG)
            print(test_rel2, file=DEBUG_LOG)
            print("Instance triples of file 2:", len(gold_inst), file=DEBUG_LOG)
            print(gold_inst, file=DEBUG_LOG)
            print("Attribute triples of file 2:", len(gold_rel1), file=DEBUG_LOG)
            print(gold_rel1, file=DEBUG_LOG)
            print("Relation triples of file 2:", len(gold_rel2), file=DEBUG_LOG)
            print(gold_rel2, file=DEBUG_LOG)
        (best_match, best_match_num) = smatch.get_best_match(test_inst, test_rel1, test_rel2,
                                                             gold_inst, gold_rel1, gold_rel2,
                                                             test_label, gold_label)
        if verbose:
            print("best match number", best_match_num, file=DEBUG_LOG)
            print("Best Match:", smatch.print_alignment(best_match, test_inst, gold_inst), file=DEBUG_LOG)
        match_total += best_match_num
        test_total += (len(test_inst) + len(test_rel1) + len(test_rel2))
        gold_total += (len(gold_inst) + len(gold_rel1) + len(gold_rel2))
        smatch.match_triple_dict.clear()
    (precision, recall, f_score) = smatch.compute_f(match_total, test_total, gold_total)
    return "%.2f" % f_score
def compute_files ( user1 , user2 , file_list , dir_pre , start_num ) : match_total = 0 test_total = 0 gold_total = 0 for fi in file_list : file1 = dir_pre + user1 + "/" + fi + ".txt" file2 = dir_pre + user2 + "/" + fi + ".txt" if not os . path . exists ( file1 ) : print ( "*********Error: " , file1 , "does not exist*********" , file = ERROR_LOG ) return - 1.00 if not os . path . exists ( file2 ) : print ( "*********Error: " , file2 , "does not exist*********" , file = ERROR_LOG ) return - 1.00 try : file1_h = open ( file1 , "r" ) file2_h = open ( file2 , "r" ) except IOError : print ( "Cannot open the files" , file1 , file2 , file = ERROR_LOG ) break cur_amr1 = smatch . get_amr_line ( file1_h ) cur_amr2 = smatch . get_amr_line ( file2_h ) if cur_amr1 == "" : print ( "AMR 1 is empty" , file = ERROR_LOG ) continue if cur_amr2 == "" : print ( "AMR 2 is empty" , file = ERROR_LOG ) continue amr1 = amr . AMR . parse_AMR_line ( cur_amr1 ) amr2 = amr . AMR . parse_AMR_line ( cur_amr2 ) test_label = "a" gold_label = "b" amr1 . rename_node ( test_label ) amr2 . rename_node ( gold_label ) ( test_inst , test_rel1 , test_rel2 ) = amr1 . get_triples ( ) ( gold_inst , gold_rel1 , gold_rel2 ) = amr2 . get_triples ( ) if verbose : print ( "Instance triples of file 1:" , len ( test_inst ) , file = DEBUG_LOG ) print ( test_inst , file = DEBUG_LOG ) print ( "Attribute triples of file 1:" , len ( test_rel1 ) , file = DEBUG_LOG ) print ( test_rel1 , file = DEBUG_LOG ) print ( "Relation triples of file 1:" , len ( test_rel2 ) , file = DEBUG_LOG ) print ( test_rel2 , file = DEBUG_LOG ) print ( "Instance triples of file 2:" , len ( gold_inst ) , file = DEBUG_LOG ) print ( gold_inst , file = DEBUG_LOG ) print ( "Attribute triples of file 2:" , len ( gold_rel1 ) , file = DEBUG_LOG ) print ( gold_rel1 , file = DEBUG_LOG ) print ( "Relation triples of file 2:" , len ( gold_rel2 ) , file = DEBUG_LOG ) print ( gold_rel2 , file = DEBUG_LOG ) ( best_match , best_match_num ) = smatch . get_best_match ( test_inst , test_rel1 , test_rel2 , gold_inst , gold_rel1 , gold_rel2 , test_label , gold_label ) if verbose : print ( "best match number" , best_match_num , file = DEBUG_LOG ) print ( "Best Match:" , smatch . print_alignment ( best_match , test_inst , gold_inst ) , file = DEBUG_LOG ) match_total += best_match_num test_total += ( len ( test_inst ) + len ( test_rel1 ) + len ( test_rel2 ) ) gold_total += ( len ( gold_inst ) + len ( gold_rel1 ) + len ( gold_rel2 ) ) smatch . match_triple_dict . clear ( ) ( precision , recall , f_score ) = smatch . compute_f ( match_total , test_total , gold_total ) return "%.2f" % f_score
Compute the smatch scores for a file list between two users
    Args:
    user1: user 1 name
    user2: user 2 name
    file_list: file list
    dir_pre: the file location prefix
    start_num: the number of restarts in smatch
    Returns:
    smatch f score.