@Test public void testGetSimilarity() throws DatabaseUnitException, Exception { assertEquals( Lists.newArrayList(new YearAndValue(1910, 2f), new YearAndValue(1920, 1f), new YearAndValue(1930, 3f), new YearAndValue(1940, 1f)), db.getSimilarity(CORPUS, "foo", "foo")); }
public List<YearAndValue> getSimilarity(final String corpusName, final String word1, final String word2) throws Exception { final Map<Integer, Embedding> embeddings1 = getEmbedding(corpusName, word1); final Map<Integer, Embedding> embeddings2 = getEmbedding(corpusName, word2); return Sets.union(embeddings1.keySet(), embeddings2.keySet()).stream() .sorted().map(year -> { if (embeddings1.containsKey(year) && embeddings2.containsKey(year)) return new YearAndValue(year, (float) embeddings1 .get(year).similarity(embeddings2.get(year))); else return new YearAndValue(year, 0f); }).collect(Collectors.toList()); }
DatabaseService { public List<YearAndValue> getSimilarity(final String corpusName, final String word1, final String word2) throws Exception { final Map<Integer, Embedding> embeddings1 = getEmbedding(corpusName, word1); final Map<Integer, Embedding> embeddings2 = getEmbedding(corpusName, word2); return Sets.union(embeddings1.keySet(), embeddings2.keySet()).stream() .sorted().map(year -> { if (embeddings1.containsKey(year) && embeddings2.containsKey(year)) return new YearAndValue(year, (float) embeddings1 .get(year).similarity(embeddings2.get(year))); else return new YearAndValue(year, 0f); }).collect(Collectors.toList()); } }
DatabaseService { public List<YearAndValue> getSimilarity(final String corpusName, final String word1, final String word2) throws Exception { final Map<Integer, Embedding> embeddings1 = getEmbedding(corpusName, word1); final Map<Integer, Embedding> embeddings2 = getEmbedding(corpusName, word2); return Sets.union(embeddings1.keySet(), embeddings2.keySet()).stream() .sorted().map(year -> { if (embeddings1.containsKey(year) && embeddings2.containsKey(year)) return new YearAndValue(year, (float) embeddings1 .get(year).similarity(embeddings2.get(year))); else return new YearAndValue(year, 0f); }).collect(Collectors.toList()); } DatabaseService(final Sql2o sql2o, final Configuration config); }
DatabaseService { public List<YearAndValue> getSimilarity(final String corpusName, final String word1, final String word2) throws Exception { final Map<Integer, Embedding> embeddings1 = getEmbedding(corpusName, word1); final Map<Integer, Embedding> embeddings2 = getEmbedding(corpusName, word2); return Sets.union(embeddings1.keySet(), embeddings2.keySet()).stream() .sorted().map(year -> { if (embeddings1.containsKey(year) && embeddings2.containsKey(year)) return new YearAndValue(year, (float) embeddings1 .get(year).similarity(embeddings2.get(year))); else return new YearAndValue(year, 0f); }).collect(Collectors.toList()); } DatabaseService(final Sql2o sql2o, final Configuration config); static void importTables(final Configuration config,
			final Sql2o sql2o); static void initializeTables(final Sql2o sql2o); void dropAll(); String getCorpusLink(final String corpus, final String word); String getCorpusName(final String corpus); String getCorpusNote(final String corpus); Map<Integer, Embedding> getEmbedding(final String corpusName,
			final String word); Map<String, List<YearAndValue>> getEmotion(final String corpusName,
			final String word); Integer getFirstYear(final String corpusName, final String word); Integer getLastYear(final String corpusName, final String word); List<YearAndValue> getSimilarity(final String corpusName,
			final String word1, final String word2); List<String> getTopContextWordsInYear(final String corpusName,
			final String table, final String word, final Integer year,
			final int limit); List<YearAndValue> getYearAndAssociation(final String corpusName,
			final String tableName, final String word1, final String word2); List<YearAndValue> getYearAndFrequency(final String corpusName,
			final String word); boolean knowCorpus(final String corpus); boolean wordInCorpus(final String word, final String corpus); }
DatabaseService { public List<YearAndValue> getSimilarity(final String corpusName, final String word1, final String word2) throws Exception { final Map<Integer, Embedding> embeddings1 = getEmbedding(corpusName, word1); final Map<Integer, Embedding> embeddings2 = getEmbedding(corpusName, word2); return Sets.union(embeddings1.keySet(), embeddings2.keySet()).stream() .sorted().map(year -> { if (embeddings1.containsKey(year) && embeddings2.containsKey(year)) return new YearAndValue(year, (float) embeddings1 .get(year).similarity(embeddings2.get(year))); else return new YearAndValue(year, 0f); }).collect(Collectors.toList()); } DatabaseService(final Sql2o sql2o, final Configuration config); static void importTables(final Configuration config,
			final Sql2o sql2o); static void initializeTables(final Sql2o sql2o); void dropAll(); String getCorpusLink(final String corpus, final String word); String getCorpusName(final String corpus); String getCorpusNote(final String corpus); Map<Integer, Embedding> getEmbedding(final String corpusName,
			final String word); Map<String, List<YearAndValue>> getEmotion(final String corpusName,
			final String word); Integer getFirstYear(final String corpusName, final String word); Integer getLastYear(final String corpusName, final String word); List<YearAndValue> getSimilarity(final String corpusName,
			final String word1, final String word2); List<String> getTopContextWordsInYear(final String corpusName,
			final String table, final String word, final Integer year,
			final int limit); List<YearAndValue> getYearAndAssociation(final String corpusName,
			final String tableName, final String word1, final String word2); List<YearAndValue> getYearAndFrequency(final String corpusName,
			final String word); boolean knowCorpus(final String corpus); boolean wordInCorpus(final String word, final String corpus); static final String SIMILARITY_TABLE; static final String EMOTION_TABLE; static final String PPMI_TABLE; static final String EMBEDDING_TABLE; static final String CHI_TABLE; final Map<String, Corpus> corpora; }