Giter Club home page Giter Club logo

wikidata's Introduction

Wikidata for Ruby Gem Version

Access all of the wonderful structured data on Wikidata, with Ruby! Also includes a convenient CLI.

Very much a work in progress, so only a few basic things are working.

Installation

Add this line to your application's Gemfile:

gem 'wikidata'

And then execute:

$ bundle

Or install it yourself as:

$ gem install wikidata

Usage

Command Line

See all the claims for a particular topic.

$ wikidata find "Kyle Chandler"

This will fetch all the data (called "claims") Wikidata has on superstar actor Kyle Chandler and print it out in the terminal, like so:

Kyle Chandler
Wikidata ID: Q359604
Claims: 14
+-------------+---------------------------------------------------------------------+
| property_id | value                                                               |
+-------------+---------------------------------------------------------------------+
| P21         | Q6581097                                                            |
+-------------+---------------------------------------------------------------------+
| P27         | Q30                                                                 |
+-------------+---------------------------------------------------------------------+
| P106        | Q33999                                                              |
+-------------+---------------------------------------------------------------------+
| P373        | Kyle Chandler                                                       |
+-------------+---------------------------------------------------------------------+
(...)

You'll notice that doesn't seem very useful for humans, because Wikidata property keys and many of its values are not human readable. To have the gem resolve all of these opaque identifiers (which adds extra network calls), pass -r.

$ wikidata find "Kyle Chandler" -r

That will provide more useful results:

(...)
+------------------------+------+---------------------------------------------------------------------+
| sex (or gender)        | P21  | male (Q6581097)                                                     |
+------------------------+------+---------------------------------------------------------------------+
| country of citizenship | P27  | United States of America (Q30)                                      |
+------------------------+------+---------------------------------------------------------------------+
| occupation             | P106 | actor / actress (Q33999)                                            |
+------------------------+------+---------------------------------------------------------------------+
| IMDb identifier        | P345 | nm0151419                                                           |
+------------------------+------+---------------------------------------------------------------------+
| place of birth         | P19  | Buffalo (Q40435)                                                    |
+------------------------+------+---------------------------------------------------------------------+
| date of birth          | P569 | 1965-09-17T00:00:00+00:00                                           |
+------------------------+------+---------------------------------------------------------------------+
(...)

Much better!

In Ruby

You can use a convenient ActiveRecord-inspired syntax for finding information:

los_angeles = Wikidata::Item.find_by_title "Los Angeles"
los_angeles.id # => "Q65"

# Let's find the mayor.
mayor = los_angeles.claims_for_property_id("P6").first.mainsnak.value.entity
mayor.label # => "Eric Garcetti"

That's the basics!

Contributing

  1. Fork it ( http://github.com//wikidata/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

wikidata's People

Contributors

wilg avatar hellno avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.