Skip to content
zverok edited this page Apr 12, 2016 · 4 revisions

Loaded and not loaded entities. Implicit loading

When you create a Reality::Entity like this:

argentina = Entity('Argentina')

it is already loaded (all relevant Wikipedia/Wikidata information is fetched and parsed). But related entities are not:

argentina = Entity('Argentina')
# => #<Reality::Entity(Argentina):country>
argentina.loaded?
# => true
argentina.capital
# => #<Reality::Entity?(Buenos Aires)>
# ^ note the question mark in entity inspect

argentina.capital.loaded?
# => false

That means, the entity needs to be loaded before you can use some of its properties:

argentina.capital.load!
# ...will take some seconds, depending on size of data and your connection
argentina.capital.loaded?
# => true
argentina.capital.area
# => #<Reality::Measure(203 km²)>

Also, all entities are loaded implicitly on method_missing, so you can just do:

argentina = Entity('Argentina')
argentina.capital.loaded?
# => false
argentina.capital.area # this will take some time
# => #<Reality::Measure(203 km²)>
argentina.capital.loaded?
# => true
argentina.capital.population # now, this will be instant
# => #<Reality::Measure(2,890,151 person)>

You can also create entities in "not loaded" state, it is helpful sometimes:

argentina = Entity.new('Argentina')
# => #<Reality::Entity?(Argentina)>
argentina.loaded?
# => false

What data is available for entity and where it comes from

Currently, the data you can see when describeing some entity, are gathered from two sources:

Reality tries its best to parse as much of data as possible (you can read some details at How it works page), but you may note there's currently waaaay less data than can be seen "by eyes". We are working on enchancing our parsers and new sources of data!

NB: except for things you can see in describe, there's some more data, fetched by demand:

  • data from external services;
  • dynamical data, for example world countries have #cities method, which fetched additional page "Cities in %countryname%" and provides this list in entities.

The latter functionality is a bit rough (as you have a small chance to guess if it is there), but it will better soon.

Entity names

Currently, reality loads entities just by Wikipedia page name (and respects redirects the same way Wikipedia does). So, for example:

# cool:
Reality::Entity('Einstein')
# => #<Reality::Entity(Albert Einstein)>

# but...
Reality::Entity('Ruby') # => about mineral
Reality::Entity('Ruby (programming language)') # => about programming language

Further Reality versions would at least work smarter with disambiguation pages and "other uses" link. But currently, that's just what you have.

Next: