Skip to content

Commit 35c60c8

Browse files
committed
Merge pull request #1 from ArnauPrat/master
All the improvements performed during the last month: - Improved code quality - Fixed issues on emails and IPs - Populations quantized
2 parents 34851d9 + 43bdc3b commit 35c60c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3887
-3807
lines changed

ldbc_socialnet_dbgen/params.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
numtotalUser:10000
22
startYear:2010
33
numYears:1
4-
serializerType:ttl
4+
serializerType:csv

ldbc_socialnet_dbgen/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,10 @@
6262
<artifactId>ssj</artifactId>
6363
<version>2.5</version>
6464
</dependency>
65+
<dependency>
66+
<groupId>com.google.code.gson</groupId>
67+
<artifactId>gson</artifactId>
68+
<version>2.2.4</version>
69+
</dependency>
6570
</dependencies>
66-
</project>
71+
</project>

ldbc_socialnet_dbgen/src/main/java/ldbc/socialnet/dbgen/dictionary/BrowserDictionary.java

Lines changed: 63 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -37,160 +37,106 @@
3737
package ldbc.socialnet.dbgen.dictionary;
3838

3939
import java.io.BufferedReader;
40-
import java.io.FileInputStream;
4140
import java.io.IOException;
4241
import java.io.InputStreamReader;
43-
import java.io.RandomAccessFile;
4442
import java.util.Random;
4543
import java.util.Vector;
4644

