Skip to contents

Avoid failed writing attempts by checking if a label already matches an item.

Usage

check_existing_property(
  search_term,
  language,
  equivalence_property = NA_character_,
  equivalence_id = NA_character_,
  classification_property = NA_character_,
  classification_id = NA_character_,
  action = "create_property",
  log_file_name = NA_character_,
  data_curator = person("Unknown", "Person"),
  wikibase_api_url = "https://www.wikidata.org/w/api.php",
  csrf = NULL
)

Arguments

search_term

A label in the given language, for example, "Estonia".

language

A single language code that indicates the language of the label and description, using BCP 47-compliant language tags (e.g., "en" for English, "fr" for French).

equivalence_property

An optional PID of a property already defined in the same Wikibase instance that records the equivalence of this new property with a property defined elsewhere, for example, on Wikidata or CIDOC-CRM. Defaults to NA_character_; if left missing, no equivalence relations is will be claimed.

equivalence_id

An optional PID or other identifier in Wikibase that records the equivalence of the property. An external ID. Defaults to NA_character_; if left missing, no equivalence relations is will be claimed.

classification_property

The instance of, or subclass of, or superclass of property. Defaults to NA_character when not used.

classification_id

The QID of the class. Defaults to NA_character when not used.

action

Defaults to "create_property".

log_file_name

An explicitly stated full path to a possible CSV log file, defaults to NULL. If the value is NULL, no log file will be created.

data_curator

The name of the data curator who runs the function and creates the log file, created with person.

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.

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 or NULL.

Details

A wrapper around MediaWiki action=wbsearchentities.

Examples

# No CSRF needed for Wikidata, but you will need it for Wikibase Suit
check_existing_property(
    search_term="instance of",
    language = "en",
    wikibase_api_url="https://www.wikidata.org/w/api.php")
#> Person U (2025). "Wikibase Create Item Log (2025-04-03 09:06:43)."
#>   rowid action id_on_target label description language datatype wikibase_api_url
#>   <hvn> <chr>  <hvn_lbl_>   <hvn> <hvn_lbl_>  <hvn_lb> <chr>    <chr>           
#> 1 wd:P… creat… P31          inst… type to wh… en       wikibas… https://www.wik…
#> # ℹ 8 more variables: equivalence_property <hvn_lbl_>,
#> #   equivalence_id <hvn_lbl_>, classification_property <hvn_lbl_>,
#> #   classification_id <hvn_lbl_>, success <lgl>, comment <glue>, time <chr>,
#> #   logfile <chr>