public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); WikidataDao wdDao = conf.get(WikidataDao.class); // Get page Title title = new Title("Berlin", env.getDefaultLanguage()); LocalPage page = lpDao.getByTitle(title, NameSpace.ARTICLE); System.out.println("Properties for " + title); // Show statements Map<String, List<LocalWikidataStatement>> statements = wdDao.getLocalStatements(page); for (String property : statements.keySet()) { System.out.println("values for property " + property + " are:"); for (LocalWikidataStatement lws : statements.get(property)) { System.out.println("\t" + lws.getFullStatement()); } } } }
@Override public Map<String, List<LocalWikidataStatement>> getLocalStatements(Language lang, WikidataEntity.Type type, int id) throws DaoException { lang = getRealLang(lang); WikidataFilter filter = new WikidataFilter.Builder() .withEntityType(type) .withEntityId(id) .build(); Map<String, List<LocalWikidataStatement>> local = new HashMap<String, List<LocalWikidataStatement>>(); for (WikidataStatement st : get(filter)) { LocalWikidataStatement lws = getLocalStatement(lang, st); if (!local.containsKey(lws.getProperty())) { local.put(lws.getProperty(), new ArrayList<LocalWikidataStatement>()); } local.get(lws.getProperty()).add(lws); } return local; }
@Override public LocalWikidataStatement getLocalStatement(Language language, WikidataStatement statement) throws DaoException { language = getRealLang(language ); String item = getLabel(language, statement.getItem().getType(), statement.getItem().getId()); String prop = getLabel(language, statement.getProperty().getType(), statement.getProperty().getId()); String value = null; WikidataValue wdv = statement.getValue(); if (wdv.getType() == WikidataValue.Type.ITEM) { value = getLabel(language, WikidataEntity.Type.ITEM, wdv.getItemValue()); } else if (wdv.getValue() == null) { value = "unknown"; } else { value = wdv.getValue().toString(); } String full = item + " " + prop + " " + value; return new LocalWikidataStatement(language, statement, full, item, prop, value); }
@Override public LocalWikidataStatement getLocalStatement(Language language, WikidataStatement statement) throws DaoException { language = getRealLang(language ); String item = getLabel(language, statement.getItem().getType(), statement.getItem().getId()); String prop = getLabel(language, statement.getProperty().getType(), statement.getProperty().getId()); String value = null; WikidataValue wdv = statement.getValue(); if (wdv.getType() == WikidataValue.Type.ITEM) { value = getLabel(language, WikidataEntity.Type.ITEM, wdv.getItemValue()); } else if (wdv.getValue() == null) { value = "unknown"; } else { value = wdv.getValue().toString(); } String full = item + " " + prop + " " + value; return new LocalWikidataStatement(language, statement, full, item, prop, value); }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); WikidataDao wdDao = conf.get(WikidataDao.class); // Get page Title title = new Title("Berlin", env.getDefaultLanguage()); LocalPage page = lpDao.getByTitle(title, NameSpace.ARTICLE); System.out.println("Properties for " + title); // Show statements Map<String, List<LocalWikidataStatement>> statements = wdDao.getLocalStatements(page); for (String property : statements.keySet()) { System.out.println("values for property " + property + " are:"); for (LocalWikidataStatement lws : statements.get(property)) { System.out.println("\t" + lws.getFullStatement()); } } } }
@Override public Map<String, List<LocalWikidataStatement>> getLocalStatements(Language lang, WikidataEntity.Type type, int id) throws DaoException { lang = getRealLang(lang); WikidataFilter filter = new WikidataFilter.Builder() .withEntityType(type) .withEntityId(id) .build(); Map<String, List<LocalWikidataStatement>> local = new HashMap<String, List<LocalWikidataStatement>>(); for (WikidataStatement st : get(filter)) { LocalWikidataStatement lws = getLocalStatement(lang, st); if (!local.containsKey(lws.getProperty())) { local.put(lws.getProperty(), new ArrayList<LocalWikidataStatement>()); } local.get(lws.getProperty()).add(lws); } return local; }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); WikidataDao wdDao = conf.get(WikidataDao.class); UniversalPageDao univDao = conf.get(UniversalPageDao.class); Language lang = env.getDefaultLanguage(); // Show statements for berlin Title title = new Title("Berlin", lang); LocalPage page = lpDao.getByTitle(title, NameSpace.ARTICLE); Map<String, List<LocalWikidataStatement>> statements = wdDao.getLocalStatements(page); System.out.println("Properties for " + title); for (String property : statements.keySet()) { System.out.println("values for property " + property + " are:"); for (LocalWikidataStatement lws : statements.get(property)) { System.out.println("\t" + lws.getFullStatement()); } } // Print out who was born in Berlin WikidataValue berlinEntity = WikidataValue.forItem(univDao.getUnivPageId(page)); for (WikidataStatement st : wdDao.getByValue("place of birth", berlinEntity)) { System.out.println(wdDao.getLocalStatement(lang, st).getFullStatement()); } } }
public static void main(String args[]) throws ConfigurationException, DaoException { Env env = EnvBuilder.envFromArgs(args); Configurator conf = env.getConfigurator(); LocalPageDao lpDao = conf.get(LocalPageDao.class); WikidataDao wdDao = conf.get(WikidataDao.class); UniversalPageDao univDao = conf.get(UniversalPageDao.class); Language lang = env.getDefaultLanguage(); // Show statements for berlin Title title = new Title("Berlin", lang); LocalPage page = lpDao.getByTitle(title, NameSpace.ARTICLE); Map<String, List<LocalWikidataStatement>> statements = wdDao.getLocalStatements(page); System.out.println("Properties for " + title); for (String property : statements.keySet()) { System.out.println("values for property " + property + " are:"); for (LocalWikidataStatement lws : statements.get(property)) { System.out.println("\t" + lws.getFullStatement()); } } // Print out who was born in Berlin WikidataValue berlinEntity = WikidataValue.forItem(univDao.getUnivPageId(page)); for (WikidataStatement st : wdDao.getByValue("place of birth", berlinEntity)) { System.out.println(wdDao.getLocalStatement(lang, st).getFullStatement()); } } }