45+
/**
46+
* This class reads the file containing the names and distributions for the browsers used in the ldbc socialnet generation and
47+
* provides access methods to get such data.
48+
*/
4749
public class BrowserDictionary {
4850

51+
private static final String SEPARATOR = " ";
52+
53+
Vector<String> vBrowser;
4954
Vector<Double> vBrowserCummulative;
50-
Vector<String> vBrowser;
5155

52-
Random randBrowsers;
53-
BufferedReader browserDictionary;
54-
String browserDicFileName;
55-
56-
int totalNumBrowsers;
56+
String fileName;
5757

58-
double probAnotherBrowser; // Probability that a user uses another browser
59-
Random randDifBrowser; // whether user change to another browser or not
58+
double probAnotherBrowser;
59+
Random randDifBrowser;
60+
Random randBrowsers;
6061

61-
public BrowserDictionary(String _browserDicFileName, long seedBrowser,double _probAnotherBrowser){
62-
randBrowsers = new Random(seedBrowser);
63-
randDifBrowser = new Random(seedBrowser);
64-
browserDicFileName = _browserDicFileName;
65-
probAnotherBrowser = _probAnotherBrowser;
62+
/**
63+
* Creator.
64+
*
65+
* @param fileName: The file which contains the browser data.
66+
* @param seedBrowser: Seed for the browsers random selection.
67+
* @param probAnotherBrowser: Probability of the user using another browser.
68+
*/
69+
public BrowserDictionary(String fileName, long seedBrowser, double probAnotherBrowser){
70+
this.fileName = fileName;
71+
this.probAnotherBrowser = probAnotherBrowser;
72+
73+
randBrowsers = new Random(seedBrowser);
74+
randDifBrowser = new Random(seedBrowser);
6675
}
6776

77+
/**
78+
* Initializes the dictionary extracting the data from the file.
79+
*/
6880
public void init(){
6981
try {
70-
browserDictionary = new BufferedReader(new InputStreamReader(getClass( ).getResourceAsStream(browserDicFileName), "UTF-8"));
82+
BufferedReader dictionary = new BufferedReader(
83+
new InputStreamReader(getClass( ).getResourceAsStream(fileName), "UTF-8"));
7184
vBrowser = new Vector<String>();
7285
vBrowserCummulative = new Vector<Double>();
7386

74-
browsersExtract();
75-
76-
browserDictionary.close();
77-
78-
} catch (IOException e) {
79-
// TODO Auto-generated catch block
80-
e.printStackTrace();
81-
}
82-
}
83-
public void browsersExtract(){
84-
String browser;
85-
double cumdistribution = 0.0; //cummulative distribution value
86-
String line;
87-
int i = 0;
88-
totalNumBrowsers = 0;
87+
String line;
88+
double cummulativeDist = 0.0;
8989

90-
try {
91-
while ((line = browserDictionary.readLine()) != null){
92-
String infos[] = line.split(" ");
93-
browser = infos[0];
94-
cumdistribution = cumdistribution + Double.parseDouble(infos[1]);
95-
vBrowser.add(browser);
96-
//System.out.println(cumdistribution);
97-
vBrowserCummulative.add(cumdistribution);
98-
i++;
99-
100-
totalNumBrowsers++;
101-
}
102-
90+
while ((line = dictionary.readLine()) != null){
91+
String data[] = line.split(SEPARATOR);
92+
String browser = data[0];
93+
cummulativeDist += Double.parseDouble(data[1]);
94+
vBrowser.add(browser);
95+
vBrowserCummulative.add(cummulativeDist);
96+
}
97+
dictionary.close();
10398
System.out.println("Done ... " + vBrowser.size() + " browsers were extracted");
10499

105100
} catch (IOException e) {
106-
// TODO Auto-generated catch block
107101
e.printStackTrace();
108102
}
109103
}
110104

111-
public String getRandomBrowser(){
112-
double prob = randBrowsers.nextDouble();
113-
114-
int minIdx = 0;
115-
int maxIdx = totalNumBrowsers - 1;
116-
117-
if (prob < vBrowserCummulative.get(minIdx)){
118-
return vBrowser.get(minIdx);
119-
}
120-
121-
while ((maxIdx - minIdx) > 1){
122-
123-
if (prob > vBrowserCummulative.get(minIdx + (maxIdx - minIdx)/2)){
124-
minIdx = minIdx + (maxIdx - minIdx)/2;
125-
}
126-
else{
127-
maxIdx = minIdx + (maxIdx - minIdx)/2;
128-
}
129-
}
130-
131-
return vBrowser.get(maxIdx);
132-
}
105+
/**
106+
* Gets the browser name.
107+
*/
108+
public String getName(byte id) {
109+
return vBrowser.get(id);
110+
}
133111

134-
public String getBrowserName(byte browserId){
135-
return vBrowser.get(browserId);
136-
}
137-
public byte getRandomBrowserId(){
138-
double prob = randBrowsers.nextDouble();
112+
/**
113+
* Gets a random browser id.
114+
*/
115+
public byte getRandomBrowserId() {
116+
double prob = randBrowsers.nextDouble();
117+
139118
int minIdx = 0;
140-
int maxIdx = totalNumBrowsers - 1;
141-
142-
if (prob < vBrowserCummulative.get(minIdx)){
143-
return (byte)minIdx;
144-
}
119+
int maxIdx = (prob < vBrowserCummulative.get(minIdx)) ? minIdx : vBrowserCummulative.size() - 1;
145120

146-
while ((maxIdx - minIdx) > 1){
121+
while ((maxIdx - minIdx) > 1) {
147122

148-
if (prob > vBrowserCummulative.get(minIdx + (maxIdx - minIdx)/2)){
149-
minIdx = minIdx + (maxIdx - minIdx)/2;
150-
}
151-
else{
152-
maxIdx = minIdx + (maxIdx - minIdx)/2;
123+
int middlePoint = minIdx + (maxIdx - minIdx) / 2;
124+
if (prob > vBrowserCummulative.get(middlePoint)) {
125+
minIdx = middlePoint;
126+
} else {
127+
maxIdx = middlePoint;
153128
}
154129
}
155130

156131
return (byte)maxIdx;
157132
}
158133

134+
/**
135+
* Gets the post browser. There is a chance of being different from the user preferred browser
136+
* @param userBrowserId: The user preferred browser.
137+
*/
159138
public byte getPostBrowserId(byte userBrowserId){
160139
double prob = randDifBrowser.nextDouble();
161-
if (prob < probAnotherBrowser){
162-
return getRandomBrowserId();
163-
}
164-
else{
165-
return userBrowserId;
166-
}
167-
}
168-
public byte getCommentBrowserId(byte userBrowserId){
169-
double prob = randDifBrowser.nextDouble();
170-
if (prob < probAnotherBrowser){
171-
return getRandomBrowserId();
172-
}
173-
else{
174-
return userBrowserId;
175-
}
176-
}
177-
178-
public String getBrowserForAUser(String originalBrowser){
179-
double prob = randDifBrowser.nextDouble();
180-
if (prob < probAnotherBrowser){
181-
return getRandomBrowser();
182-
}
183-
else{
184-
return originalBrowser;
185-
}
140+
return (prob < probAnotherBrowser) ? getRandomBrowserId() : userBrowserId;
186141
}
187-
188-
public Vector<String> getvBrowser() {
189-
return vBrowser;
190-
}
191-
192-
public void setvBrowser(Vector<String> vBrowser) {
193-
this.vBrowser = vBrowser;
194-
}
195-
196142
}

0 commit comments

Comments
 (0)