Ruby gem to help with bulk lookups of Wikidata items (currently for internal EveryPolitician use)
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin Update files with what bundler 1.10 generates Nov 5, 2015
lib
test Move pry require into test_helper.rb Sep 30, 2016
.gitignore
.rubocop.yml
.rubocop_todo.yml regenerate Rubocop TODO list Sep 22, 2016
.travis.yml
CHANGES
Gemfile 0.0.1 Oct 17, 2015
LICENSE.txt 0.0.1 Oct 17, 2015
README.md
Rakefile Add Rubocop rake task Sep 22, 2016
wikisnakker.gemspec

README.md

Wikisnakker Build Status

This project allows you to do bulk lookups of Wikidata items. If you want to look up large amounts of Wikidata items at once then this library should make that job considerably faster.

⚠️ This project is under heavy development and is in a very pre-alpha state, it's not yet ready for use in production.

Features/problems

  • Many

Installation

Add this line to your application's Gemfile:

gem 'wikisnakker', git: 'https://github.com/everypolitician/wikisnakker'

And then execute:

$ bundle

Usage

You can pass an array of qualifiers to Wikisnakker::Item.find. This will return an array of Wikisnakker::Item instances.

require 'wikisnakker'
items = Wikisnakker::Item.find(['Q2', 'Q513', 'Q41225'])
items.map { |item| item.label('en') } # => ["Earth", "Mount Everest", "Big Ben"]
items.map { |item| item.P18.value } # => ["https://upload.wikimedia.org/wikipedia/commons/9/97/The_Earth_seen_from_Apollo_17.jpg", "https://upload.wikimedia.org/wikipedia/commons/e/e7/Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006.jpg", "https://upload.wikimedia.org/wikipedia/commons/7/78/Big-ben-1858.jpg"]

If you pass a string to Wikisnakker::Item.find then it will return a single Wikisnakker::Item instance:

require 'wikisnakker'
douglas_adams = Wikisnakker::Item.find('Q42')
douglas_adams.label('en') # => "Douglas Adams"

Then you can lookup properties on returned items. For example P19 is "place of birth". A P19 is an item, so you can then call .label() on its return value and call further P* methods on it.

cambridge = douglas_adams.P19.value
cambridge.label('en') # => "Cambridge"

P569 is "date of birth" and P570 is "date of death".

douglas_adams.P569.value # => "1952-03-11"
douglas_adams.P570.value # => "2001-05-11"

Sometimes a property will have multiple values, for example P735, which is "given names". In this case you can call P735s on the Wikisnakker::Item instance to get an array back:

douglas_adams.P735s.map { |given_name| given_name.value.label('en') }
# => ["Douglas", "Noel"]

You can also lookup aliases in a certain language for an item:

douglas_adams.aliases('en')
# => ["Douglas Noël Adams", "Douglas Noel Adams"]

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/everypolitician/wikisnakker.