1 of 27

When the whole world is your database

Victor Shepelev aka @zverok

RubyConf India 2018

2 of 27

Namaskāra!

I am Victor Shepelev

  • a.k.a @zverok
  • from Kharkiv, Ukraine
  • working at VerbIT.ai
  • open source author and Ruby mentor
  • SciRuby maintainer
  • (also poet)

3 of 27

Understanding the world

With Ruby!

1

4 of 27

Let’s start with some questions

  • Where in the world is Bengaluru?
  • When was the “3 Idiots” movie first released?
  • Show me the picture of Bengal Tiger

No, seriously. How you do this in Ruby?

?

5 of 27

You do something like this

  • Find some appropriate API
  • Find the Ruby gem for this API
  • Use this gem in your app

Is it so?..

6 of 27

What those questions may imply

  • Where in the world is Bengaluru?
    • What time is there?
    • What currency is there, what’s it rate to USD?
    • How far is it from %myplace%?
    • What’s the weather there?

!

7 of 27

So you end up like this

  • Multiple APIs with different semantics
  • Multiple gems with they own semantics
    • (Or no gem at all)
  • Miriad of incompatible data types
    • Their own classes, OpenStructs, raw hashes...

Should it be this way?

8 of 27

What we really want: an easy and idiomatic access to entire world’s common-sense knowledge

!

9 of 27

Why?..

  • Assisted intelligence
  • Making sense of complicated data
  • Input data for experiments, demos and play
  • Because we (should) can!

10 of 27

Face the Reality

gem install reality --pre

2

11 of 27

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

# ...

12 of 27

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>

13 of 27

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

14 of 27

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)>

# ...

15 of 27

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)>

16 of 27

How reality is built*

* because gem names are mostly for puns, right?..

3

17 of 27

A bit of history

  • Heavily inspired by Wolfram Language
  • Spring 2015: first experiments
  • November 2015: Ruby Association Grant
  • March 2016: first public release
  • 2016-2017: lot of redesigning...
  • Feb 2018: prerelease of new version
  • Spring 2018: new version

18 of 27

What is it now

  • A set of describers (external services)
  • ...returning entities (Hash on steroids)
  • plus rich value types

...all playing together!

19 of 27

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>

20 of 27

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"

21 of 27

22 of 27

Rich value types

  • Link (id of entity that could be loaded)
  • Geo coordinates, numbers with units, timezones, currencies...
  • Based of reliable existing gems when possible

23 of 27

Beyond the Reality

The part where you can join!

4

slightly

v

known

v

24 of 27

More describers!

  • Big open data sources: TheMovieDB, MusicBrainz, Worldbank
  • Scientific data from NASA and many others
  • Local governmental & non-profit open data
  • Social networks: Twitter, Facebook, whatever
  • Your ideas?

25 of 27

Spread the impact!

  • Usage examples and case studies
  • Extract independently useful parts
  • ...

Reality is just a playground!

26 of 27

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)>

27 of 27

That is it!

Stay in touch

  • github.com/molybdenum-99/reality
  • zverok.github.io

(with reality)