-
Notifications
You must be signed in to change notification settings - Fork 43
Entity
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
Currently, the data you can see when describe
ing some entity, are
gathered from two sources:
- Wikidata property lists;
- English Wikipedia parsed pages.
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.
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:
- entity Lists;
- Entity internals in Advanced section.
- Intro
- Applications
- Links and mentions
- Tutorial:
- Tips & tricks
- Advanced topics
- Molybdenum?..