maxlath / wikibase-cli

read and edit a Wikibase instance from the command line
MIT License
226 stars 24 forks source link

wd claims should also emit claim guids #39

Closed nichtich closed 5 years ago

nichtich commented 6 years ago

I'd like to get a claim guid for editing wd claim $subject $property prints the simplified object value. I'd expect some option, e.g. wd claims --guid $subject $property.

maxlath commented 6 years ago

yes! I was thinking of something of this kind, but not knowing where to put it. I made an attempt to do that, which outputs something like this:

wd claims Q4115189 P31 --guid

returns

[
  {
    "guid": "Q4115189$DF92E189-4E3B-4397-AD41-B23998557E55",
    "value": "Q2065736"
  },
  {
    "guid": "Q4115189$02E70CCE-15FE-4FC5-A4C9-A38BF6D7E49B",
    "value": "Q571"
  }
]

What do you think?

nichtich commented 6 years ago

In my opinion this should be the default because we can also get claim values by this:

$ wd d -s Q4115189 | jq .claims.P31
[
  "Q2065736",
  "Q571"
]

So I'd want

$ wd claims -j Q4115189 P31
[
  {
    "id": "Q4115189$DF92E189-4E3B-4397-AD41-B23998557E55",
    "value": "Q2065736"
  },
  {
    "id": "Q4115189$02E70CCE-15FE-4FC5-A4C9-A38BF6D7E49B",
    "value": "Q571"
  }
]
$ wd claims Q4115189 P31
Q4115189$DF92E189-4E3B-4397-AD41-B23998557E55 Q2065736
Q4115189$02E70CCE-15FE-4FC5-A4C9-A38BF6D7E49B Q571

By it could also be triggered by an option --ids. Anyway the field should be named id instead of guid because this is the field name in original JSON data.

maxlath commented 6 years ago

so since the freshly published v5.1.0 (thank to wikidata-sdk v5.3.0) , you can pass options to the simplify function to produce the behavior you describe above:

wd data --simplify --keep ids Q4115189 | jq .claims.P31

or for short

wd d -sk ids Q4115189 | jq .claims.P31
maxlath commented 5 years ago

closing this issue as there isn't much activity, please re-open if the proposed solution isn't satisfying