Sha256: eccf7c7f98a5cf1b4806d33a718fe0b9ac8771be5646c99b12f6732f3db0c8db
Contents?: true
Size: 1.18 KB
Versions: 4
Compression:
Stored size: 1.18 KB
Contents
package bae; import java.util.HashMap; import java.util.Map; import java.util.Set; public class FrequencyTable { private Map<String, Map<String, Long>> frequencyTable; public FrequencyTable() { this.frequencyTable = new HashMap<>(); } public void insertOrIgnore(String label) { // Add new hash to frequency table if it's not already there this.frequencyTable.putIfAbsent(label, new HashMap<String, Long>()); } public void increaseFrequencyBy(String label, String word, long frequency) { // Add label if it doesn't exist insertOrIgnore(label); Map<String, Long> frequencyRow = this.frequencyTable.get(label); // Make sure we have a frequency for that position in the table frequencyRow.putIfAbsent(word, 0L); // Update frequency frequencyRow.put(word, frequencyRow.get(word) + frequency); } public Set<String> getLabels() { return this.frequencyTable.keySet(); } public long get(String label, String word) { try { return this.frequencyTable.get(label).get(word); } catch (NullPointerException e) { return 0L; } } }
Version data entries
4 entries across 4 versions & 1 rubygems