Skip to content

Commit

Permalink
Merge pull request #443 from choubeyy/main
Browse files Browse the repository at this point in the history
Added Flat Transactions
  • Loading branch information
udayRage authored Jun 12, 2024
2 parents 607871f + f021a38 commit 3acd331
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions PAMI/extras/graph/flatTransactions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# The goal of the below is to obtain flat transactions from the output of subgraph mining
# Flat transactions are transactions that contain the list of subgraphs that are present in a graph
#
# from PAMI.extras.graph import flatTransactions as ft
#
# obj = ft.FlatTransactions()
#
# flatTransactions = obj.getFlatTransactions(fidGidDictMap)
# (fidGidDictMap is a list of dictionaries with keys 'FID' and 'GIDs'
# FID is subgraph/fragment ID and GIDs are the graph IDs that contain the subgraph)
#
# obj.saveFlatTransactions(oFile)

class FlatTransactions:

def __init__(self):
self.flatTransactions = {}
def getFlatTransactions(self, fidGidDictMap):
"""
fidGidMap is a list of dictionaries with keys 'FID' and 'GIDs'
An example of this type of output is: getSubgraphGraphMapping in GSpan class
from subgraphMining/basic/gspan.py in PAMI
"""
graphToSubgraphs = {}

for mapping in fidGidDictMap:
fid = mapping['FID']
gids = mapping['GIDs']

for gid in gids:
if gid not in graphToSubgraphs:
graphToSubgraphs[gid] = []
graphToSubgraphs[gid].append(fid)

for gid in graphToSubgraphs:
graphToSubgraphs[gid] = sorted(set(graphToSubgraphs[gid]))

self.flatTransactions = graphToSubgraphs
return self.flatTransactions

def saveFlatTransactions(self, oFile):
"""
Save the available flat transactions to a file
"""
with open(oFile, 'w') as f:
for _, fids in self.flatTransactions.items():
f.write(f"{' '.join(map(str, fids))}\n")

0 comments on commit 3acd331

Please sign in to comment.