support for P18 (image)
edsu opened this issue · 3 comments
edsu commented
It would be useful to be able to get P18, but this is what happens whey you try to fetch it:
[1] pry(main)> require 'wikidata'
=> true
[2] pry(main)> i = Wikidata::Item.find 'Q6882'
=> <Wikidata::Item id: Q6882, title: "James Joyce">
[3] pry(main)> i.property 'P18'
Unkown property type commonsMedia
Unkown property type commonsMedia
=> nil
klacointe commented
I've just push an experimental support for commonsMedia (only images for now).
Can you let me know if this is what you expected?
irb(main):001:0> require 'wikidata'
=> true
irb(main):002:0> i = Wikidata::Item.find 'Q6882'
=> <Wikidata::Item id: Q6882, title: "James Joyce">
irb(main):003:0> i.property('P18')
=> #<Wikidata::Property::CommonsMedia:0x007fa522a8fc90 @property=#<Hashie::Mash id="Q6882$8CB12994-045E-4EB3-98F8-3975EA1BF9A7" mainsnak=#<Hashie::Mash datatype="commonsMedia" datavalue=#<Hashie::Mash type="string" value="Revolutionary Joyce Better Contrast.jpg"> property="P18" snaktype="value"> rank="normal" references=[#<Hashie::Mash hash="d6e3ab4045fb3f3feea77895bc6b27e663fc878a" snaks=#<Hashie::Mash P143=[#<Hashie::Mash datatype="wikibase-item" datavalue=#<Hashie::Mash type="wikibase-entityid" value=#<Hashie::Mash entity-type="item" numeric-id=206855>> property="P143" snaktype="value">]> snaks-order=["P143"]>] type="statement">>
irb(main):004:0> i.property('P18').url
=> "https://upload.wikimedia.org/wikipedia/commons/1/1e/Revolutionary_Joyce_Better_Contrast.jpg"
irb(main):005:0> i.property('P18').url 200
=> "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Revolutionary_Joyce_Better_Contrast.jpg/200px-Revolutionary_Joyce_Better_Contrast.jpg"
Il you have examples of wikidata pages with other commonsMedia statements like video, audio etc i'll will add support for them.
edsu commented
Yes, this is super. I started adding support on my own branch, but yours is much better! Thank you so much for the quick turn around.
klacointe commented
version 0.0.7 published with this feature