4
4
import random
5
5
import json
6
6
import os
7
+ import codecs
7
8
from timeparameters import *
8
9
9
10
PERSON_PREFIX = "http://www.ldbc.eu/ldbc_socialnet/1.0/data/pers"
10
11
COUNTRY_PREFIX = "http://dbpedia.org/resource/"
12
+ SEED = 1
11
13
12
14
def findNameParameters (names , amount = 100 ):
13
15
srtd = sorted (names ,key = lambda x : - x [1 ])
14
- return map (lambda x :x [0 ], srtd [:amount - 1 ])
16
+ res = []
17
+ for t in srtd :
18
+ if t [1 ] > 100 and t [1 ] < 150 :
19
+ res .append (t [0 ])
20
+ return res
15
21
16
22
class JSONSerializer :
17
23
def __init__ (self ):
@@ -26,7 +32,7 @@ def registerHandler(self, handler, inputParams):
26
32
self .inputs .append (inputParams )
27
33
28
34
def writeJSON (self ):
29
- output = open (self .outputFile , "w" )
35
+ output = codecs . open (self .outputFile , "w" , encoding = "utf-8 " )
30
36
31
37
if len (self .inputs ) == 0 :
32
38
return
@@ -38,7 +44,8 @@ def writeJSON(self):
38
44
handler = self .handlers [j ]
39
45
data = self .inputs [j ][i ]
40
46
jsonDict .update (handler (data ))
41
- output .write (json .dumps (jsonDict )+ "\n " )
47
+ output .write (json .dumps (jsonDict , ensure_ascii = False ))
48
+ output .write ("\n " )
42
49
43
50
output .close ()
44
51
@@ -58,7 +65,7 @@ def handleCountryParam(Country):
58
65
return {"Country" :Country , "CountryURI" : (COUNTRY_PREFIX + Country )}
59
66
60
67
def handleTagParam (tag ):
61
- return {"Tag" : tag . encode ( "utf-8" ) }
68
+ return {"Tag" : tag }
62
69
63
70
def handleTagTypeParam (tagType ):
64
71
return {"TagType" : tagType }
@@ -67,7 +74,7 @@ def handleHSParam((HS0, HS1)):
67
74
return {"HS0" :HS0 , "HS1" :HS1 }
68
75
69
76
def handleFirstNameParam (firstName ):
70
- return {"Name" :firstName . decode ( "utf-8" ) }
77
+ return {"Name" :firstName }
71
78
72
79
def handlePairPersonParam ((person1 , person2 )):
73
80
return {"Person1ID" :person1 , "Person2ID" :person2 , "Person2URI" :(PERSON_PREFIX + str (person2 )), "Person1URI" :(PERSON_PREFIX + str (person1 ))}
@@ -87,7 +94,8 @@ def main(argv=None):
87
94
factorFiles = []
88
95
friendsFiles = []
89
96
outdir = argv [2 ]+ "/"
90
-
97
+ random .seed (SEED )
98
+
91
99
for file in os .listdir (indir ):
92
100
if file .endswith ("factors.txt" ):
93
101
factorFiles .append (indir + file )
0 commit comments