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

Fixed issues with TKG and changed names of 'mine' in subgraphMining #412

Merged
merged 8 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
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
Binary file modified PAMI/subgraphMining/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion PAMI/subgraphMining/basic/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class _gSpan(ABC):

@abstractmethod
def startMine(self):
def mine(self):
"""
Run the gSpan algorithm.
"""
Expand Down
6 changes: 2 additions & 4 deletions PAMI/subgraphMining/basic/gspan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#
# obj = alg.GSpan(iFile, minSupport)
#
# obj.startMine()
#
# obj.run()
# obj.mine()
#
# frequentGraphs = obj.getFrequentSubgraphs()
#
Expand Down Expand Up @@ -65,7 +63,7 @@ def __init__(self, iFile, minSupport, outputSingleVertices=True, maxNumberOfEdge
self._memoryRSS = float()


def startMine(self):
def mine(self):

if self.maxNumberOfEdges <= 0:
return
Expand Down
4 changes: 2 additions & 2 deletions PAMI/subgraphMining/topK/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class _TKG(ABC):

@abstractmethod
def startMine(self):
def mine(self):
"""
Run the gSpan algorithm.
Run the tkg algorithm.
"""
pass

Expand Down
41 changes: 20 additions & 21 deletions PAMI/subgraphMining/topK/tkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# obj = alg.TKG(iFile, k)

# obj.startMine()
# obj.mine()

# frequentGraphs = obj.getKSubgraphs()

Expand Down Expand Up @@ -42,7 +42,6 @@ def __init__(self, iFile, k, maxNumberOfEdges=float('inf'), outputSingleVertices
self.outputGraphIds = outputGraphIds
self.outputSingleVertices = outputSingleVertices
self.maxNumberOfEdges = maxNumberOfEdges
self.frequentSubgraphs = []
self.graphCount = 0
self.patternCount = 0
self.frequentVertexLabels = []
Expand All @@ -56,7 +55,7 @@ def __init__(self, iFile, k, maxNumberOfEdges=float('inf'), outputSingleVertices
self.pruneByEdgeCount = 0


def startMine(self):
def mine(self):
"""
This Python function starts a mining process on a graph database, calculates runtime, pattern count,
and memory usage metrics.
Expand Down Expand Up @@ -359,8 +358,7 @@ def gspanDfs(self, c: _ab.DfsCode, graphDB, subgraphId):
newC.add(extension)

if self.isCanonical(newC):
subgraph = _ab.FrequentSubgraph(newC, newGraphIds, sup)
self.frequentSubgraphs.append(subgraph)
self.savePattern(_ab.FrequentSubgraph(newC, newGraphIds, sup))
self.gspanDfs(newC, graphDB, newGraphIds)


Expand Down Expand Up @@ -434,7 +432,7 @@ def findAllOnlyOneVertex(self, graphDB, outputFrequentVertices):
if outputFrequentVertices:
tempD = _ab.DfsCode()
tempD.add(_ab.ExtendedEdge(0, 0, label, label, -1))
self.frequentSubgraphs.append(_ab.FrequentSubgraph(tempD, tempSupG, sup))
self.savePattern(_ab.FrequentSubgraph(tempD, tempSupG, sup))
elif TKG.ELIMINATE_INFREQUENT_VERTICES:
for graphId in tempSupG:
g = graphDB[graphId]
Expand Down Expand Up @@ -514,33 +512,34 @@ def getMinSupport(self):
return self.minSup

def getKSubgraphs(self):
subgraphsList = self.getSubgraphsList()

""" Return the formatted subgraphs as a single string with correct formatting and newlines. """
subgraphsList = self.getSubgraphsList()
sb = []
for i, subgraph in enumerate(subgraphsList):
sb = []
subgraphDescription = [f"t # {i} * {subgraph.support}"]
dfsCode = subgraph.dfsCode

sb.append(f"t # {i} * {subgraph.support}\n")
if len(dfsCode.eeList) == 1:
ee = dfsCode.eeList[0]
sb.append(f"v 0 {ee.vLabel1}\n")
subgraphDescription.append(f"v 0 {ee.vLabel1}")
if ee.edgeLabel != -1:
sb.append(f"v 1 {ee.vLabel2}\n")
sb.append(f"e 0 1 {ee.edgeLabel}\n")
subgraphDescription.append(f"v 1 {ee.vLabel2}")
subgraphDescription.append(f"e 0 1 {ee.edgeLabel}")
else:
vLabels = dfsCode.getAllVLabels()
for j, vLabel in enumerate(vLabels):
sb.append(f"v {j} {vLabel}\n")
subgraphDescription.append(f"v {j} {vLabel}")
for ee in dfsCode.eeList:
sb.append(f"e {ee.v1} {ee.v2} {ee.edgeLabel}\n")
subgraphDescription.append(f"e {ee.v1} {ee.v2} {ee.edgeLabel}")

# Include graph IDs if the feature is enabled
if self.outputGraphIds and subgraph.setOfGraphsIds:
subgraphDescription.append("x " + " ".join(str(id) for id in subgraph.setOfGraphsIds))
sb.append('\n'.join(subgraphDescription))
return '\n\n'.join(sb)

if self.outputGraphIds:
sb.append("x " + " ".join(str(id) for id in subgraph.setOfGraphsIds))
sb.append("\n\n")
print("".join(sb))


def getSubgraphs(self):
def getSubgraphsList(self):
"""Creates a copy of the queue's contents without emptying the original queue."""
subgraphsList = list(self.kSubgraphs.queue)
subgraphsList.sort(key=lambda sg: sg.support, reverse=True)
Expand Down