public NameSampler() {
try {
if (first.compareAndSet(null, new Multinomial<String>())) {
Preconditions.checkState(last.getAndSet(new Multinomial<String>()) == null);
Splitter onTab = Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings().trimResults();
for (String resourceName : ImmutableList.of("dist.male.first", "dist.female.first")) {
for (String line : Resources.readLines(Resources.getResource(resourceName), Charsets.UTF_8)) {
if (!line.startsWith("#")) {
Iterator<String> parts = onTab.split(line).iterator();
String name = initialCap(parts.next());
double weight = Double.parseDouble(parts.next());
if (first.get().getWeight(name) == 0) {
first.get().add(name, weight);
} else {
// do this instead of add because some first names may appear more than once
first.get().set(name, first.get().getWeight(name) + weight);
}
}
}
}
for (String line : Resources.readLines(Resources.getResource("dist.all.last"), Charsets.UTF_8)) {
if (!line.startsWith("#")) {
Iterator<String> parts = onTab.split(line).iterator();
String name = initialCap(parts.next());
double weight = Double.parseDouble(parts.next());
last.get().add(name, weight);
}
}