Skip to contents

Receive the label and description of a property on the basis of its PID from a Wikibase instance. It will not add further statements about the property.

Usage

get_property_definition(
  pid,
  language = c("en", "nl", "hu"),
  wikibase_api_url = "https://www.wikidata.org/w/api.php",
  return_type = "JSON",
  csrf = NULL
)

Arguments

pid

The PID of the property in the Wikibase instance (or Wikidata itself).

language

Defaults to c("en", "nl", "hu"). A character string of the languages in which the users wants to receive the labels and descriptions of the property. The vector of languages must use BCP 47-compliant language tags (e.g., "en" for English, and "hu" for Hungarian.)

wikibase_api_url

The full URL of the Wikibase API, which is the address that the wbdataset R client sends requests to when interacting with the knowledge base. In this case it defaults to 'https://www.wikidata.org/w/api.php', Wikidata itself, where no CSRF is needed.

return_type

Defaults to "data.frame" that is suitable for receiving the information in stand-alone use. The "JSON" passes on a JSON string in the format that you may need it in further Wikibase API calls.

csrf

The CSRF token of your session, received with get_csrf, not needed if wikibase_api_url="https://www.wikidata.org/w/api.php". Defaults to NULL.

Value

A data.frame of the PID with the labels and descriptions of the property in the selected languages. Alternatively, when return_type="JSON", the same data prepared for use in a subsequent API call, for example, to copy these contents into a new Wikibase instance.

Details

Currently the language has a choose a default, "en", for cases where the user-chosen language return empty labels and descriptions. This feature may be elaborated or changed later. The function receives aliases (alternative labels), too, but does not return them; the format of aliases needs to be decided in view of how other functions will use them, as aliases themselves can break the tidiness of the returned data.

Examples

# Receive a data.frame for further use
get_property_definition(pid = "P2047", return_type = "data.frame")
#>   source_pid language     label                                 description
#> 1      P2047       en  duration       length of time of an event or process
#> 2      P2047       nl tijdsduur tijdsduur van een evenement, werk of proces
#> 3      P2047       hu időtartam                   film, dal stb. időtartama
#>   datatype success
#> 1 quantity    TRUE
#> 2 quantity    TRUE
#> 3 quantity    TRUE

# Receive JSON for copying with wbeditidentiy
get_property_definition(pid = "P2047", language = c("en", "hu"))
#> {"labels":{"en":{"language":"en","value":"duration"},"hu":{"language":"hu","value":"időtartam"}},"descriptions":{"en":{"language":"en","value":"length of time of an event or process"},"hu":{"language":"hu","value":"film, dal stb. időtartama"}},"datatype":"quantity"}