-
Notifications
You must be signed in to change notification settings - Fork 1
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
Japan Road Race Championship template request #2
Comments
That could look something like this: // template.js
const datePattern = /^\d{4}-\d{2}-\d{2}$/
const itemIdPattern = /^Q\d+$/
const ordinalPattern = /^\d+$/
module.exports = (label, year, location, start, end, follows, isFollowedBy, ordinal) => {
const championship = championships[year]
const type = types[location]
const location = locations[location]
// Validating arguments as it would be easy to get messed up given the number of arguments to pass
if (label.split(' ').length < 4) throw new Error(`that label looks too short: ${label}`)
if (!championship) throw new Error(`unknown championship: ${championship}`)
if (!type) throw new Error(`unknown type: ${type}`)
if (!location) throw new Error(`unknown location: ${location}`)
if (!datePattern.test(start)) throw new Error(`invalid start date: ${start}`)
if (!datePattern.test(end)) throw new Error(`invalid end date: ${end}`)
// Make those qualifier values optional: pass null to skip
if (follows === 'null') follows === null
if (isFollowedBy === 'null') isFollowedBy === null
if (follows && !itemIdPattern.test(follows)) throw new Error(`invalid follows item id: ${follows}`)
if (isFollowedBy && !itemIdPattern.test(isFollowedBy)) throw new Error(`invalid isFollowedBy item id: ${isFollowedBy}`)
if (!ordinalPattern.test(ordinal)) throw new Error(`invalid ordinal number: ${ordinal}`)
const qualifiers = {
P156: ordinal
}
if (follows) qualifiers.P155 = follows
if (isFollowedBy) qualifiers.P156 = isFollowedBy
const newItem = {
labels: {
en: label
},
claims: {
P31: { value: type, qualifiers },
P361: { value: championship, qualifiers },
P17: 'Q17',
P276: location,
P580: start,
P582: end,
}
}
return newItem
}
const championships = {
2019: 'Q106725472',
2018: 'Q106726771',
2017: 'Q106726795',
}
const types = {
'Okayama': 'Q106712954',
'Motegi': 'Q106712966',
}
const locations = {
'Okayama': 'Q173185',
'Motegi': 'Q1420895',
} to be then called from the CLI like that: wd create-entity ./template.js "2019 All Japan Road Race Championship Round 6 Okayama" 2019 Okayama 2019-08-30 2019-09-01 null Q106713038 12 I haven't tested it so it might require some adjustments ^^ |
@maxlath |
I completed the const lists at the bottom as follow :
Tried :
Got this output :
Replaced location by locatione in line 9 ; line 15 (!locatione) ; line 42
Got :
Tried :
as a dummy edit, to avoid coming up against the null error above again Got :
At the beginning I remember getting the credential set up prompt, I followed the instructions, choose OAuth, copy/pasted the 4 "keys" from the meta.wikimedia webpage into the terminal ( but I didn't "tick" any of the boxes on the webpage, didn't change anything, just went to the bottom of webpage and clicked on some kind of validation button (from memory) ). Now I'm wondering if I should have ticked some of those boxes to be able to get the proper permission... I tried
The 4 "keys" show up In the "Manage connected applications" webpage of meta.wikimedia.org, for wikibase-cli-myusername I only have "revoke access" not "manage access" ( I was hoping to be able to activate the necessary permission which I might have missed at the "ticking boxes" step... Let me know if you need me to try something else. |
So I did a few mistakes in the template >< which I could have easily tested by running the command with the // template.js
const datePattern = /^\d{4}-\d{2}-\d{2}$/
const itemIdPattern = /^Q\d+$/
const ordinalPattern = /^\d+$/
module.exports = (label, year, locationName, start, end, follows, isFollowedBy, ordinal) => {
console.error({ label, year, locationName, start, end, follows, isFollowedBy, ordinal })
const championship = championships[year]
const type = types[locationName]
const location = locations[locationName]
// Validating arguments as it would be easy to get messed up given the number of arguments to pass
if (label.split(' ').length < 4) throw new Error(`that label looks too short: ${label}`)
if (!championship) throw new Error(`unknown championship: ${championship}`)
if (!type) throw new Error(`unknown type: ${type}`)
if (!location) throw new Error(`unknown location: ${location}`)
if (!datePattern.test(start)) throw new Error(`invalid start date: ${start}`)
if (!datePattern.test(end)) throw new Error(`invalid end date: ${end}`)
// Make those qualifier values optional: pass null to skip
if (follows === 'null') follows = null
if (isFollowedBy === 'null') isFollowedBy = null
if (follows && !itemIdPattern.test(follows)) throw new Error(`invalid follows item id: ${follows}`)
if (isFollowedBy && !itemIdPattern.test(isFollowedBy)) throw new Error(`invalid isFollowedBy item id: ${isFollowedBy}`)
if (!ordinalPattern.test(ordinal)) throw new Error(`invalid ordinal number: ${ordinal}`)
const qualifiers = {
P156: ordinal
}
if (follows) qualifiers.P155 = follows
if (isFollowedBy) qualifiers.P156 = isFollowedBy
const newItem = {
labels: {
en: label
},
claims: {
P31: { value: type, qualifiers },
P361: { value: championship, qualifiers },
P17: 'Q17',
P276: location,
P580: start,
P582: end,
}
}
return newItem
}
const championships = {
2021: 'Q106735845',
2020: 'Q106707657',
2019: 'Q106725472',
2018: 'Q106726771',
2017: 'Q106726795',
2016: 'Q106726816',
2015: 'Q106726831',
}
const types = {
'Autopolis': 'Q106705839',
'Autopolis 2&4' : 'Q106763105',
'MFJ GP' : 'Q106712980',
'Motegi': 'Q106712966',
'Motegi 2&4' : 'Q106763118',
'Okayama': 'Q106712954',
'Sugo' : 'Q106697764',
'Suzuka' : 'Q106737001',
'Suzuka 2&4' : 'Q106737001',
'Tsukuba' : 'Q106725499',
}
const locations = {
'Autopolis' : 'Q1748785',
'Motegi': 'Q1420895',
'Okayama': 'Q173185',
'Sugo' : 'Q917398',
'Suzuka' : 'Q174170',
'Tsukuba' : 'Q2097263',
} As for the permissions, I would recommand to delete the previous tokens and run: wb config credentials https://www.wikidata.org reset and select the following authorizations:
|
There was a tiny typo line 29 ( I tried to make the Would it be possible :
Test case with the current syntax :
Allowed me to create
Following the proposed pattern, the ideal ( at least in my mind, at this point...) syntax would resemble something like :
And the result should be as it it appears for Q106799195 ( created manually for the demo purpose ) I'm not sure my explanations are clear enough, so I could create the items manually as they are expected to appear for each parameter combination/CLI syntax if you feel it's necessary, it wouldn't a problem at all for me, feel free to ask if you think it may save you some time. Thanks again for your help |
could be something like this? // template.js
const datePattern = /^\d{4}-\d{2}-\d{2}$/
const itemIdPattern = /^Q\d+$/
const ordinalPattern = /^\d+$/
module.exports = (label, year, locationName, followsP31, ordinalP31, isFollowedP31, followsP361, ordinalP361, isFollowedP361, start, end ) => {
console.error({ label, year, locationName, followsP31, ordinalP31, isFollowedP31, followsP361, ordinalP361, isFollowedP361, start, end })
const championship = championships[year]
const type = types[locationName]
const location = locations[locationName]
// Validating arguments as it would be easy to get messed up given the number of arguments to pass
if (label.split(' ').length < 4) throw new Error(`that label looks too short: ${label}`)
if (!championship) throw new Error(`unknown championship: ${championship}`)
if (!type) throw new Error(`unknown type: ${type}`)
if (!location) throw new Error(`unknown location: ${location}`)
if (!datePattern.test(start)) throw new Error(`invalid start date: ${start}`)
if (!datePattern.test(end)) throw new Error(`invalid end date: ${end}`)
// Make those qualifier values optional: pass null to skip
if (followsP31 === 'null') followsP31 = null
if (isFollowedByP31 === 'null') isFollowedByP31 = null
if (ordinalP31 === 'null') ordinalP31 = null
if (followsP31 === 'somevalue') followsP31 = { snaktype: 'somevalue' }
if (isFollowedByP31 === 'somevalue') isFollowedByP31 = { snaktype: 'somevalue' }
if (ordinalP31 === 'somevalue') ordinalP31 = { snaktype: 'somevalue' }
if (isNormalSnaktypeValue(followsP31) && !itemIdPattern.test(followsP31)) throw new Error(`invalid followsP31 item id: ${followsP31}`)
if (isNormalSnaktypeValue(isFollowedByP31) && !itemIdPattern.test(isFollowedByP31)) throw new Error(`invalid isFollowedByP31 item id: ${isFollowedByP31}`)
if (isNormalSnaktypeValue(ordinalP31) && !ordinalP31Pattern.test(ordinalP31)) throw new Error(`invalid ordinalP31 number: ${ordinalP31}`)
const qualifiersP31 = {}
if (followsP31) qualifiersP31.P155 = followsP31
if (isFollowedByP31) qualifiersP31.P156 = isFollowedByP31
if (ordinalP31) qualifiersP31.P1545 = ordinalP31
if (followsP361 === 'null') followsP361 = null
if (isFollowedByP361 === 'null') isFollowedByP361 = null
if (ordinalP361 === 'null') ordinalP361 = null
if (followsP361 === 'somevalue') followsP361 = { snaktype: 'somevalue' }
if (isFollowedByP361 === 'somevalue') isFollowedByP361 = { snaktype: 'somevalue' }
if (ordinalP361 === 'somevalue') ordinalP361 = { snaktype: 'somevalue' }
if (isNormalSnaktypeValue(followsP361) && !itemIdPattern.test(followsP361)) throw new Error(`invalid followsP361 item id: ${followsP361}`)
if (isNormalSnaktypeValue(isFollowedByP361) && !itemIdPattern.test(isFollowedByP361)) throw new Error(`invalid isFollowedByP361 item id: ${isFollowedByP361}`)
if (isNormalSnaktypeValue(ordinalP361) && !ordinalP361Pattern.test(ordinalP361)) throw new Error(`invalid ordinalP361 number: ${ordinalP361}`)
const qualifiersP361 = {}
if (followsP361) qualifiersP361.P155 = followsP361
if (isFollowedByP361) qualifiersP361.P156 = isFollowedByP361
if (ordinalP361) qualifiersP361.P1545 = ordinalP361
const newItem = {
labels: {
en: label
},
claims: {
P31: { value: type, qualifiers: qualifiersP31 },
P361: { value: championship, qualifiers: qualifiersP361 },
P17: 'Q17',
P276: location,
P580: start,
P582: end,
}
}
return newItem
}
const championships = {
2021: 'Q106735845',
2020: 'Q106707657',
2019: 'Q106725472',
2018: 'Q106726771',
2017: 'Q106726795',
2016: 'Q106726816',
2015: 'Q106726831',
}
const types = {
'Autopolis': 'Q106705839',
'Autopolis 2&4' : 'Q106763105',
'MFJ GP' : 'Q106712980',
'Motegi': 'Q106712966',
'Motegi 2&4' : 'Q106763118',
'Okayama': 'Q106712954',
'Sugo' : 'Q106697764',
'Suzuka' : 'Q106737001',
'Suzuka 2&4' : 'Q106737001',
'Tsukuba' : 'Q106725499',
}
const locations = {
'Autopolis' : 'Q1748785',
'Motegi': 'Q1420895',
'Okayama': 'Q173185',
'Sugo' : 'Q917398',
'Suzuka' : 'Q174170',
'Tsukuba' : 'Q2097263',
}
const isNormalSnaktypeValue = value => typeof value === 'string' |
Below is the one I used, I just had to define There's just the qualifiers orders but it's cosmetic so don't bother it'll do like this. Once again, thanks for bestowing your magic on this, for kicks I'll try to do a whole or even half a season manually and the same using your code, just to fully realize how much time you saved me, and if I do I'll report the numbers. // template.js
const datePattern = /^\d{4}-\d{2}-\d{2}$/
const itemIdPattern = /^Q\d+$/
const ordinalPattern = /^\d+$/
const ordinalP31Pattern = /^\d+$/
const ordinalP361Pattern = /^\d+$/
module.exports = (label, year, locationName, followsP31, ordinalP31, isFollowedP31, followsP361, ordinalP361, isFollowedP361, start, end ) => {
console.error({ label, year, locationName, followsP31, ordinalP31, isFollowedP31, followsP361, ordinalP361, isFollowedP361, start, end })
const championship = championships[year]
const type = types[locationName]
const location = locations[locationName]
// Validating arguments as it would be easy to get messed up given the number of arguments to pass
if (label.split(' ').length < 4) throw new Error(`that label looks too short: ${label}`)
if (!championship) throw new Error(`unknown championship: ${championship}`)
if (!type) throw new Error(`unknown type: ${type}`)
if (!location) throw new Error(`unknown location: ${location}`)
if (!datePattern.test(start)) throw new Error(`invalid start date: ${start}`)
if (!datePattern.test(end)) throw new Error(`invalid end date: ${end}`)
// Make those qualifier values optional: pass null to skip
if (followsP31 === 'null') followsP31 = null
if (isFollowedP31 === 'null') isFollowedP31 = null
if (ordinalP31 === 'null') ordinalP31 = null
if (followsP31 === 'somevalue') followsP31 = { snaktype: 'somevalue' }
if (isFollowedP31 === 'somevalue') isFollowedP31 = { snaktype: 'somevalue' }
if (ordinalP31 === 'somevalue') ordinalP31 = { snaktype: 'somevalue' }
if (isNormalSnaktypeValue(followsP31) && !itemIdPattern.test(followsP31)) throw new Error(`invalid followsP31 item id: ${followsP31}`)
if (isNormalSnaktypeValue(isFollowedP31) && !itemIdPattern.test(isFollowedP31)) throw new Error(`invalid isFollowedP31 item id: ${isFollowedP31}`)
if (isNormalSnaktypeValue(ordinalP31) && !ordinalP31Pattern.test(ordinalP31)) throw new Error(`invalid ordinalP31 number: ${ordinalP31}`)
const qualifiersP31 = {}
if (followsP31) qualifiersP31.P155 = followsP31
if (isFollowedP31) qualifiersP31.P156 = isFollowedP31
if (ordinalP31) qualifiersP31.P1545 = ordinalP31
if (followsP361 === 'null') followsP361 = null
if (isFollowedP361 === 'null') isFollowedP361 = null
if (ordinalP361 === 'null') ordinalP361 = null
if (followsP361 === 'somevalue') followsP361 = { snaktype: 'somevalue' }
if (isFollowedP361 === 'somevalue') isFollowedP361 = { snaktype: 'somevalue' }
if (ordinalP361 === 'somevalue') ordinalP361 = { snaktype: 'somevalue' }
if (isNormalSnaktypeValue(followsP361) && !itemIdPattern.test(followsP361)) throw new Error(`invalid followsP361 item id: ${followsP361}`)
if (isNormalSnaktypeValue(isFollowedP361) && !itemIdPattern.test(isFollowedP361)) throw new Error(`invalid isFollowedP361 item id: ${isFollowedP361}`)
if (isNormalSnaktypeValue(ordinalP361) && !ordinalP361Pattern.test(ordinalP361)) throw new Error(`invalid ordinalP361 number: ${ordinalP361}`)
const qualifiersP361 = {}
if (followsP361) qualifiersP361.P155 = followsP361
if (isFollowedP361) qualifiersP361.P156 = isFollowedP361
if (ordinalP361) qualifiersP361.P1545 = ordinalP361
const newItem = {
labels: {
en: label
},
claims: {
P31: { value: type, qualifiers: qualifiersP31 },
P361: { value: championship, qualifiers: qualifiersP361 },
P17: 'Q17',
P276: location,
P580: start,
P582: end,
}
}
return newItem
}
const championships = {
2021: 'Q106735845',
2020: 'Q106707657',
2019: 'Q106725472',
2018: 'Q106726771',
2017: 'Q106726795',
2016: 'Q106726816',
2015: 'Q106726831',
}
const types = {
'Autopolis': 'Q106705839',
'Autopolis 2&4' : 'Q106763105',
'MFJ GP' : 'Q106712980',
'Motegi': 'Q106712966',
'Motegi 2&4' : 'Q106763118',
'Okayama': 'Q106712954',
'Sugo' : 'Q106697764',
'Suzuka' : 'Q106737001',
'Suzuka 2&4' : 'Q106737001',
'Tsukuba' : 'Q106725499',
}
const locations = {
'Autopolis' : 'Q1748785',
'Motegi': 'Q1420895',
'Okayama': 'Q173185',
'Sugo' : 'Q917398',
'Suzuka' : 'Q174170',
'Tsukuba' : 'Q2097263',
}
const isNormalSnaktypeValue = value => typeof value === 'string' |
Hi,
I'd like to get started with wikibase-cli mainly to replace/supplement QuickStatements for my WD batch editing.
As an example I tried the following with QS ( I prepared it in a spreadsheet ) to create and populate an item in one "operation" :
unfortunately it doesn't work and as a workaround I used :
Then after manually copy/pasting the newly created item's Q number :
Woud you have some pointers on how to move in that direction, to familiarize myself so somewhere down the road I'd like to able to write/modify a little script in which I'd have the values for P31, P361, P276 as arguments ( with an/several "if function"
example : with arg1 being the year and arg2 being Okayama ( with a list of abt 10 different values for arg2 )
etc....
and
so I can process several seasons and rounds faster, although I can't see a way to change the value for P580 and P582 other than manually...
Thanks in advance for any guidance you'd be willing to provide.
The text was updated successfully, but these errors were encountered: