@Test public void testSimilarityJSON() throws Exception { final JSON expected = new JSON(); expected.addValues("bar", Lists.newArrayList(new YearAndValue(1910, 0f), new YearAndValue(1920, 0f), new YearAndValue(1930, 1f))); final Map<String, Object> actual = Server.getSimilarityJson(db, CORPUS, "foo", "bar"); assertEquals(expected.data.get("xs"), actual.get("xs")); assertEquals(((List<?>) expected.data.get("columns")).get(0), ((List<?>) actual.get("columns")).get(0)); }
static final Map<String, Object> getSimilarityJson(final DatabaseService db, final String corpus, final String initialWord, final String... moreWords) throws Exception { final JSON data = new JSON(); final Map<Integer, Embedding> initialWordEmbeddings = db.getEmbedding(corpus, initialWord); for (final String word : moreWords) { final Map<Integer, Embedding> otherWordEmbeddings = db.getEmbedding(corpus, word); final List<YearAndValue> yavs = new ArrayList<>(); otherWordEmbeddings.keySet().stream().filter(x -> initialWordEmbeddings.containsKey(x)).sorted() .forEach(year -> { yavs.add(new YearAndValue(year, (float) initialWordEmbeddings.get(year).similarity(otherWordEmbeddings.get(year)))); }); data.addValues(word, yavs); } LOG.trace("finished similarity {} in {}", new Object[] { initialWord, corpus }); return data.data; }
Server { static final Map<String, Object> getSimilarityJson(final DatabaseService db, final String corpus, final String initialWord, final String... moreWords) throws Exception { final JSON data = new JSON(); final Map<Integer, Embedding> initialWordEmbeddings = db.getEmbedding(corpus, initialWord); for (final String word : moreWords) { final Map<Integer, Embedding> otherWordEmbeddings = db.getEmbedding(corpus, word); final List<YearAndValue> yavs = new ArrayList<>(); otherWordEmbeddings.keySet().stream().filter(x -> initialWordEmbeddings.containsKey(x)).sorted() .forEach(year -> { yavs.add(new YearAndValue(year, (float) initialWordEmbeddings.get(year).similarity(otherWordEmbeddings.get(year)))); }); data.addValues(word, yavs); } LOG.trace("finished similarity {} in {}", new Object[] { initialWord, corpus }); return data.data; } }
Server { static final Map<String, Object> getSimilarityJson(final DatabaseService db, final String corpus, final String initialWord, final String... moreWords) throws Exception { final JSON data = new JSON(); final Map<Integer, Embedding> initialWordEmbeddings = db.getEmbedding(corpus, initialWord); for (final String word : moreWords) { final Map<Integer, Embedding> otherWordEmbeddings = db.getEmbedding(corpus, word); final List<YearAndValue> yavs = new ArrayList<>(); otherWordEmbeddings.keySet().stream().filter(x -> initialWordEmbeddings.containsKey(x)).sorted() .forEach(year -> { yavs.add(new YearAndValue(year, (float) initialWordEmbeddings.get(year).similarity(otherWordEmbeddings.get(year)))); }); data.addValues(word, yavs); } LOG.trace("finished similarity {} in {}", new Object[] { initialWord, corpus }); return data.data; }  }
Server { static final Map<String, Object> getSimilarityJson(final DatabaseService db, final String corpus, final String initialWord, final String... moreWords) throws Exception { final JSON data = new JSON(); final Map<Integer, Embedding> initialWordEmbeddings = db.getEmbedding(corpus, initialWord); for (final String word : moreWords) { final Map<Integer, Embedding> otherWordEmbeddings = db.getEmbedding(corpus, word); final List<YearAndValue> yavs = new ArrayList<>(); otherWordEmbeddings.keySet().stream().filter(x -> initialWordEmbeddings.containsKey(x)).sorted() .forEach(year -> { yavs.add(new YearAndValue(year, (float) initialWordEmbeddings.get(year).similarity(otherWordEmbeddings.get(year)))); }); data.addValues(word, yavs); } LOG.trace("finished similarity {} in {}", new Object[] { initialWord, corpus }); return data.data; }  static void startErrorServer(final Configuration config, final ArrayList<String> messageParts); static void startServer(final DatabaseService db, final Configuration config, boolean onlyExternal); static void stopServer(); }
Server { static final Map<String, Object> getSimilarityJson(final DatabaseService db, final String corpus, final String initialWord, final String... moreWords) throws Exception { final JSON data = new JSON(); final Map<Integer, Embedding> initialWordEmbeddings = db.getEmbedding(corpus, initialWord); for (final String word : moreWords) { final Map<Integer, Embedding> otherWordEmbeddings = db.getEmbedding(corpus, word); final List<YearAndValue> yavs = new ArrayList<>(); otherWordEmbeddings.keySet().stream().filter(x -> initialWordEmbeddings.containsKey(x)).sorted() .forEach(year -> { yavs.add(new YearAndValue(year, (float) initialWordEmbeddings.get(year).similarity(otherWordEmbeddings.get(year)))); }); data.addValues(word, yavs); } LOG.trace("finished similarity {} in {}", new Object[] { initialWord, corpus }); return data.data; }  static void startErrorServer(final Configuration config, final ArrayList<String> messageParts); static void startServer(final DatabaseService db, final Configuration config, boolean onlyExternal); static void stopServer();  }