These use wikibase-cli and jq.
find-surname.js
:
module.exports = name => `SELECT ?item WHERE { ?item wdt:P31 wd:Q101352; rdfs:label '${name}'@en }`
with shell alias:
surname_find () {
wd sparql ~/Code/wikidata-scripting/names/find-surname.js $1 | tee >(pbcopy)
}
surname_set () {
wd ac $1 P734 $2
}
surname_find_and_set () {
surname_find $2 | xargs wd ac $1 P734
}
add-surname.js
:
module.exports = (name) => {
return {
type: 'item',
labels: { en: name },
descriptions: { en: 'Family name' },
claims: {
P31: { value: 'Q101352' },
P1705: { value: { text: name, language: 'mul' } },
P282: { value: 'Q8229' }
}
}
}
with shell alias:
surname_create () {
wd ce ~/Code/wikidata-scripting/names/add-surname.js $1 | jq -r .entity.id | tee >(pbcopy)
}
When a surname definitely doesn't already exist, the above can be combined as:
surname_create_and_set () {
wd ac $1 P734 $(surname_create $2)
}
In principle these could be combined further into a find-or-create approach, but I prefer trying the "known" route first and then manually follow up with a create-and-set where needed, at least until I'm more confident I know various failure modes etc.