-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreateTrainConnect.py
82 lines (72 loc) · 1.95 KB
/
createTrainConnect.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: UTF-8 -*-
#
from numpy import *
#
import operator
import sys;
import re
import cal
#import change
#listdir
from os import listdir
#word2vec
from gensim import corpora, models, similarities
from gensim import utils, matutils
from gensim.models import word2vec
from gensim import *
#
def loadGraphDict(fileName):#
dataDict = {}
fx = open(fileName)
for line in fx.readlines():#
lineArr = re.split(' |,|\t',line.strip())#
lenth=len(lineArr)
if(lenth<2):
break;
if(lineArr[0] not in dataDict.keys()):
dataDict[str(lineArr[0])]=[str(lineArr[1])]
#
#elif(len(dataDict[str(lineArr[0])])>0)
if(lineArr[1] not in dataDict[str(lineArr[0])]):
dataDict[str(lineArr[0])].append(str(lineArr[1]))
#
#
if(lineArr[1] not in dataDict.keys()):
dataDict[str(lineArr[1])]=[str(lineArr[0])]#
#elif(len(dataDict[str(lineArr[0])])>0)
if(lineArr[0] not in dataDict[str(lineArr[1])]):
dataDict[str(lineArr[1])].append(str(lineArr[0]))#
return dataDict
#
def start():
#father="data/"
nLen = len(sys.argv);
for i in range(0, nLen):
print("argv %d:%s" %(i, sys.argv[i]));
father=str(sys.argv[1])
filename=str(sys.argv[2])
fx=open(father+'connect.txt')
fc=open(father+'trainConnect.txt','w')
ft=open(father+'testConnect.txt','w')
randomIter=random.randint(0, 3)
nowIter=0
i=0
for line in fx.readlines():
lineArr = line.strip().split()
if(nowIter==randomIter):
nowIter+=1;
#if(len(xDict[lineArr[0]])>10):
ft.write('%s %s\n'%(lineArr[0],lineArr[1]))
else:
nowIter+=1;
#if(len(xDict[lineArr[0]])>10):
fc.write('%s %s\n'%(lineArr[0],lineArr[1]))
if(nowIter>=3):
randomIter=random.randint(0, 3);
nowIter=0
i+=1
print("items="),i
fc.close()
ft.close()
if __name__=="__main__":
start()