@Test public void getFrequencyHashMap() throws IOException { setUpRequestMock(); setUpFrequencyMocks(NGramField.content, "one", 1L); setUpFrequencyMocks(NGramField.content_title, "one", 1L); setUpFrequencyMocks(NGramField.content, "two", 1L); setUpFrequencyMocks(NGramField.content_title, "two", 1L); setUpFrequencyMocks(NGramField.content, "three", 1L); setUpFrequencyMocks(NGramField.content_title, "three", 1L); setUpFrequencyMocks(NGramField.bigrams, "one two", 1L); setUpFrequencyMocks(NGramField.bigrams_title, "one two", 1L); setUpFrequencyMocks(NGramField.bigrams, "two three", 1L); setUpFrequencyMocks(NGramField.bigrams_title, "two three", 1L); setUpFrequencyMocks(NGramField.trigrams, "one two three", 1L); setUpFrequencyMocks(NGramField.trigrams_title, "one two three", 1L); System.out.println(NGramField.content_title); FrequencyMap map = new FrequencyMap(); TermFrequencySearcher target = new TermFrequencySearcher(mockedRequest); map = target.getFrequencyHashMap( new TokenizedString("one two three"), map); Assert.assertEquals("term frequency for unigram 'one' expected equals actual", (long) 1L, (long) map.descriptionTermFrequencyMap.get("one")); Assert.assertEquals("term total frequency for unigram 'two' expected equals actual", (long) 1L, (long) map.descriptionTermFrequencyMap.get("two")); Assert.assertEquals("term total frequency for unigram 'three' expected equals actual", (long)1L, (long)map.descriptionTermFrequencyMap.get("three")); Assert.assertEquals("term frequency for bigram 'one two' expected equals actual", (long)1L, (long)map.descriptionTermFrequencyMap.get("one two")); Assert.assertEquals("term total frequency for bigram 'two three' expected equals actual", (long)1L, (long)map.descriptionTermFrequencyMap.get("two three")); Assert.assertEquals("term total frequency for unigram 'one two three' expected equals actual", (long)1L, (long)map.descriptionTermFrequencyMap.get("one two three")); }
public FrequencyMap getFrequencyHashMap(TokenizedString tokens, FrequencyMap map) throws IOException { HashMap<String, Long> descriptionFrequencyMap = new HashMap<String, Long>(); HashMap<String, Long> titleFrequencyMap = new HashMap<String, Long>(); for (int i = 0; i < tokens.length; ++i) { NGram nGram = new NGram(tokens, i, 1); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 1; ++i) { NGram nGram = new NGram(tokens, i, 2); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 2; ++i) { NGram nGram = new NGram(tokens, i, 3); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams_title, nGram.toLowerCorpusString())); } map.descriptionTermFrequencyMap = descriptionFrequencyMap; map.titleTermFrequencyMap = titleFrequencyMap; return map; }
TermFrequencySearcher { public FrequencyMap getFrequencyHashMap(TokenizedString tokens, FrequencyMap map) throws IOException { HashMap<String, Long> descriptionFrequencyMap = new HashMap<String, Long>(); HashMap<String, Long> titleFrequencyMap = new HashMap<String, Long>(); for (int i = 0; i < tokens.length; ++i) { NGram nGram = new NGram(tokens, i, 1); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 1; ++i) { NGram nGram = new NGram(tokens, i, 2); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 2; ++i) { NGram nGram = new NGram(tokens, i, 3); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams_title, nGram.toLowerCorpusString())); } map.descriptionTermFrequencyMap = descriptionFrequencyMap; map.titleTermFrequencyMap = titleFrequencyMap; return map; } }
TermFrequencySearcher { public FrequencyMap getFrequencyHashMap(TokenizedString tokens, FrequencyMap map) throws IOException { HashMap<String, Long> descriptionFrequencyMap = new HashMap<String, Long>(); HashMap<String, Long> titleFrequencyMap = new HashMap<String, Long>(); for (int i = 0; i < tokens.length; ++i) { NGram nGram = new NGram(tokens, i, 1); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 1; ++i) { NGram nGram = new NGram(tokens, i, 2); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 2; ++i) { NGram nGram = new NGram(tokens, i, 3); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams_title, nGram.toLowerCorpusString())); } map.descriptionTermFrequencyMap = descriptionFrequencyMap; map.titleTermFrequencyMap = titleFrequencyMap; return map; } TermFrequencySearcher(SolrQueryRequest request); }
TermFrequencySearcher { public FrequencyMap getFrequencyHashMap(TokenizedString tokens, FrequencyMap map) throws IOException { HashMap<String, Long> descriptionFrequencyMap = new HashMap<String, Long>(); HashMap<String, Long> titleFrequencyMap = new HashMap<String, Long>(); for (int i = 0; i < tokens.length; ++i) { NGram nGram = new NGram(tokens, i, 1); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 1; ++i) { NGram nGram = new NGram(tokens, i, 2); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 2; ++i) { NGram nGram = new NGram(tokens, i, 3); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams_title, nGram.toLowerCorpusString())); } map.descriptionTermFrequencyMap = descriptionFrequencyMap; map.titleTermFrequencyMap = titleFrequencyMap; return map; } TermFrequencySearcher(SolrQueryRequest request); FrequencyMap getFrequencyHashMap(TokenizedString tokens, FrequencyMap map); FrequencyMap getTotalFrequencies(FrequencyMap map); }
TermFrequencySearcher { public FrequencyMap getFrequencyHashMap(TokenizedString tokens, FrequencyMap map) throws IOException { HashMap<String, Long> descriptionFrequencyMap = new HashMap<String, Long>(); HashMap<String, Long> titleFrequencyMap = new HashMap<String, Long>(); for (int i = 0; i < tokens.length; ++i) { NGram nGram = new NGram(tokens, i, 1); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.content_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 1; ++i) { NGram nGram = new NGram(tokens, i, 2); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.bigrams_title, nGram.toLowerCorpusString())); } for (int i = 0; i < tokens.length - 2; ++i) { NGram nGram = new NGram(tokens, i, 3); descriptionFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams, nGram.toLowerCorpusString())); titleFrequencyMap.put(nGram.toLowerCorpusString(), getFrequency(NGramField.trigrams_title, nGram.toLowerCorpusString())); } map.descriptionTermFrequencyMap = descriptionFrequencyMap; map.titleTermFrequencyMap = titleFrequencyMap; return map; } TermFrequencySearcher(SolrQueryRequest request); FrequencyMap getFrequencyHashMap(TokenizedString tokens, FrequencyMap map); FrequencyMap getTotalFrequencies(FrequencyMap map);  }