Skip to content

Commit 08944ff

Browse files
committed
added xsanchez changes
1 parent da25ccc commit 08944ff

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2013 LDBC
3+
* Linked Data Benchmark Council (http://ldbc.eu)
4+
*
5+
* This file is part of ldbc_socialnet_dbgen.
6+
*
7+
* ldbc_socialnet_dbgen is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* ldbc_socialnet_dbgen is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with ldbc_socialnet_dbgen. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* Copyright (C) 2011 OpenLink Software <[email protected]>
21+
* All Rights Reserved.
22+
*
23+
* This program is free software; you can redistribute it and/or modify
24+
* it under the terms of the GNU General Public License as published by
25+
* the Free Software Foundation; only Version 2 of the License dated
26+
* June 1991.
27+
*
28+
* This program is distributed in the hope that it will be useful,
29+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
30+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31+
* GNU General Public License for more details.
32+
*
33+
* You should have received a copy of the GNU General Public License
34+
* along with this program; if not, write to the Free Software
35+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
36+
*/
37+
package ldbc.socialnet.dbgen.serializer;
38+
39+
import ldbc.socialnet.dbgen.objects.Comment;
40+
import ldbc.socialnet.dbgen.objects.Group;
41+
import ldbc.socialnet.dbgen.objects.Photo;
42+
import ldbc.socialnet.dbgen.objects.Post;
43+
import ldbc.socialnet.dbgen.objects.ReducedUserProfile;
44+
import ldbc.socialnet.dbgen.objects.UserExtraInfo;
45+
46+
/**
47+
* The empty serializer does nothing.
48+
*
49+
* Its purpose is to avoid the serializing I/O costs in debug phases.
50+
*/
51+
public class EmptySerializer implements Serializer {
52+
53+
public EmptySerializer() {
54+
}
55+
56+
public Long unitsGenerated() {
57+
return 0L;
58+
}
59+
60+
public void gatherData(ReducedUserProfile profile, UserExtraInfo extraInfo){
61+
}
62+
63+
public void gatherData(Post post){
64+
}
65+
66+
public void gatherData(Comment comment){
67+
}
68+
69+
public void gatherData(Photo photo){
70+
}
71+
72+
public void gatherData(Group group) {
73+
}
74+
75+
public void close() {
76+
}
77+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package ldbc.socialnet.dbgen.serializer;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.HashMap;
6+
import java.util.HashSet;
7+
8+
import ldbc.socialnet.dbgen.dictionary.LocationDictionary;
9+
10+
import com.google.gson.ExclusionStrategy;
11+
import com.google.gson.FieldAttributes;
12+
13+
/**
14+
* Container class used to store all the generator statistics.
15+
*
16+
*/
17+
public class Statistics {
18+
19+
/**
20+
* This was used in early states to exclude a field of a class in the gson parser library.
21+
* It is keep for the sake of having a quick example/place to write future field exclusions.
22+
*/
23+
public class StatisticsExclude implements ExclusionStrategy {
24+
25+
public boolean shouldSkipClass(Class<?> arg0) {
26+
return false;
27+
}
28+
29+
public boolean shouldSkipField(FieldAttributes f) {
30+
31+
return (f.getDeclaringClass() == CountryPair.class && f.getName().equals("population"));
32+
}
33+
34+
}
35+
36+
/**
37+
* Container to keep paired countries and their population. It is used to sort
38+
* this pairs by population.
39+
*/
40+
private class CountryPair implements Comparable<CountryPair> {
41+
public String[] countries = new String[2];
42+
public Long population;
43+
44+
45+
public int compareTo(CountryPair pair) {
46+
return pair.population.compareTo(population);
47+
}
48+
}
49+
50+
public Integer minPersonId;
51+
public Integer maxPersonId;
52+
public String minWorkFrom;
53+
public String maxWorkFrom;
54+
public String minPostCreationDate;
55+
public String maxPostCreationDate;
56+
public HashSet<String> firstNames;
57+
public HashSet<String> tagNames;
58+
public HashSet<String> countries;
59+
public HashSet<String> tagClasses;
60+
private ArrayList<String[]> countryPairs;
61+
62+
public Statistics() {
63+
minPersonId = Integer.MAX_VALUE;
64+
maxPersonId = Integer.MIN_VALUE;
65+
firstNames = new HashSet<String>();
66+
tagNames = new HashSet<String>();
67+
tagClasses = new HashSet<String>();
68+
countries = new HashSet<String>();
69+
countryPairs = new ArrayList<String[]>();
70+
}
71+
72+
/**
73+
* Makes all the country pairs of the countries found in the countries statistic field belonging
74+
* to the same continent. This pairs are sorted by population.
75+
*
76+
* @param dicLocation The location dictionary.
77+
*/
78+
public void makeCountryPairs(LocationDictionary dicLocation) {
79+
HashMap<Integer, ArrayList<Integer>> closeCountries = new HashMap<Integer, ArrayList<Integer>>();
80+
for (String s : countries) {
81+
Integer id = dicLocation.getCountryId(s);
82+
Integer continent = dicLocation.belongsTo(id);
83+
if (!closeCountries.containsKey(continent)) {
84+
closeCountries.put(continent, new ArrayList<Integer>());
85+
}
86+
closeCountries.get(continent).add(id);
87+
}
88+
89+
ArrayList<CountryPair> toSort = new ArrayList<CountryPair>();
90+
for (ArrayList<Integer> relatedCountries : closeCountries.values()) {
91+
for (int i = 0; i < relatedCountries.size(); i++) {
92+
for (int j = i+1; j < relatedCountries.size(); j++) {
93+
CountryPair pair = new CountryPair();
94+
pair.countries[0] = dicLocation.getLocationName(relatedCountries.get(i));
95+
pair.countries[1] = dicLocation.getLocationName(relatedCountries.get(j));
96+
pair.population = dicLocation.getPopulation(relatedCountries.get(i))
97+
+ dicLocation.getPopulation(relatedCountries.get(j));
98+
toSort.add(pair);
99+
}
100+
}
101+
}
102+
Collections.sort(toSort);
103+
for (CountryPair p : toSort) {
104+
countryPairs.add(p.countries);
105+
}
106+
}
107+
108+
/**
109+
* Get gson exclusion class for the statistics.
110+
*
111+
* @return The exclusion class.
112+
*/
113+
public StatisticsExclude getExclusion() {
114+
return new StatisticsExclude();
115+
}
116+
}

0 commit comments

Comments
 (0)