Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Flat Transactions #443

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")