def total_relation_matched(A_tlinks, B_tlinks, B_relations, B_tg): 
	global outfile 
	count = 0 
	for tlink in A_tlinks.split('\n'): 
		if tlink.strip() == '': 
			continue 
		if debug >= 2: 
			print tlink
		x, y, rel = get_x_y_rel(tlink) 
		foo = relation_to_timegraph.interval_rel_X_Y(x, y, B_tg, rel, 'evaluation')
		if re.search(get_entity_rel(tlink.strip()), B_relations): 
			count += 1 
			if debug >= 2: 
				print x, y, rel, 'True' 
			continue 
		if debug >= 2: 
			print x, y, rel, foo[1]
		if re.search('true', foo[1]):
			count += 1 
		else:
			## ignore the false ones, since they are false from our annotation; but keep the UNKNOWN ones
			if True:
				#foo[1] == 'UNKNOWN':
				if debug >= 1: 
					print x, y, rel, foo[1]
					print y, x, reverse_relation(rel)
				outfile.write('tlink\t'+ x + '\t' + y + '\t' + rel + '\t' + '-'.join(sys.argv[2].split('/')).strip('-') + '\t' + foo[1] + '\n')
				outfile.write('tlink\t'+ y + '\t' + x + '\t' + reverse_relation(rel) + '\t' + '-'.join(sys.argv[2].split('/')).strip('-') + '\t' + foo[1] + '\n')
	return count 
def total_implicit_matched(system_reduced, gold_reduced, gold_tg): 
    count = 0 
    for tlink in system_reduced.split('\n'): 
        if tlink.strip() == '': 
            continue 
        if debug >= 2: 
            print tlink
        if re.search(tlink, gold_reduced): 
            continue 

        x, y, rel = get_x_y_rel(tlink) 
        foo = relation_to_timegraph.interval_rel_X_Y(x, y, gold_tg, rel, 'evaluation')
        if debug >= 2: 
            print x, y, rel, foo[1]
        if re.search('true', foo[1]):
            count += 1 
    return count 
def total_implicit_matched(system_reduced, gold_reduced, gold_tg):
    count = 0
    for tlink in system_reduced.split('\n'):
        if tlink.strip() == '':
            continue
        if debug >= 2:
            print(tlink)
        if re.search(tlink, gold_reduced):
            continue

        x, y, rel = get_x_y_rel(tlink)
        foo = relation_to_timegraph.interval_rel_X_Y(x, y, gold_tg, rel,
                                                     'evaluation')
        if debug >= 2:
            print(x, y, rel, foo[1])
        if re.search('true', foo[1]):
            count += 1
    return count
def total_relation_matched(A_tlinks, B_tlinks, B_relations, B_tg):
    count = 0
    for tlink in A_tlinks.split('\n'):
        if tlink.strip() == '':
            continue
        if debug >= 2:
            print tlink
        x, y, rel = get_x_y_rel(tlink)
        foo = relation_to_timegraph.interval_rel_X_Y(x, y, B_tg, rel, 'evaluation')
        if re.search(get_entity_rel(tlink.strip()), B_relations):
            count += 1
            if debug >= 2:
                print 'True'
            continue
        if debug >= 2:
            print x, y, rel, foo[1]
        if re.search('true', foo[1]):
            count += 1
    return count
def total_relation_matched(A_tlinks, B_tlinks, B_relations, B_tg): 
    count = 0 
    for tlink in A_tlinks.split('\n'): 
        if tlink.strip() == '': 
            continue 
        if debug >= 2: 
            print tlink
        x, y, rel = get_x_y_rel(tlink) 
        foo = relation_to_timegraph.interval_rel_X_Y(x, y, B_tg, rel, 'evaluation')
        if re.search(get_entity_rel(tlink.strip()), B_relations): 
            count += 1 
            if debug >= 2: 
                print 'True' 
            continue 
        if debug >= 2: 
            print x, y, rel, foo[1]
        if re.search('true', foo[1]):
            count += 1 
    return count