import sys

# display usage message
def usage(bin_name):
    print("Usage: python %s <graph_file_1> <graph_file_2>" % bin_name)

# parse arguments
def parse(bin_name,args):
    # accept only the two required arguments
    if(len(args)!=2):
        # case not, display usage message
        usage(bin_name)
        # and quit
        sys.exit(0)
    # case two supplied, return the two parms
    return args[0],args[1]

def get_edge_list(graph):
    edge_list=[]
    previous=""
    for line in open(graph):
        if previous!="":
	    edge_list.append((previous,line.strip()))
	previous=line.strip()
    return edge_list

def get_intersect(g1,g2):
    inter=[]
    for edge in g1:
        if edge in g2:
            inter.append(edge)
    return inter

# Main itself
def main(graph1,graph2):
    g1 = get_edge_list(graph1)
    g2 = get_edge_list(graph2)
    g1g2 = get_intersect(g1,g2)
    g2g1 = get_intersect(g2,g1)
    print("|G1|: %d |G2|: %d |G1G2|: %d |G2G1|: %d ||G1G2|/|G1+G2||: %f ||G1G2|/|G2||: %f ||G2G1|/|G1||: %f" % (len(g1),len(g2),len(g1g2),len(g2g1),len(g1g2)/(float)(len(g1)+len(g2)-len(g1g2)),len(g1g2)/(float)(len(g2)),len(g2g1)/(float)(len(g1))))

# Entry Point
# Check who is calling
# By now, only direct calls are supported

if __name__ == '__main__':
        # start parsing args
        graph1,graph2=parse(sys.argv[0],sys.argv[1:])

        # if ok, call main
        main(graph1,graph2)
else:
        # Not Supported. Working on it.
        print("Module import not supported yet!")
        #So, exiting
        sys.exit(0)
