Search in sources :

Example 1 with SearchResult

use of org.wikidata.query.rdf.tool.wikibase.SearchResponse.SearchResult in project wikidata-query-rdf by wikimedia.

the class WikibaseRepository method firstEntityIdForLabelStartingWith.

/**
 * Get the first id with the provided label in the provided language.
 *
 * @throws RetryableException thrown if there is an error communicating with
 *             wikibase
 */
public String firstEntityIdForLabelStartingWith(String label, String language, String type) throws RetryableException {
    URI uri = uris.searchForLabel(label, language, type);
    log.debug("Searching for entity using {}", uri);
    try {
        SearchResponse result = checkApi(getJson(new HttpGet(uri), SearchResponse.class));
        List<SearchResult> resultList = result.getSearch();
        if (resultList.isEmpty()) {
            return null;
        }
        return resultList.get(0).getId();
    } catch (IOException e) {
        throw new RetryableException("Error searching for page", e);
    }
}
Also used : RetryableException(org.wikidata.query.rdf.tool.exception.RetryableException) HttpGet(org.apache.http.client.methods.HttpGet) SearchResult(org.wikidata.query.rdf.tool.wikibase.SearchResponse.SearchResult) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 URI (java.net.URI)1 HttpGet (org.apache.http.client.methods.HttpGet)1 RetryableException (org.wikidata.query.rdf.tool.exception.RetryableException)1 SearchResult (org.wikidata.query.rdf.tool.wikibase.SearchResponse.SearchResult)1