@Test public void testGetTopContextWordsInYear() throws Exception { assertEquals(Arrays.asList(new String[] { "bar" }), db.getTopContextWordsInYear(CORPUS, DatabaseService.PPMI_TABLE, "foo", 1910, 1)); assertEquals(Arrays.asList(new String[] { "bar", "boo" }), db.getTopContextWordsInYear(CORPUS, DatabaseService.PPMI_TABLE, "foo", 1910, 2)); }
public List<String> getTopContextWordsInYear(final String corpusName, final String table, final String word, final Integer year, final int limit) { final Corpus corpus = corpora.get(corpusName); final List<String> words = new ArrayList<>(); if (!corpus.hasMappingFor(word) || (year == null)) return words; final Integer givenWordId = corpus.getIdFor(word); final String sql = String.format(TOP_CONTEXT_QUERY, table); try (Connection con = sql2o.open()) { for (final Integer wordId : con.createQuery(sql) .addParameter("givenWord", givenWordId) .addParameter("corpus", corpus.getId()) .addParameter("year", year).addParameter("limit", limit) .executeScalarList(Integer.class)) words.add(corpus.getStringFor(wordId)); return words; } }
DatabaseService { public List<String> getTopContextWordsInYear(final String corpusName, final String table, final String word, final Integer year, final int limit) { final Corpus corpus = corpora.get(corpusName); final List<String> words = new ArrayList<>(); if (!corpus.hasMappingFor(word) || (year == null)) return words; final Integer givenWordId = corpus.getIdFor(word); final String sql = String.format(TOP_CONTEXT_QUERY, table); try (Connection con = sql2o.open()) { for (final Integer wordId : con.createQuery(sql) .addParameter("givenWord", givenWordId) .addParameter("corpus", corpus.getId()) .addParameter("year", year).addParameter("limit", limit) .executeScalarList(Integer.class)) words.add(corpus.getStringFor(wordId)); return words; } } }
DatabaseService { public List<String> getTopContextWordsInYear(final String corpusName, final String table, final String word, final Integer year, final int limit) { final Corpus corpus = corpora.get(corpusName); final List<String> words = new ArrayList<>(); if (!corpus.hasMappingFor(word) || (year == null)) return words; final Integer givenWordId = corpus.getIdFor(word); final String sql = String.format(TOP_CONTEXT_QUERY, table); try (Connection con = sql2o.open()) { for (final Integer wordId : con.createQuery(sql) .addParameter("givenWord", givenWordId) .addParameter("corpus", corpus.getId()) .addParameter("year", year).addParameter("limit", limit) .executeScalarList(Integer.class)) words.add(corpus.getStringFor(wordId)); return words; } } DatabaseService(final Sql2o sql2o, final Configuration config); }
DatabaseService { public List<String> getTopContextWordsInYear(final String corpusName, final String table, final String word, final Integer year, final int limit) { final Corpus corpus = corpora.get(corpusName); final List<String> words = new ArrayList<>(); if (!corpus.hasMappingFor(word) || (year == null)) return words; final Integer givenWordId = corpus.getIdFor(word); final String sql = String.format(TOP_CONTEXT_QUERY, table); try (Connection con = sql2o.open()) { for (final Integer wordId : con.createQuery(sql) .addParameter("givenWord", givenWordId) .addParameter("corpus", corpus.getId()) .addParameter("year", year).addParameter("limit", limit) .executeScalarList(Integer.class)) words.add(corpus.getStringFor(wordId)); return words; } } 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<String> getTopContextWordsInYear(final String corpusName, final String table, final String word, final Integer year, final int limit) { final Corpus corpus = corpora.get(corpusName); final List<String> words = new ArrayList<>(); if (!corpus.hasMappingFor(word) || (year == null)) return words; final Integer givenWordId = corpus.getIdFor(word); final String sql = String.format(TOP_CONTEXT_QUERY, table); try (Connection con = sql2o.open()) { for (final Integer wordId : con.createQuery(sql) .addParameter("givenWord", givenWordId) .addParameter("corpus", corpus.getId()) .addParameter("year", year).addParameter("limit", limit) .executeScalarList(Integer.class)) words.add(corpus.getStringFor(wordId)); return words; } } 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; }