Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce distinct language parameters for search and response #9

Merged
merged 1 commit into from
May 29, 2022

Conversation

giocomai
Copy link

@giocomai giocomai commented Mar 9, 2022

In both find_item and find_property there is currently only one language parameter. In spite of what the current documentation suggests, this is not "the language to return the labels and descriptions in", but rather the language in which the search is conducted. Indeed, labels and description are currently always returned in English, no matter what language is set to.

Search language is important, as the same string gives different results when searching in a different language. However, having the label and description always in English may be undesirable.

With this pull request, I suggest introducing a new parameter, response_language, to define this aspect. The API call this "uselang", which you may prefer. Indeed, the wbsearchentities API have a language and a uselang parameter, see: https://www.wikidata.org/w/api.php?action=help&modules=wbsearchentities

language Search in this language. This only affects how entities are selected, not the language in which the results are returned: this is controlled by the "uselang" parameter.

See below reprex that illustrates the difference:

library("WikidataR")
search_string <- "San Francesco"

# search in English, return labels and description in English (default)
find_item(search_string, "en")
#> 
#>  Wikidata item search
#> 
#> Number of results:    10 
#> 
#> Results:
#> 1     San Francesco (Q1174762) - Wikimedia disambiguation page 
#> 2     San Francesco (Q672894) - minor basilica in Bologna, Italy 
#> 3     San Francesco (Q3670083) - church in Pisa, Italy 
#> 4     Francis of Assisi (Q676555) - Italian Catholic saint, friar, deacon and preacher and founder of the Franciscan Order (1181/2–1226) 
#> 5     San Francesco (Q3670054) - church in Grosseto 
#> 6     San Francesco (Q3670107) - church in Volterra, Tuscany, Italy 
#> 7     San Francesco (Q3585331) - church building in Città di Castello, Italy 
#> 8     San Francesco (Q52989040) - school in Aosta in the province of Aosta (Italy) [school id: AOIP001000] 
#> 9     San Francesco (Q2341041) - church in Treviso 
#> 10    San Francesco (Q25051590) - church in Matelica, Italy


# search in Italian (see different result order), but still return label and description in English
find_item(search_string, "it")
#> 
#>  Wikidata item search
#> 
#> Number of results:    10 
#> 
#> Results:
#> 1     Francis of Assisi (Q676555) - Italian Catholic saint, friar, deacon and preacher and founder of the Franciscan Order (1181/2–1226) 
#> 2     San Francesco (Q1174762) - Wikimedia disambiguation page 
#> 3     Liganj (Q3238434) 
#> 4     San Francesco (Q52989040) - school in Aosta in the province of Aosta (Italy) [school id: AOIP001000] 
#> 5     San Francesco (Q25051590) - church in Matelica, Italy 
#> 6     Saint Francis (Q15588902) - painting attributed to Cimabue 
#> 7     San Francesco (Q3947085) - painting by Carlo Crivelli 
#> 8     San Francesco (Q18487343) - human settlement in Italy 
#> 9     St Francis (Q22337548) - painting by Bernardo Strozzi 
#> 10    Saint Francis of Assisi (Q23929176) - painting by Raphael

# search in Italian, return label and description in Italian
find_item(search_string, "it", response_language = "it")
#> 
#>  Wikidata item search
#> 
#> Number of results:    10 
#> 
#> Results:
#> 1     Francesco d'Assisi (Q676555) - religioso, santo e poeta italiano 
#> 2     San Francesco (Q1174762) - pagina di disambiguazione di un progetto Wikimedia 
#> 3     San Francesco del Carnaro (Q3238434) - frazione del comune croato di Laurana 
#> 4     San Francesco (Q52989040) - istituto comprensivo di Aosta in provincia di Aosta (Italia) [codice scuola: AOIP001000] 
#> 5     San Francesco (Q25051590) - chiesa in Matelica 
#> 6     San Francesco (Q15588902) - dipinto di Cimabue 
#> 7     San Francesco (Q3947085) - dipinto di Carlo Crivelli conservato nel Museo reale delle belle arti del Belgio a Bruxelles 
#> 8     San Francesco (Q18487343) - frazione di Pelago 
#> 9     San Francesco (Q22337548) - dipinto di Bernardo Strozzi 
#> 10    San Francesco (Q23929176) - dipinto di Raffaello

Created on 2022-03-09 by the reprex package (v2.0.1)

@TS404 TS404 merged commit 93b9466 into TS404:master May 29, 2022
@TS404
Copy link
Owner

TS404 commented May 29, 2022

Really useful commits - thank you! As a solely English speaker, I am prone to not thinking about the language aspects of these functions carefully enough. I appreciate the additions.

@giocomai
Copy link
Author

Excellent, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants