reality 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/reality/definitions/wikipedia_person.rb +1 -1
- data/lib/reality/entity.rb +7 -6
- data/lib/reality/version.rb +1 -1
- data/lib/reality/wikidata.rb +2 -2
- data/lib/reality/wikidata/query.rb +5 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 725f78139506531415afc4cdd24927ae8845eecf
|
4
|
+
data.tar.gz: 1260575c3e637ec2e1c032dd894b4985dad78450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a25e4eb32e02b862a5667e08493fe7a5128bfa97a0b69436f37040a27ff5752ed47417ec3588e7659ebf189ebb1a658016bd9f8e5815ad8f40ebb95a365752fe
|
7
|
+
data.tar.gz: c52eebc26b43a1cc2c4e885920138fcd9841a3bedb747f1ec9e04a45bf895d0cc5869d8e3d4eb620399cc3e8618299c0219b97b6f4101ff7c1d8cc414f9582eb
|
data/README.md
CHANGED
@@ -231,7 +231,7 @@ to Wikipedia API. _TODO: explain the problem and point to recipes._
|
|
231
231
|
## Credits
|
232
232
|
|
233
233
|
* [Victor Shepelev](https://zverok.github.io) [@zverok](https://github.com/zverok);
|
234
|
-
*
|
234
|
+
* Sergii Mostovyi [@smostovoy](https://github.com/smostovoy);
|
235
235
|
* [Valentino Stoll](http://www.awesomevibe.com/) [@codenamev](https://github.com/codenamev);
|
236
236
|
* [Several great contributors](https://github.com/molybdenum-99/reality/graphs/contributors).
|
237
237
|
|
@@ -3,7 +3,7 @@ module Reality
|
|
3
3
|
module Person
|
4
4
|
extend Entity::WikipediaType
|
5
5
|
|
6
|
-
infobox_name 'Infobox person'
|
6
|
+
infobox_name 'Infobox person', 'Infobox person ii'
|
7
7
|
|
8
8
|
# Singular artists, like Bjork or David Bowie
|
9
9
|
# TODO: should not repeat code from musical artist, but include it from module?
|
data/lib/reality/entity.rb
CHANGED
@@ -21,7 +21,7 @@ module Reality
|
|
21
21
|
# call any of them by name, like `argentina.capital`.
|
22
22
|
#
|
23
23
|
# Or you can create not loaded entities with just {#initialize} (it
|
24
|
-
# may be useful when you want to further batch-load several of them
|
24
|
+
# may be useful when you want to further batch-load several of them
|
25
25
|
# through {List#load!}).
|
26
26
|
#
|
27
27
|
class Entity
|
@@ -48,6 +48,7 @@ module Reality
|
|
48
48
|
#
|
49
49
|
# @return [Hash<Symbol, Object>]
|
50
50
|
attr_reader :values
|
51
|
+
alias_method :attributes, :values
|
51
52
|
|
52
53
|
# @private
|
53
54
|
attr_reader :wikipedia_type, :wikidata, :wikidata_id
|
@@ -173,7 +174,7 @@ module Reality
|
|
173
174
|
if @wikidata_id
|
174
175
|
@wikidata = Wikidata::Entity.one_by_id(@wikidata_id)
|
175
176
|
if @wikidata && @wikidata.en_wikipage
|
176
|
-
@wikipage = Infoboxer.wikipedia.get(@wikidata.en_wikipage)
|
177
|
+
@wikipage = Infoboxer.wikipedia.get(@wikidata.en_wikipage.tr('_', ' '))
|
177
178
|
end
|
178
179
|
else
|
179
180
|
@wikipage = Infoboxer.wikipedia.get(name)
|
@@ -209,7 +210,7 @@ module Reality
|
|
209
210
|
#
|
210
211
|
# * loads itself if it was not loaded;
|
211
212
|
# * returns one of {values} by method name.
|
212
|
-
#
|
213
|
+
#
|
213
214
|
# Note, that even if there's no value with required key, `method_missing`
|
214
215
|
# will return `nil` (and not through `NoMethodError` as someone may
|
215
216
|
# expect). That's because even supposedly homogenous entities may have different
|
@@ -220,7 +221,7 @@ module Reality
|
|
220
221
|
def method_missing(sym, *arg, **opts, &block)
|
221
222
|
if arg.empty? && opts.empty? && !block && sym !~ /[=?!]/ &&
|
222
223
|
!UNSUPPORTED_METHODS.include?(sym)
|
223
|
-
|
224
|
+
|
224
225
|
load! unless loaded?
|
225
226
|
|
226
227
|
# now some new method COULD emerge while loading
|
@@ -276,7 +277,7 @@ module Reality
|
|
276
277
|
# # :gdp_ppp=>{:amount=>964279000000.0, :unit=>"$"},
|
277
278
|
# # :population=>{:amount=>43417000.0, :unit=>"person"},
|
278
279
|
# # :head_of_government=>
|
279
|
-
# # {:name=>"Mauricio Macri",
|
280
|
+
# # {:name=>"Mauricio Macri",
|
280
281
|
# # :birthday=>"1959-02-08",
|
281
282
|
# # ....},
|
282
283
|
# # :country=>"Argentina",
|
@@ -298,7 +299,7 @@ module Reality
|
|
298
299
|
# # :coord=>{:lat=>-34.0, :lng=>-64.0},
|
299
300
|
# # :official_website=>"http://www.argentina.gob.ar/",
|
300
301
|
# # :gdp_nominal=>{:amount=>537659972702.0, :unit=>"$"}}
|
301
|
-
# #
|
302
|
+
# #
|
302
303
|
# ```
|
303
304
|
#
|
304
305
|
# @return [Hash]
|
data/lib/reality/version.rb
CHANGED
data/lib/reality/wikidata.rb
CHANGED
@@ -97,7 +97,7 @@ module Reality
|
|
97
97
|
when 'http://www.opengis.net/ont/geosparql#wktLiteral'
|
98
98
|
# TODO: WTF
|
99
99
|
if hash['value'] =~ /^\s*point\s*\(\s*([-\d.]+)\s+([-\d.]+)\s*\)\s*$/i
|
100
|
-
|
100
|
+
lng, lat = $1, $2
|
101
101
|
Geo::Coord.new(lat.to_f, lng.to_f)
|
102
102
|
else
|
103
103
|
fail ArgumentError, "Unparseable WKT: #{hash['value']}"
|
@@ -136,7 +136,7 @@ module Reality
|
|
136
136
|
|
137
137
|
def en_wikipage
|
138
138
|
return nil unless about
|
139
|
-
|
139
|
+
|
140
140
|
name = about.first.
|
141
141
|
scan(%r{https://en\.wikipedia\.org/wiki/(.+)$}).
|
142
142
|
flatten.first.derp{|s| URI.unescape(s)}
|
@@ -3,7 +3,7 @@ module Reality
|
|
3
3
|
module Query
|
4
4
|
PREFIX = %Q{
|
5
5
|
PREFIX wikibase: <http://wikiba.se/ontology#>
|
6
|
-
PREFIX wd: <http://www.wikidata.org/entity/>
|
6
|
+
PREFIX wd: <http://www.wikidata.org/entity/>
|
7
7
|
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
8
8
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
9
9
|
PREFIX p: <http://www.wikidata.org/prop/>
|
@@ -36,7 +36,7 @@ module Reality
|
|
36
36
|
|
37
37
|
QUERY = %Q{
|
38
38
|
#{PREFIX}
|
39
|
-
|
39
|
+
|
40
40
|
SELECT ?s ?p ?o ?oLabel WHERE {
|
41
41
|
%{selectors} .
|
42
42
|
#{PREDICATES} .
|
@@ -58,7 +58,8 @@ module Reality
|
|
58
58
|
|
59
59
|
def by_wikititle(*titles)
|
60
60
|
fetch(:en_wikipage, titles.
|
61
|
-
map{|t| SELECTORS[:wikipedia] % {title:
|
61
|
+
map{|t| SELECTORS[:wikipedia] % {title: t.tr(' ', '_')}}
|
62
|
+
#map{|t| SELECTORS[:wikipedia] % {title: URI.escape(t, UNSAFE)}}
|
62
63
|
)
|
63
64
|
end
|
64
65
|
|
@@ -82,7 +83,7 @@ module Reality
|
|
82
83
|
}.flatten(1).
|
83
84
|
group_by(&key).
|
84
85
|
# of several entities with same label, we always prefer first-by-id
|
85
|
-
map{|key, group| group.sort_by(&:id_i).first}.
|
86
|
+
map{|key, group| group.sort_by(&:id_i).first}.
|
86
87
|
map{|entity| [entity.send(key), entity]}.to_h
|
87
88
|
end
|
88
89
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reality
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Shepelev and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: infoboxer
|
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
version: '0'
|
226
226
|
requirements: []
|
227
227
|
rubyforge_project:
|
228
|
-
rubygems_version: 2.
|
228
|
+
rubygems_version: 2.6.10
|
229
229
|
signing_key:
|
230
230
|
specification_version: 4
|
231
231
|
summary: Simple and easy proxy to real-life knowledge.
|