private String getPropertyName(int id) throws DaoException { String name = propertyNames.get(id); if (name != null && name.equals("__NULL__")) { return null; } else if (name != null) { return name; } WikidataEntity entity = wikidataDao.getItem(id); if (entity == null) { name = null; } else if (entity.getLabels().containsKey(Language.EN)) { name = entity.getLabels().get(Language.EN); } else if (entity.getLabels().containsKey(Language.SIMPLE)) { name = entity.getLabels().get(Language.SIMPLE); } else { name = null; } propertyNames.put(id, name == null ? "__NULL__" : name); return name; } }
public final void loadData(final LanguageSet langs) throws DaoException { final TIntSet savedConcepts = TCollections.synchronizedSet(new TIntHashSet()); final AtomicInteger matches = new AtomicInteger(); final AtomicInteger count = new AtomicInteger(); WikidataFilter filter = (new WikidataFilter.Builder()).withPropertyId(COORDINATE_LOCATION_PROPERTY_ID).build(); Iterable<WikidataStatement> statements = wdDao.get(filter); ParallelForEach.iterate(statements.iterator(), WpThreadUtils.getMaxThreads(), 100, new Procedure<WikidataStatement>() { @Override public void call(WikidataStatement statement) throws Exception { try { if (storeStatement(savedConcepts, langs, statement)) { matches.incrementAndGet(); } } catch (Exception e) { LOG.error("storage of statement failed: " + statement.toString(), e); miDao.incrementErrorsQuietly(Geometry.class); } if (count.incrementAndGet() % 10000 == 0){ LOG.info("Matched " + matches + " out of " + count + " statements from " + this.getClass().getName()); } } }, Integer.MAX_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); 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()); } } }
Integer id = wdDao.getItemId(lp); Geometry rootPoint = sdDao.getGeometry(id, layerName, "earth"); Map<Integer, Geometry> resMap = snDao.getNeighbors(rootPoint, layerName, "earth", new HashSet<Integer>()); System.out.println(i.toString() + " " + wdDao.getUniversalPage(i).getBestEnglishTitle(lpDao, true).getCanonicalTitle() + " " + distanceMetrics.getDistance(resMap.get(i), rootPoint) + " km");
for (WikidataStatement st : wd.getByValue("instance of", WikidataValue.forItem(6256))) { int countryId = st.getItem().getId(); WikidataEntity country = wd.getItem(countryId); Geometry geometry = sd.getGeometry(countryId, "wikidata", "earth"); if (geometry != null) {
@Override public Geometry getGeometry(String articleName, Language language, String layerName, String refSysName) throws DaoException { LocalPage lp = localPageDao.getByTitle(new Title(articleName, language), NameSpace.ARTICLE); if (lp == null) return null; Integer id = wikidataDao.getItemId(lp); if (id == null) throw new DaoException("Could not find Wikidata item for \"" + lp.toString() + "\""); return getGeometry(id, layerName); }
public WikidataValueScorer(Env env, Config conf) throws ConfigurationException { super(env, conf); try { wikidataDao = env.getConfigurator().get(WikidataDao.class); columnName = conf.getString("column"); Language lang = env.getLanguages().getBestAvailableEnglishLang(false); WikidataEntity prop = wikidataDao.getProperty(lang, conf.getString("property")); if (prop == null) { throw new IllegalArgumentException("Couldn't find property with name " + conf.getString("property")); } propertyId = prop.getId(); } catch (WikiBrainException e) { throw new ConfigurationException(e); } catch (DaoException e) { throw new ConfigurationException(e); } }
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()); } } } }
Integer id = wdDao.getItemId(lp); Geometry rootPoint = sdDao.getGeometry(id, layerName, "earth"); Map<Integer, Geometry> resMap = snDao.getNeighbors(rootPoint, layerName, "earth", new HashSet<Integer>()); System.out.println(i.toString() + " " + wdDao.getUniversalPage(i).getBestEnglishTitle(lpDao, true).getCanonicalTitle() + " " + distanceMetrics.getDistance(resMap.get(i), rootPoint) + " km");
for (WikidataStatement st : wd.getByValue("instance of", WikidataValue.forItem(6256))) { int countryId = st.getItem().getId(); WikidataEntity country = wd.getItem(countryId); Geometry geometry = sd.getGeometry(countryId, "wikidata", "earth"); if (geometry != null) {
@Override public Geometry getGeometry(String articleName, Language language, String layerName, String refSysName) throws DaoException { LocalPage lp = localPageDao.getByTitle(new Title(articleName, language), NameSpace.ARTICLE); if (lp == null) return null; Integer id = wikidataDao.getItemId(lp); if (id == null) throw new DaoException("Could not find Wikidata item for \"" + lp.toString() + "\""); return getGeometry(id, layerName); }
public WikidataValueScorer(Env env, Config conf) throws ConfigurationException { super(env, conf); try { wikidataDao = env.getConfigurator().get(WikidataDao.class); columnName = conf.getString("column"); Language lang = env.getLanguages().getBestAvailableEnglishLang(false); WikidataEntity prop = wikidataDao.getProperty(lang, conf.getString("property")); if (prop == null) { throw new IllegalArgumentException("Couldn't find property with name " + conf.getString("property")); } propertyId = prop.getId(); } catch (WikiBrainException e) { throw new ConfigurationException(e); } catch (DaoException e) { throw new ConfigurationException(e); } }
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()); } } } }
public static void main(String[] args){ try { Env env = new EnvBuilder().build(); Configurator c = env.getConfigurator(); SpatialContainmentDao scDao = c.get(SpatialContainmentDao.class); WikidataDao wdDao = c.get(WikidataDao.class); LocalPageDao lpDao = c.get(LocalPageDao.class); LanguageSet loadedLangs = lpDao.getLoadedLanguages(); // set up the parameters for the call to getContainedItemIds String containerName = "Israel"; Set<String> subLayers = Sets.newHashSet(); subLayers.add("wikidata"); LocalPage lp = lpDao.getByTitle(new Title(containerName,Language.getByLangCode("simple")), NameSpace.ARTICLE); Integer id = wdDao.getItemId(lp); TIntSet containedItemIds = scDao.getContainedItemIds(id, Layers.COUNTRY, RefSys.EARTH, subLayers, SpatialContainmentDao.ContainmentOperationType.CONTAINMENT); int counter = 0; System.out.println("Items contained in the spatial footprint of the article '" + lp.getTitle() + "' are:"); for (int cId : containedItemIds.toArray()){ UniversalPage univPage = wdDao.getUniversalPage(cId); Title t = univPage.getBestEnglishTitle(lpDao, true); System.out.println(t.getCanonicalTitle()); counter++; } System.out.printf("Found %d items\n", counter); } catch(Exception e){ e.printStackTrace(); } }
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()); } } }
private String getPropertyName(int id) throws DaoException { String name = propertyNames.get(id); if (name != null && name.equals("__NULL__")) { return null; } else if (name != null) { return name; } WikidataEntity entity = wikidataDao.getItem(id); if (entity == null) { name = null; } else if (entity.getLabels().containsKey(Language.EN)) { name = entity.getLabels().get(Language.EN); } else if (entity.getLabels().containsKey(Language.SIMPLE)) { name = entity.getLabels().get(Language.SIMPLE); } else { name = null; } propertyNames.put(id, name == null ? "__NULL__" : name); return name; } }
Integer containerId1 = wdDao.getItemId(lpDao.getByTitle(new Title("China", Language.getByLangCode("simple")), NameSpace.ARTICLE)); TIntSet containedItemIds1 = scDao.getContainedItemIds(containerId1,layerName1, "earth", subLayers, SpatialContainmentDao.ContainmentOperationType.CONTAINMENT); Integer containerId2 = wdDao.getItemId(lpDao.getByTitle(new Title("California", Language.getByLangCode("simple")), NameSpace.ARTICLE)); TIntSet containedItemIds2 = scDao.getContainedItemIds(containerId2,layerName2, "earth", subLayers, SpatialContainmentDao.ContainmentOperationType.CONTAINMENT);
public final void loadData(final LanguageSet langs) throws DaoException { final TIntSet savedConcepts = TCollections.synchronizedSet(new TIntHashSet()); final AtomicInteger matches = new AtomicInteger(); final AtomicInteger count = new AtomicInteger(); WikidataFilter filter = (new WikidataFilter.Builder()).withPropertyId(COORDINATE_LOCATION_PROPERTY_ID).build(); Iterable<WikidataStatement> statements = wdDao.get(filter); ParallelForEach.iterate(statements.iterator(), WpThreadUtils.getMaxThreads(), 100, new Procedure<WikidataStatement>() { @Override public void call(WikidataStatement statement) throws Exception { try { if (storeStatement(savedConcepts, langs, statement)) { matches.incrementAndGet(); } } catch (Exception e) { LOG.error("storage of statement failed: " + statement.toString(), e); miDao.incrementErrorsQuietly(Geometry.class); } if (count.incrementAndGet() % 10000 == 0){ LOG.info("Matched " + matches + " out of " + count + " statements from " + this.getClass().getName()); } } }, Integer.MAX_VALUE); }