lvaudor / glitter

an R package which writes SPARQL queries
https://lvaudor.github.io/glitter
44 stars 5 forks source link

simple query to label thing #173

Closed lvaudor closed 1 year ago

lvaudor commented 1 year ago

Hey!

I have been trying to write a function that would make it possible to find the label of a thing (it's something I need for the development of sequins but I guess the issue's place is actually here). For instance, calling

label("wd:Q152088", "en")

would return "french fries".

Well, the following function does the trick:

label=function(string, endpoint="Wikidata", language="en", labelling_prop="rdfs:label"){
  if(stringr::str_detect(string,"^\\?")){
    return(string)
  }
  result=spq_init() %>% 
    spq_add(glue::glue("{string} {labelling_prop} ?string_label")) %>% 
    spq_mutate(languages=lang(string_label)) %>% 
    spq_perform(endpoint=endpoint) %>% 
    dplyr::filter(languages==language) %>% 
    .$string_label
  return(result)
}

The thing is, I would also like to label properties with it. For instance

label("wdt:P31", "en")

would return "instance of". Unfortunately, it does not. It only works for "wd:P31" (without the "t"). In the same spirit

label("rdfs:name", "en") 

returns nothing (which is not surprising, but let's dream big).

Can you think of a way to label "usual" or Wikidata "wdt" properties as they appear in the queries themselves?

maelle commented 1 year ago

is this a duplicate of #201?

lvaudor commented 1 year ago

Ah, yes ! (tiens, j'ai de la suite dans les idées ;-))

maelle commented 1 year ago

Duplicate of #201