public Map<String, List<WikidataStatement>> getStatementsInLanguage(Language language) { Map<String, List<WikidataStatement>> inLang = new HashMap<String, List<WikidataStatement>>(); for (WikidataStatement s : statements) { String label = s.getProperty().getLabels().get(language); if (label != null) { if (!inLang.containsKey(label)) { inLang.put(label, new ArrayList<WikidataStatement>()); } inLang.get(label).add(s); } } return inLang; }
public Map<String, List<WikidataStatement>> getStatementsInLanguage(Language language) { Map<String, List<WikidataStatement>> inLang = new HashMap<String, List<WikidataStatement>>(); for (WikidataStatement s : statements) { String label = s.getProperty().getLabels().get(language); if (label != null) { if (!inLang.containsKey(label)) { inLang.put(label, new ArrayList<WikidataStatement>()); } inLang.get(label).add(s); } } return inLang; }
@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 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; }
@Override public double score(LocalId candidate, Map<String, String> row, Geometry geometry) throws DaoException { if (!row.containsKey(columnName)) { throw new IllegalArgumentException("No column with name " + columnName + " in dbx"); } String rowValue = row.get(columnName).toString(); for (WikidataStatement st : wikidataDao.getStatements(candidate.asLocalPage())) { if (st.getProperty() == null || st.getProperty().getId() != propertyId) { continue; } String candidateVal = null; if (st.getValue().getType() == WikidataValue.Type.ITEM) { candidateVal = String.valueOf(st.getValue().getItemValue()); } else if (st.getValue().getType() == WikidataValue.Type.INT) { candidateVal = String.valueOf(st.getValue().getIntValue()); } else if (st.getValue().getType() == WikidataValue.Type.STRING) { candidateVal = st.getValue().getStringValue(); } else { LOG.warn("Unexpected type for property " + st.getProperty() + ": " + st.getValue()); } if (candidateVal != null && candidateVal.equalsIgnoreCase(rowValue)) { return 1.0; } } return 0.0; } }
@Override public double score(LocalId candidate, Map<String, String> row, Geometry geometry) throws DaoException { if (!row.containsKey(columnName)) { throw new IllegalArgumentException("No column with name " + columnName + " in dbx"); } String rowValue = row.get(columnName).toString(); for (WikidataStatement st : wikidataDao.getStatements(candidate.asLocalPage())) { if (st.getProperty() == null || st.getProperty().getId() != propertyId) { continue; } String candidateVal = null; if (st.getValue().getType() == WikidataValue.Type.ITEM) { candidateVal = String.valueOf(st.getValue().getItemValue()); } else if (st.getValue().getType() == WikidataValue.Type.INT) { candidateVal = String.valueOf(st.getValue().getIntValue()); } else if (st.getValue().getType() == WikidataValue.Type.STRING) { candidateVal = st.getValue().getStringValue(); } else { LOG.warn("Unexpected type for property " + st.getProperty() + ": " + st.getValue()); } if (candidateVal != null && candidateVal.equalsIgnoreCase(rowValue)) { 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); }
@Override public void save(WikidataStatement item) throws DaoException { insert( item.getId(), item.getItem().getType().code, item.getItem().getId(), item.getProperty().getId(), item.getValue().getTypeName().toLowerCase(), encodeValue(item.getValue()), item.getRank().ordinal() ); }
@Override public void save(WikidataStatement item) throws DaoException { insert( item.getId(), item.getItem().getType().code, item.getItem().getId(), item.getProperty().getId(), item.getValue().getTypeName().toLowerCase(), encodeValue(item.getValue()), item.getRank().ordinal() ); }