@Test public void lookupProviders() throws IOException, URISyntaxException { Collection<String> providers = WikidataUtil.findTaxonIdProviders(); final Collection<String> properties = WikidataUtil.PROVIDER_TO_WIKIDATA.values(); assertThat(properties, everyItem(isIn(providers))); }
public static List<String> findTaxonIdProviders() throws IOException, URISyntaxException { List<String> providers = new ArrayList<>(); String sparlql = "SELECT ?scheme ?urlScheme ?idRegex WHERE { " + "?scheme wdt:P31 wd:Q42396390 . " + "} "; final String jsonString = executeQuery(sparlql); JsonNode jsonNode = new ObjectMapper().readTree(jsonString); if (jsonNode.has("results")) { JsonNode results = jsonNode.get("results"); if (results.has("bindings")) { JsonNode bindings = results.get("bindings"); for (JsonNode binding : bindings) { JsonNode scheme = binding.get("scheme"); if (valueExists(scheme)) { String taxonProvider = scheme.get("value").asText(); providers.add(StringUtils.replace(taxonProvider, "http: } } } } return providers; }
WikidataUtil { public static List<String> findTaxonIdProviders() throws IOException, URISyntaxException { List<String> providers = new ArrayList<>(); String sparlql = "SELECT ?scheme ?urlScheme ?idRegex WHERE { " + "?scheme wdt:P31 wd:Q42396390 . " + "} "; final String jsonString = executeQuery(sparlql); JsonNode jsonNode = new ObjectMapper().readTree(jsonString); if (jsonNode.has("results")) { JsonNode results = jsonNode.get("results"); if (results.has("bindings")) { JsonNode bindings = results.get("bindings"); for (JsonNode binding : bindings) { JsonNode scheme = binding.get("scheme"); if (valueExists(scheme)) { String taxonProvider = scheme.get("value").asText(); providers.add(StringUtils.replace(taxonProvider, "http: } } } } return providers; } }
WikidataUtil { public static List<String> findTaxonIdProviders() throws IOException, URISyntaxException { List<String> providers = new ArrayList<>(); String sparlql = "SELECT ?scheme ?urlScheme ?idRegex WHERE { " + "?scheme wdt:P31 wd:Q42396390 . " + "} "; final String jsonString = executeQuery(sparlql); JsonNode jsonNode = new ObjectMapper().readTree(jsonString); if (jsonNode.has("results")) { JsonNode results = jsonNode.get("results"); if (results.has("bindings")) { JsonNode bindings = results.get("bindings"); for (JsonNode binding : bindings) { JsonNode scheme = binding.get("scheme"); if (valueExists(scheme)) { String taxonProvider = scheme.get("value").asText(); providers.add(StringUtils.replace(taxonProvider, "http: } } } } return providers; }  }
WikidataUtil { public static List<String> findTaxonIdProviders() throws IOException, URISyntaxException { List<String> providers = new ArrayList<>(); String sparlql = "SELECT ?scheme ?urlScheme ?idRegex WHERE { " + "?scheme wdt:P31 wd:Q42396390 . " + "} "; final String jsonString = executeQuery(sparlql); JsonNode jsonNode = new ObjectMapper().readTree(jsonString); if (jsonNode.has("results")) { JsonNode results = jsonNode.get("results"); if (results.has("bindings")) { JsonNode bindings = results.get("bindings"); for (JsonNode binding : bindings) { JsonNode scheme = binding.get("scheme"); if (valueExists(scheme)) { String taxonProvider = scheme.get("value").asText(); providers.add(StringUtils.replace(taxonProvider, "http: } } } } return providers; }  static String executeQuery(String sparql); static List<String> findTaxonIdProviders(); static List<Taxon> findRelatedTaxonIds(String externalId); static void addLinkedTaxa(List<Taxon> relatedIds, JsonNode bindings); static String nonWdTaxonWhereClause(TaxonomyProvider taxonomyProvider, String taxonId); static String wdTaxonWhereClause(String taxonId); static String createSparqlQuery(String externalId, String preferredLanguage); static boolean valueExists(JsonNode name); }
WikidataUtil { public static List<String> findTaxonIdProviders() throws IOException, URISyntaxException { List<String> providers = new ArrayList<>(); String sparlql = "SELECT ?scheme ?urlScheme ?idRegex WHERE { " + "?scheme wdt:P31 wd:Q42396390 . " + "} "; final String jsonString = executeQuery(sparlql); JsonNode jsonNode = new ObjectMapper().readTree(jsonString); if (jsonNode.has("results")) { JsonNode results = jsonNode.get("results"); if (results.has("bindings")) { JsonNode bindings = results.get("bindings"); for (JsonNode binding : bindings) { JsonNode scheme = binding.get("scheme"); if (valueExists(scheme)) { String taxonProvider = scheme.get("value").asText(); providers.add(StringUtils.replace(taxonProvider, "http: } } } } return providers; }  static String executeQuery(String sparql); static List<String> findTaxonIdProviders(); static List<Taxon> findRelatedTaxonIds(String externalId); static void addLinkedTaxa(List<Taxon> relatedIds, JsonNode bindings); static String nonWdTaxonWhereClause(TaxonomyProvider taxonomyProvider, String taxonId); static String wdTaxonWhereClause(String taxonId); static String createSparqlQuery(String externalId, String preferredLanguage); static boolean valueExists(JsonNode name); static final Map<TaxonomyProvider, String> PROVIDER_TO_WIKIDATA; static final Map<String, TaxonomyProvider> WIKIDATA_TO_PROVIDER; }