@Test public void testDaoRead() throws DaoException { DatasetDao dao = new DatasetDao(); Dataset ds = dao.get(Language.getByLangCode("en"), "wordsim353.txt"); assertEquals(353, ds.getData().size()); assertEquals("en", ds.getLanguage().getLangCode()); double sim = Double.NaN; for (KnownSim ks : ds.getData()) { if (ks.phrase1.equals("morality") && ks.phrase2.equals("marriage")) { sim = ks.similarity; } } assertTrue(!Double.isNaN(sim)); assertEquals(sim, 0.354145342886, 0.000001); }
public Dataset get(Language language, String name) throws DaoException { if (groups.containsKey(name)) { List<Dataset> members = new ArrayList<Dataset>(); for (String n : groups.get(name)) { members.add(get(language, n)); } return new Dataset(name, members); } if (name.contains("/") || name.contains("\\")) { throw new DaoException("get() reads a dataset by name for a jar. Try read() instead?"); } Info info = getInfo(name); if (info == null) { throw new DaoException("no dataset with name '" + name + "'"); } if (!info.languages.containsLanguage(language)) { throw new DaoException("dataset '" + name + "' does not support language " + language); } try { return read(name, language, WpIOUtils.openResource(RESOURCE_DATSET + "/" + name)); } catch (IOException e) { throw new DaoException(e); } }
DatasetDao { public Dataset get(Language language, String name) throws DaoException { if (groups.containsKey(name)) { List<Dataset> members = new ArrayList<Dataset>(); for (String n : groups.get(name)) { members.add(get(language, n)); } return new Dataset(name, members); } if (name.contains("/") || name.contains("\\")) { throw new DaoException("get() reads a dataset by name for a jar. Try read() instead?"); } Info info = getInfo(name); if (info == null) { throw new DaoException("no dataset with name '" + name + "'"); } if (!info.languages.containsLanguage(language)) { throw new DaoException("dataset '" + name + "' does not support language " + language); } try { return read(name, language, WpIOUtils.openResource(RESOURCE_DATSET + "/" + name)); } catch (IOException e) { throw new DaoException(e); } } }
DatasetDao { public Dataset get(Language language, String name) throws DaoException { if (groups.containsKey(name)) { List<Dataset> members = new ArrayList<Dataset>(); for (String n : groups.get(name)) { members.add(get(language, n)); } return new Dataset(name, members); } if (name.contains("/") || name.contains("\\")) { throw new DaoException("get() reads a dataset by name for a jar. Try read() instead?"); } Info info = getInfo(name); if (info == null) { throw new DaoException("no dataset with name '" + name + "'"); } if (!info.languages.containsLanguage(language)) { throw new DaoException("dataset '" + name + "' does not support language " + language); } try { return read(name, language, WpIOUtils.openResource(RESOURCE_DATSET + "/" + name)); } catch (IOException e) { throw new DaoException(e); } } DatasetDao();  DatasetDao(Collection<Info> info); }
DatasetDao { public Dataset get(Language language, String name) throws DaoException { if (groups.containsKey(name)) { List<Dataset> members = new ArrayList<Dataset>(); for (String n : groups.get(name)) { members.add(get(language, n)); } return new Dataset(name, members); } if (name.contains("/") || name.contains("\\")) { throw new DaoException("get() reads a dataset by name for a jar. Try read() instead?"); } Info info = getInfo(name); if (info == null) { throw new DaoException("no dataset with name '" + name + "'"); } if (!info.languages.containsLanguage(language)) { throw new DaoException("dataset '" + name + "' does not support language " + language); } try { return read(name, language, WpIOUtils.openResource(RESOURCE_DATSET + "/" + name)); } catch (IOException e) { throw new DaoException(e); } } DatasetDao();  DatasetDao(Collection<Info> info); void setNormalize(boolean normalize); List<Dataset> getAllInLanguage(Language lang); Dataset read(Language language, File path); Dataset get(Language language, String name); boolean isGroup(String name); List<Dataset> getGroup(Language language, String name); List<Dataset> getDatasetOrGroup(Language language, String name); Info getInfo(String name); void setDisambiguator(Disambiguator dab); void setResolvePhrases(boolean resolvePhrases); void setGroups(Map<String, List<String>> groups); void write(Dataset dataset, File path); static Collection<Info> readInfos(); static Collection<Info> readInfos(BufferedReader reader); }
DatasetDao { public Dataset get(Language language, String name) throws DaoException { if (groups.containsKey(name)) { List<Dataset> members = new ArrayList<Dataset>(); for (String n : groups.get(name)) { members.add(get(language, n)); } return new Dataset(name, members); } if (name.contains("/") || name.contains("\\")) { throw new DaoException("get() reads a dataset by name for a jar. Try read() instead?"); } Info info = getInfo(name); if (info == null) { throw new DaoException("no dataset with name '" + name + "'"); } if (!info.languages.containsLanguage(language)) { throw new DaoException("dataset '" + name + "' does not support language " + language); } try { return read(name, language, WpIOUtils.openResource(RESOURCE_DATSET + "/" + name)); } catch (IOException e) { throw new DaoException(e); } } DatasetDao();  DatasetDao(Collection<Info> info); void setNormalize(boolean normalize); List<Dataset> getAllInLanguage(Language lang); Dataset read(Language language, File path); Dataset get(Language language, String name); boolean isGroup(String name); List<Dataset> getGroup(Language language, String name); List<Dataset> getDatasetOrGroup(Language language, String name); Info getInfo(String name); void setDisambiguator(Disambiguator dab); void setResolvePhrases(boolean resolvePhrases); void setGroups(Map<String, List<String>> groups); void write(Dataset dataset, File path); static Collection<Info> readInfos(); static Collection<Info> readInfos(BufferedReader reader); static final String RESOURCE_DATSET; static final String RESOURCE_DATASET_INFO; }