-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsl-converter.py
30 lines (24 loc) · 993 Bytes
/
psl-converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def convertFile(pslTempFileName,pslObjFileName):
communities = dict()
pslCommunities = open(pslTempFileName, 'r+')
for line in pslCommunities:
line = line.strip("\n")
line = line.strip(")")
if line!="":
property_id = line.split("\t")[0]
prob = line.split("\t")[1]
nodeId = int(property_id.split("(")[1].split(",")[0])
community = int(property_id.split("(")[1].split(",")[1].strip(")"))
if nodeId in communities:
if float(prob) > float(communities[nodeId][1]):
communities[nodeId] = (community,prob)
else:
communities[nodeId] = (community,prob)
pslCommFile = open(pslObjFileName, 'w+')
pslCommFile.truncate()
fileContent = ""
for key in sorted(communities):
fileContent += "x"+str(key)+": " + str(communities[key][0]) + "\n"
pslCommFile.write(fileContent)
#convertFile("testPslTemp.comm","testPsl.comm")
convertFile("psl/psl-example/data/testPslPottsTemp.comm","psl/psl-example/data/testPslPotts.comm")