private static List<Pair<String, Double>> convertCounter(Counter<String> counts, double power) { List<Pair<String, Double>> convertedCounts = new ArrayList<Pair<String, Double>>(); for (String word : counts.keySet()) { double x = Math.pow(counts.getCount(word), power); Pair<String, Double> countPair = Pair.create(word, x); convertedCounts.add(countPair); } return convertedCounts; }
private Pair<Integer, Set<Integer>> getWordContextPair( List<String> sentence, int wordPosition) { String centerWord = sentence.get(wordPosition); int centerWordIndex = encodedVocab.get(centerWord); Set<Integer> contextWordSet = new HashSet<Integer>(); for (int i = wordPosition - contextSize; i < wordPosition + contextSize; i++) { if (i < 0) continue; // Ignore contexts prior to start of sentence if (i >= sentence.size()) break; // Ignore contexts after end of current sentence if (i == centerWordIndex) continue; // Ignore center word String contextWord = sentence.get(i); int contextWordIndex = encodedVocab.get(contextWord); contextWordSet.add(contextWordIndex); } return Pair.create(centerWordIndex, contextWordSet); }