Ejemplo n.º 1
0
def get_frequency(G_q, train_g_path):
    """
    # Projecting a Query Graph to BoFG histogram
    """
    train_lst = fn.get_file_list(train_g_path, ".g")
    freq_lst = []
    for g_tr in train_lst:
        G_tr = nx.read_gpickle(train_g_path + g_tr)
        # Count the frequency of each G_tr in G_q
        # Check that Node labels of G_tr belongs to that of G_q
        with open(train_g_path + g_tr[:-2] + ".nodelabel", "r") as nl:
            G_tr_nlabels = json.load(nl)
        G_q_nlabels = [int(n_tup[1]["label"]) for n_tup in G_q.nodes(data=True)]
        if fn.is_subset(G_tr_nlabels, G_q_nlabels):
            # print G_tr_nlabels, G_tr.edges(data=True)
            nm = iso.numerical_node_match("label", 1)
            em = iso.numerical_edge_match("weight", 0)
            GM = iso.GraphMatcher(G_q, G_tr, node_match=nm, edge_match=em)

            frequency = len(list(GM.subgraph_isomorphisms_iter()))
            if frequency > 0:
                BoFG_ID = int(g_tr[-5:-2])
                freq_lst.append((BoFG_ID, frequency))

    return freq_lst
Ejemplo n.º 2
0
def get_frequency(G_q, train_g_path):
    """
    # Projecting a Query Graph to BoFG histogram
    """
    train_lst = fn.get_file_list(train_g_path, '.g')
    freq_lst = []
    for g_tr in train_lst:
        G_tr = nx.read_gpickle(train_g_path + g_tr)
        # Count the frequency of each G_tr in G_q
        # Check that Node labels of G_tr belongs to that of G_q
        with open(train_g_path + g_tr[:-2] + '.nodelabel', 'r') as nl:
            G_tr_nlabels = json.load(nl)
        G_q_nlabels = [
            int(n_tup[1]['label']) for n_tup in G_q.nodes(data=True)
        ]
        if fn.is_subset(G_tr_nlabels, G_q_nlabels):
            # print G_tr_nlabels, G_tr.edges(data=True)
            nm = iso.numerical_node_match('label', 1)
            em = iso.numerical_edge_match('weight', 0)
            GM = iso.GraphMatcher(G_q, G_tr, node_match=nm, edge_match=em)

            frequency = len(list(GM.subgraph_isomorphisms_iter()))
            if frequency > 0:
                BoFG_ID = int(g_tr[-5:-2])
                freq_lst.append((BoFG_ID, frequency))

    return freq_lst
Ejemplo n.º 3
0
            G_q.add_edge( v1, v2, weight=order_dist )


    
"""
# Projecting a Query Graph to BoFG histogram
"""
train_path = 'train/model_1/graph/'
train_lst = fn.get_file_list( train_path, '.g' )
for g_tr in train_lst:
    G_tr = nx.read_gpickle( train_path + g_tr )
    # Count the frequency of each G_tr in G_q
    # Check that Node labels of G_tr belongs to that of G_q
    with open( train_path + g_tr[:-2] + '.nodelabel', 'r') as nl:
        G_tr_nlabels = json.load( nl )
    G_q_nlabels = [ int(n_tup[1]['label']) for n_tup in G_q.nodes(data=True)]
    if fn.is_subset( G_tr_nlabels, G_q_nlabels ):
        # print G_tr_nlabels, G_tr.edges(data=True)
        nm = iso.numerical_node_match('label', 1)
        em = iso.numerical_edge_match('weight', 0)
        GM = iso.GraphMatcher( G_q, G_tr, node_match=nm, edge_match=em )
#==============================================================================
#         for subgraph in GM.subgraph_isomorphisms_iter():
#             print subgraph
#==============================================================================
        if len(list(GM.subgraph_isomorphisms_iter())) > 0:
            BoFG_ID = int( g_tr[-5:-2] )
            

    
Ejemplo n.º 4
0
        if v1 == v2:  # Remove Nodes self to self
            del G_q_od[v1][v2]
        else:  # Modify Weights of Other Nodes & Assign them to Graph G
            # Edge Label
            order_dist = G_q_od[v1][v2]
            order_dist -= 1
            G_q.add_edge(v1, v2, weight=order_dist)
"""
# Projecting a Query Graph to BoFG histogram
"""
train_path = 'train/model_1/graph/'
train_lst = fn.get_file_list(train_path, '.g')
for g_tr in train_lst:
    G_tr = nx.read_gpickle(train_path + g_tr)
    # Count the frequency of each G_tr in G_q
    # Check that Node labels of G_tr belongs to that of G_q
    with open(train_path + g_tr[:-2] + '.nodelabel', 'r') as nl:
        G_tr_nlabels = json.load(nl)
    G_q_nlabels = [int(n_tup[1]['label']) for n_tup in G_q.nodes(data=True)]
    if fn.is_subset(G_tr_nlabels, G_q_nlabels):
        # print G_tr_nlabels, G_tr.edges(data=True)
        nm = iso.numerical_node_match('label', 1)
        em = iso.numerical_edge_match('weight', 0)
        GM = iso.GraphMatcher(G_q, G_tr, node_match=nm, edge_match=em)
        #==============================================================================
        #         for subgraph in GM.subgraph_isomorphisms_iter():
        #             print subgraph
        #==============================================================================
        if len(list(GM.subgraph_isomorphisms_iter())) > 0:
            BoFG_ID = int(g_tr[-5:-2])