User:So9q/Tool ideas/ImproveWikidata
Improve Wikidata (code, workboard with user stories) is a Python REPL TUI made by So9q that reads from a rule-directory with json-files and semi-automatically edits Wikidata. It's design is based on KISS and YAGNI principles.
In essence it is a TUI frontend to WikibaseIntegrator, that enables users to share json rules using git or other measures and collaborate on editing Wikidata in a semi-automatic way in the terminal with as little hassle as possible.
It could be used to semi-automate an import into Wikidata where many user collaborate simultaneously.
Rules
[edit]v1
[edit]The format of time is the one Wikidata uses ie. "+2021-01-18T07:38:02Z".
Top level is a dictionary of keys. Valid keys are:
- target
- add
- remove
target
[edit]Is a dictionary that has two valid keys:
- sparql :: a query in it's entirety
- predobj :: a list of predicates and objects used to construct a sparql query, see [1]
- narrow :: (optional) list of predobj that narrows down the query
This dictionary has to contain either a sparql query or a predobj list with at least one member to be valid. If a sparql key is found the predobj and narrow in the same dictionary are ignored.
predobj
[edit]List containing:
- p :: sparql predicate string without prefix, e.g. "P1"
- plabel :: dictionary of predicate labels for increased readability of rules
- o :: sparql object string without prefix, e.g. "Q1"
- olabel :: dictionary of object labels for increased readability of rules
- oformat :: can be one of "time", "coordinate", "url", "quantity", "string". For urls, strings and quantities it can be omitted as they are autodetected.
Note: the oformat is subject to get additional values. Move values could include those used by wikibaseintegrator.
add
[edit]List of predobj dictionaries with added support for qualifiers and references:
- p :: sparql predicate string without prefix, e.g. "P1"
- plabel :: dictionary of predicate labels for increased readability of rules
- o :: sparql object string without prefix, e.g. "Q1"
- olabel :: dictionary of object labels for increased readability of rules
- oformat :: can be one of "time", "coordinate". For strings and quantities it can be omitted.
- qualifiers :: list of predobj specifying qualifiers
- references :: list of predobj specifying references, each reference can have qualifiers.
remove
[edit]Same as add, but the object is removed instead of added. If a qualifier or reference is specified only the specified qualifier or reference on the object will be removed, not the object itself.
Examples
[edit]Adding a statement without a reference
[edit]Example adding trade union operative area: Sweden for Swedish trade unions that are missing it.
{
"target": {
"sparql": "",
"predobj": [
{
"p": "P31",
"plabel": {
"en": "instance of"
},
"o": "Q178790",
"olabel": {
"en": "trade union"
}
}
],
"narrow": [
{
"p": "P17",
"plabel": {
"en": "country"
},
"o": "Q34",
"olabel": {
"en": "Sweden"
}
}
]
},
"add": [
{
"p": "P2541",
"plabel": {
"en": "operation area"
},
"o": "Q34",
"olabel": {
"en": "Sweden"
}
}
]
}
Adding a statement with a reference
[edit]Example adding trade union operative area: Sweden for Swedish trade unions that are missing it.
{
"target": {
"sparql": "",
"predobj": [
{
"p": "P31",
"plabel": {
"en": "instance of"
},
"o": "Q178790",
"olabel": {
"en": "trade union"
}
}
],
"narrow": [
{
"p": "P17",
"plabel": {
"en": "country"
},
"o": "Q34",
"olabel": {
"en": "Sweden"
}
}
]
},
"add": [
{
"p": "P2541",
"plabel": {
"en": "operation area"
},
"o": "Q34",
"olabel": {
"en": "Sweden"
},
"references": [
{
"p": "P",
"plabel": {
"en": "reference url"
},
"o": "https://fackforbunden.se/info/fackorganistation",
"olabel": {},
"qualifiers": [
{
"p": "P813",
"plabel": {
"en": "retrieved"
},
"o": "+2021-01-18T07:38:02Z",
"olabel": {},
"oformat": "time"
}
]
}
]
}
]
}