private boolean keepEntity(WikidataEntity entity) { if (entity.getType() == WikidataEntity.Type.PROPERTY) { return true; } else if (universalIds.contains(entity.getId())) { return true; } else if (keepAllLabeledEntities && !entity.getLabels().isEmpty()) { return true; } else { return false; } }
private boolean keepEntity(WikidataEntity entity) { if (entity.getType() == WikidataEntity.Type.PROPERTY) { return true; } else if (universalIds.contains(entity.getId())) { return true; } else if (keepAllLabeledEntities && !entity.getLabels().isEmpty()) { return true; } else { return false; } }
@Override public Set<Integer> conceptsWithValue(String propertyName, WikidataValue value) throws DaoException { Set<Integer> concepts = new HashSet<Integer>(); for (WikidataStatement st : getByValue(propertyName, value)) { if (st.getItem().getType() == WikidataEntity.Type.ITEM) { concepts.add(st.getItem().getId()); } } return concepts; }
@Override public Set<Integer> conceptsWithValue(String propertyName, WikidataValue value) throws DaoException { Set<Integer> concepts = new HashSet<Integer>(); for (WikidataStatement st : getByValue(propertyName, value)) { if (st.getItem().getType() == WikidataEntity.Type.ITEM) { concepts.add(st.getItem().getId()); } } return concepts; }
@Override public Iterable<WikidataStatement> getByValue(String propertyName, WikidataValue value) throws DaoException { Set<Integer> propIds = new HashSet<Integer>(); for (WikidataEntity e : getPropertyByName(propertyName)) { propIds.add(e.getId()); } if (propIds.isEmpty()) { return new ArrayList<WikidataStatement>(); } WikidataFilter filter = new WikidataFilter.Builder() .withPropertyIds(propIds) .withValue(value) .build(); return get(filter); }
@Override public Iterable<WikidataStatement> getByValue(String propertyName, WikidataValue value) throws DaoException { Set<Integer> propIds = new HashSet<Integer>(); for (WikidataEntity e : getPropertyByName(propertyName)) { propIds.add(e.getId()); } if (propIds.isEmpty()) { return new ArrayList<WikidataStatement>(); } WikidataFilter filter = new WikidataFilter.Builder() .withPropertyIds(propIds) .withValue(value) .build(); return get(filter); }
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 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); } }
@Override public Iterable<WikidataStatement> getByValue(WikidataEntity property, WikidataValue value) throws DaoException { WikidataFilter filter = new WikidataFilter.Builder() .withPropertyId(property.getId()) .withValue(value) .build(); return get(filter); }
@Override public Iterable<WikidataStatement> getByValue(WikidataEntity property, WikidataValue value) throws DaoException { WikidataFilter filter = new WikidataFilter.Builder() .withPropertyId(property.getId()) .withValue(value) .build(); return get(filter); }
@Override public double score(LocalId candidate, Map<String, String> row, Geometry geometry) throws DaoException { for (WikidataStatement st : wikidataDao.getStatements(candidate.asLocalPage())) { if (st.getProperty() == null || st.getProperty().getId() != INSTANCE_OF_PROPERTY) { continue; } if (st.getValue().getType() == WikidataValue.Type.ITEM) { String name = getPropertyName(st.getValue().getIntValue()); if (name != null && instanceOfKeywords.contains(name.toLowerCase())) { return 1.0; } } } return 0.0; }
@Override public double score(LocalId candidate, Map<String, String> row, Geometry geometry) throws DaoException { for (WikidataStatement st : wikidataDao.getStatements(candidate.asLocalPage())) { if (st.getProperty() == null || st.getProperty().getId() != INSTANCE_OF_PROPERTY) { continue; } if (st.getValue().getType() == WikidataValue.Type.ITEM) { String name = getPropertyName(st.getValue().getIntValue()); if (name != null && instanceOfKeywords.contains(name.toLowerCase())) { return 1.0; } } } return 0.0; }
private boolean storeStatement(TIntSet savedConcepts, LanguageSet langs, WikidataStatement statement) throws DaoException { UniversalPage uPage = wdDao.getUniversalPage(statement.getItem().getId()); if (uPage == null || !uPage.isInLanguageSet(langs, false)){ return false; } int itemId = statement.getItem().getId(); Geometry g = WikiBrainSpatialUtils.jsonToGeometry(statement.getValue().getJsonValue().getAsJsonObject()); if (g == null) { return false; } if (savedConcepts.contains(itemId)) { return false; } savedConcepts.add(itemId); spatialDao.saveGeometry(itemId, Layers.WIKIDATA, RefSys.EARTH, g); miDao.incrementRecords(Geometry.class); return true; } }
private boolean storeStatement(TIntSet savedConcepts, LanguageSet langs, WikidataStatement statement) throws DaoException { UniversalPage uPage = wdDao.getUniversalPage(statement.getItem().getId()); if (uPage == null || !uPage.isInLanguageSet(langs, false)){ return false; } int itemId = statement.getItem().getId(); Geometry g = WikiBrainSpatialUtils.jsonToGeometry(statement.getValue().getJsonValue().getAsJsonObject()); if (g == null) { return false; } if (savedConcepts.contains(itemId)) { return false; } savedConcepts.add(itemId); spatialDao.saveGeometry(itemId, Layers.WIKIDATA, RefSys.EARTH, g); miDao.incrementRecords(Geometry.class); return true; } }
@Override public double score(LocalId candidate, Map<String, String> row, Geometry geometry) throws DaoException { for (WikidataStatement st : wikidataDao.getStatements(candidate.asLocalPage())) { if (st.getProperty() == null || st.getProperty().getId() != COORDINATE_PROPERTY) { continue; } Geometry point = WikiBrainSpatialUtils.jsonToGeometry(st.getValue().getJsonValue().getAsJsonObject()); if (point != null && geometry.contains(point)) { return 1.0; } } return 0.0; } }
@Override public double score(LocalId candidate, Map<String, String> row, Geometry geometry) throws DaoException { for (WikidataStatement st : wikidataDao.getStatements(candidate.asLocalPage())) { if (st.getProperty() == null || st.getProperty().getId() != COORDINATE_PROPERTY) { continue; } Geometry point = WikiBrainSpatialUtils.jsonToGeometry(st.getValue().getJsonValue().getAsJsonObject()); if (point != null && geometry.contains(point)) { return 1.0; } } return 0.0; } }
@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); }