When the whole world is your database
Victor Shepelev aka @zverok
RubyConf India 2018
Namaskāra!
I am Victor Shepelev
Understanding the world
With Ruby!
1
Let’s start with some questions
No, seriously. How you do this in Ruby?
?
You do something like this
Is it so?..
What those questions may imply
!
So you end up like this
Should it be this way?
What we really want: an easy and idiomatic access to entire world’s common-sense knowledge
!
Why?..
Face the Reality
gem install reality --pre
2
require 'reality'
require 'reality/miracles'
bengaluru = Reality.wikipedia.get('Bengaluru')
# => #<Reality::Entity wikipedia:en://Bangalore>
bengaluru.describe
# ...
# official_name: Bengaluru
# coordinates: 12°58'0"N 77°34'0"E
# subdivision_type: Country
# subdivision_name: <wikipedia:en://India>
# area_total_km2: 709km²
# elevation_m: 920m
# population_total: 12,339,447people
# ...
bengaluru.coordinates.timezone.now
# => 2018-02-08 15:50:01
bengaluru.subdivision_name
# => #<Reality::Link wikipedia:en://India>
india = bengaluru.subdivision_name
india.currency_code
# => #<Reality::Currency Indian Rupee (₹, INR)>
india.currency_code.rate_to('USD')
# => 0.015555
kharkiv = Reality.wikipedia.get('Kharkiv')
bengaluru.coordinates.distance(kharkiv)
# => #<Reality::Measure 5,561 km>
Reality.open_weather_map.query(at: bengaluru).first.describe
# #<Reality::Entity openweathermap://6695236>
# temp: 27.53°C
# pressure: 1,013hPa
# humidity: 44%
# temp_min: 27°C
# temp_max: 28°C
# wind_speed: 2.1m/s
# sunrise: 2018-02-08 06:44:26 +0530
# sunset: 2018-02-08 18:23:32 +0530
idiots = Reality.wikipedia.get('3 Idiots')
idiots['meta.wikidata']
# => #<Reality::Link wikidata://Q229633>
idiots_wd = idiots['meta.wikidata'].load
idiots_wd.describe
# director: <wikidata://Q3418007 (Rajkumar Hirani)>
# cast member: <wikidata://Q9557 (Aamir Khan)>, ...
# instance of: <wikidata://Q11424 (film)>
# genre: <wikidata://Q859369 (comedy-drama)>
# ...
aamir = idiots_wd.cast_member.first
# => #<Reality::Link wikidata://Q9557 (Aamir Khan)>
Reality.wikidata.query(cast_member: aamir).all
#<Reality::Link wikidata://Q58619 (Akele Hum Akele Tum)>,
#<Reality::Link wikidata://Q229633 (3 Idiots)>,
#<Reality::Link wikidata://Q283481 (Andaz Apna Apna)>,
#<Reality::Link wikidata://Q283555 (Talaash)>,
#<Reality::Link wikidata://Q369413 (Mann)>,
# ...
Reality.open_street_map
.query(around: aamir.place_of_birth,
aerodrome: 'international', radius: 30_000).first
# => #<Reality::Link osm://way(22826676) (Chhatrapati Shivaji International Airport)>
How reality is built*
* because gem names are mostly for puns, right?..
3
A bit of history
What is it now
...all playing together!
Describer: schemaless DB
Reality.commons.query(category: 'Panthera tigris tigris')
.first
# => #<Reality::Link commons://File:A Royal Bengal Tiger.jpg>
tiger = Reality.commons.get('File:A Royal Bengal Tiger.jpg')
# => #<Reality::Entity commons://File:A Royal Bengal Tiger.jpg>
Entity: schemaless object
tiger.uri
# => "commons://File:A Royal Bengal Tiger.jpg"
tiger.observations.map(&:variable)
# => ["meta.title", "meta.url", "meta.image", "meta.thumb"]
tiger['meta.image']
# => "https://upload.wikimedia.org/..._Bengal_Tiger.jpg"
Rich value types
Beyond the Reality
The part where you can join!
4
slightly
v
known
v
More describers!
Spread the impact!
Reality is just a playground!
here = Reality.openstreetmap.query(name: 'Chancery Pavilion').first
Reality.openstreetmap
.query(around: here, radius: 1000, amenity: 'pub').all
#<Reality::Link osm://node(1835304318) (The Biere Club)>,
#<Reality::Link osm://node(2322740069) (Jimmy's)>,
#<Reality::Link osm://node(2694443988) (Plan B)>,
#<Reality::Link osm://node(2907543445) (Bootleggers)>,
#<Reality::Link osm://node(3458335906) (Bangalore Brew Works)>,
#<Reality::Link osm://node(4498096390) (Mojo Café pub & Bistro)>, #<Reality::Link osm://node(5168571696) (3 Page Bar and Restaurant)>
That is it!
Stay in touch
(with reality)