freebase-api 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b7e8a2c6fe8238795c80a201f277020c42ea8ea
4
- data.tar.gz: e627b3686db5e0db9f374b9130f720e3ae5e2aed
3
+ metadata.gz: 097e43bda28de6d2a47a68371b45b8982aaa0aa6
4
+ data.tar.gz: 50efef5ff00a462c924538242c5b47507bb0238f
5
5
  SHA512:
6
- metadata.gz: a8074d7dc7be46e31da0c6bff00e6f021dbf1fd477a2d2a00130277e30f96cec052b70aa07056a7625eb71f2817ce10f5bb5b1b703b4c24aa4f83f14de2f84dc
7
- data.tar.gz: d989451faf085ac0cf720e1d5c666115b785912ab05641a6fb237d4337efabdc647b95f60dcf2a48db69c331ce1a236eeea9cec6dadd003fe45fbcb05c4eca5c
6
+ metadata.gz: d54082df7c8343c22cc3ffc840ea6d24cde478c8c03711b3dc619d7c94ccd945592cb91104e6f87a54bf2eed7d6b66cf57c48bff8ce01a9a4ddb7ab74de1f8cc
7
+ data.tar.gz: 5f3e0f3ca84ab1a35ac6d0d5fae3bee10badc63c4010636a9f62469e80d1ad17047f9d65fcc95b1717dd5ec671304fb8f113b939c9eb0efcdcbe2fb5131bb76e
@@ -40,30 +40,67 @@ module FreebaseAPI
40
40
  "id" => topic['mid'],
41
41
  "lang" => lang,
42
42
  "property" => {
43
- "/type/object/name" => {
44
- "valuetype" => "string",
45
- "values" => [
46
- {
47
- "text" => "#{topic['name']}",
48
- "lang" => lang,
49
- "value" => "#{topic['name']}"
50
- }
51
- ]
52
- }
43
+ "/type/object/name" => build_simple_property_data("string", [{"text" => topic['name'], "lang" => lang}])
53
44
  }
54
45
  }
55
- data["property"]["/common/topic/notable_for"] = {
56
- "valuetype" => "object",
57
- "values" => [
58
- {
59
- "text" => topic['notable']['name'],
60
- "lang" => lang,
61
- "id" => topic['notable']['id']
62
- }
63
- ],
64
- } if topic.has_key?('notable')
46
+ if topic.has_key?('notable')
47
+ data["property"]["/common/topic/notable_for"] = build_simple_property_data("object",
48
+ [{
49
+ "text" => topic['notable']['name'],
50
+ "lang" => lang,
51
+ "id" => topic['notable']['id']
52
+ }])
53
+ end
54
+ merge_custom_output(topic['output'], data["property"], lang) if topic.has_key?('output')
65
55
  data
66
56
  end
57
+
58
+ # @private
59
+ def build_simple_property_data(type, values)
60
+ values_f = values.map do |v|
61
+ hash = { "lang" => v["lang"], "text" => v["text"].to_s }
62
+ if v.has_key?("id")
63
+ hash["id"] = v["id"]
64
+ else
65
+ hash["value"] = v["text"]
66
+ end
67
+ hash
68
+ end
69
+ {
70
+ "valuetype" => type,
71
+ "values" => values_f
72
+ }
73
+ end
74
+
75
+ # @private
76
+ def merge_custom_output(output, properties, lang)
77
+ values = nil
78
+ valuetype = nil
79
+ output.each do |_, hash|
80
+ hash.each do |property, values|
81
+ if values.first.is_a?(Hash)
82
+ values = values.map do |value|
83
+ {
84
+ "text" => value['name'],
85
+ "lang" => lang,
86
+ "id" => value['mid']
87
+ }
88
+ end
89
+ valuetype = "object"
90
+ else
91
+ values = values.map do |value|
92
+ {
93
+ "text" => "#{value}",
94
+ "lang" => lang,
95
+ "value" => "#{value}"
96
+ }
97
+ end
98
+ valuetype = "string"
99
+ end
100
+ properties[property] = build_simple_property_data(valuetype, values)
101
+ end
102
+ end
103
+ end
67
104
  end
68
105
 
69
106
  def initialize(id, options={})
@@ -1,3 +1,3 @@
1
1
  module FreebaseAPI
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -60,155 +60,5 @@
60
60
  },
61
61
  "lang": "en",
62
62
  "score": 27.369299
63
- },
64
- {
65
- "mid": "/m/02p7m2",
66
- "id": "/en/dylan_moran",
67
- "name": "Dylan Moran",
68
- "notable": {
69
- "name": "Stand-up comedian",
70
- "id": "/m/04tkfj6"
71
- },
72
- "lang": "en",
73
- "score": 27.203932
74
- },
75
- {
76
- "mid": "/m/0d0w6b",
77
- "id": "/en/dylan_postl",
78
- "name": "Hornswoggle",
79
- "notable": {
80
- "name": "Wrestler",
81
- "id": "/m/02nx2gc"
82
- },
83
- "lang": "en",
84
- "score": 26.060364
85
- },
86
- {
87
- "mid": "/m/0219gl",
88
- "id": "/en/eric_harris_and_dylan_klebold",
89
- "name": "Eric Harris and Dylan Klebold",
90
- "lang": "en",
91
- "score": 25.414064
92
- },
93
- {
94
- "mid": "/m/07g7jw",
95
- "id": "/en/dylan_walsh",
96
- "name": "Dylan Walsh",
97
- "notable": {
98
- "name": "Actor",
99
- "id": "/m/02hrh1q"
100
- },
101
- "lang": "en",
102
- "score": 24.362093
103
- },
104
- {
105
- "mid": "/m/03dqyd",
106
- "id": "/en/dylan_dog",
107
- "name": "Dylan Dog",
108
- "notable": {
109
- "name": "Fictional Character",
110
- "id": "/fictional_universe/fictional_character"
111
- },
112
- "lang": "en",
113
- "score": 23.879669
114
- },
115
- {
116
- "mid": "/m/07nx9j",
117
- "id": "/en/dylan_baker",
118
- "name": "Dylan Baker",
119
- "notable": {
120
- "name": "Actor",
121
- "id": "/m/02hrh1q"
122
- },
123
- "lang": "en",
124
- "score": 22.494648
125
- },
126
- {
127
- "mid": "/m/0dtb_z3",
128
- "id": "/authority/musicbrainz/dd48dca0-74b5-33e0-8a3b-7b5af62a2203",
129
- "name": "Dylan",
130
- "notable": {
131
- "name": "Musical Album",
132
- "id": "/music/album"
133
- },
134
- "lang": "en",
135
- "score": 22.073868
136
- },
137
- {
138
- "mid": "/m/05q546",
139
- "id": "/en/dylan_ratigan",
140
- "name": "Dylan Ratigan",
141
- "notable": {
142
- "name": "TV Personality",
143
- "id": "/tv/tv_personality"
144
- },
145
- "lang": "en",
146
- "score": 21.934017
147
- },
148
- {
149
- "mid": "/m/0lqsy",
150
- "id": "/en/full_house",
151
- "name": "Full House",
152
- "notable": {
153
- "name": "TV Program",
154
- "id": "/tv/tv_program"
155
- },
156
- "lang": "en",
157
- "score": 21.582886
158
- },
159
- {
160
- "mid": "/m/0gw_yr3",
161
- "id": "/authority/imdb/name/nm3729721",
162
- "name": "Dylan O'Brien",
163
- "notable": {
164
- "name": "Actor",
165
- "id": "/m/02hrh1q"
166
- },
167
- "lang": "en",
168
- "score": 21.544655
169
- },
170
- {
171
- "mid": "/m/0b2p4m",
172
- "id": "/en/dylan_bruno",
173
- "name": "Dylan Bruno",
174
- "notable": {
175
- "name": "Actor",
176
- "id": "/m/02hrh1q"
177
- },
178
- "lang": "en",
179
- "score": 21.431660
180
- },
181
- {
182
- "mid": "/m/08c8zn",
183
- "id": "/en/sara_dylan",
184
- "name": "Sara Dylan",
185
- "notable": {
186
- "name": "Model",
187
- "id": "/m/0d1pc"
188
- },
189
- "lang": "en",
190
- "score": 20.911421
191
- },
192
- {
193
- "mid": "/m/027p9zq",
194
- "id": "/en/brad_benton",
195
- "name": "Dylan Vox",
196
- "notable": {
197
- "name": "Actor",
198
- "id": "/m/02hrh1q"
199
- },
200
- "lang": "en",
201
- "score": 20.779615
202
- },
203
- {
204
- "mid": "/m/01wk7ld",
205
- "id": "/en/dizzee_rascal",
206
- "name": "Dizzee Rascal",
207
- "notable": {
208
- "name": "Rapper",
209
- "id": "/m/0hpcdn2"
210
- },
211
- "lang": "en",
212
- "score": 20.738529
213
63
  }
214
64
  ]
@@ -0,0 +1,56 @@
1
+ [
2
+ {
3
+ "mid": "/m/01vrncs",
4
+ "id": "/en/bob_dylan",
5
+ "name": "Bob Dylan",
6
+ "notable": {
7
+ "name": "Folk rock Artist",
8
+ "id": "/m/016jny"
9
+ },
10
+ "lang": "en",
11
+ "score": 82.743378,
12
+ "output": {
13
+ "description": {
14
+ "/common/topic/description": [
15
+ "Bob Dylan is an American singer-songwriter, artist, and writer. He has been an influential figure in popular music and culture for more than five decades. Much of his most celebrated work dates from the 1960s, when he was both a chronicler and a reluctant figurehead of social unrest. A number of Dylan's early songs, such as \"Blowin' in the Wind\" and \"The Times They Are a-Changin'\", became anthems for the American civil rights and anti-war movements. Leaving behind his initial base in the culture of the folk music revival, Dylan's six-minute single \"Like a Rolling Stone\" radically altered the parameters of popular music in 1965. His mid-1960s recordings, backed by rock musicians, reached the top end of the United States music charts while also attracting denunciation and criticism from others in the folk movement.\nDylan's lyrics have incorporated a variety of political, social, philosophical, and literary influences. They defied existing pop music conventions and appealed hugely to the then burgeoning counterculture."
16
+ ]
17
+ }
18
+ }
19
+ },
20
+ {
21
+ "mid": "/m/04prwq",
22
+ "id": "/en/dylan_and_cole_sprouse",
23
+ "name": "Dylan and Cole Sprouse",
24
+ "notable": {
25
+ "name": "Singer",
26
+ "id": "/m/0290ngj"
27
+ },
28
+ "lang": "en",
29
+ "score": 39.279640,
30
+ "output": {
31
+ "description": {
32
+ "/common/topic/description": [
33
+ "Dylan Thomas Sprouse and Cole Mitchell Sprouse are American actors. They are twins and are collectively referred to as Dylan and Cole Sprouse or the Sprouse brothers, usually abbreviated as Sprouse Bros. Their first major theatrical film role was in Big Daddy, where they starred alongside Adam Sandler. They later appeared in several television sitcoms and starred in the straight-to-DVD films, I Saw Mommy Kissing Santa Claus and Just for Kicks.\nIn 2005, they starred in the Disney Channel sitcom The Suite Life of Zack & Cody. As a result of the series' success, the media has termed them \"heartthrobs\" and \"overwhelming draws\" among preteen and teen audiences. The following year, the brothers launched a franchise known as the Sprouse Bros brand, which included a clothing line, book series and magazine. The majority of the Sprouses' franchise ended in 2008, except for their clothing line. The Suite Life of Zack & Cody was retooled in 2008 as The Suite Life on Deck, in which the brothers reprised their roles as Zack and Cody. The Suite Life on Deck went on to become the most-watched tween/children's television show in 2008 and 2009. The show ended in May 2011."
34
+ ]
35
+ }
36
+ }
37
+ },
38
+ {
39
+ "mid": "/m/02fkm",
40
+ "id": "/en/dylan_thomas",
41
+ "name": "Dylan Thomas",
42
+ "notable": {
43
+ "name": "Novelist",
44
+ "id": "/m/02xhgwq"
45
+ },
46
+ "lang": "en",
47
+ "score": 38.964607,
48
+ "output": {
49
+ "description": {
50
+ "/common/topic/description": [
51
+ "Dylan Marlais Thomas was a Welsh poet and writer whose works include the poems \"Do not go gentle into that good night\" and \"And death shall have no dominion\", the \"play for voices\", Under Milk Wood, and stories and radio broadcasts such as A Child's Christmas in Wales and Portrait of the Artist as a Young Dog. He became popular in his lifetime and remained so after his premature death in New York. In his later life he acquired a reputation, which he encouraged, as a \"roistering, drunken and doomed poet\".\nThomas was born in Swansea, Wales, in 1914. An undistinguished pupil, he left school at 16, becoming a journalist for a short time. Although many of his works appeared in print while he was still a teenager, it was the publication of \"Light breaks where no sun shines\", in 1934, that caught the attention of the literary world. While living in London, Thomas met Caitlin Macnamara, whom he married in 1937. Their relationship was defined by alcoholism and was mutually destructive. In the early part of his marriage, Thomas and his family lived hand-to-mouth, settling in the Welsh fishing village of Laugharne."
52
+ ]
53
+ }
54
+ }
55
+ }
56
+ ]
@@ -55,7 +55,7 @@ describe FreebaseAPI::Topic do
55
55
 
56
56
  it "should return ordered scores" do
57
57
  topic_search.keys.first.should == 72.587578
58
- topic_search.keys.last.should == 20.738529
58
+ topic_search.keys.last.should == 27.369299
59
59
  end
60
60
 
61
61
  it "should return topics" do
@@ -69,6 +69,14 @@ describe FreebaseAPI::Topic do
69
69
  it "should store some properties" do
70
70
  item.properties.keys.should == ["/type/object/name", "/common/topic/notable_for"]
71
71
  end
72
+
73
+ context "with output" do
74
+ let(:data) { load_fixture 'search_with_output' }
75
+
76
+ it "should store some properties" do
77
+ item.properties.keys.should == ["/type/object/name", "/common/topic/notable_for", "/common/topic/description"]
78
+ end
79
+ end
72
80
  end
73
81
 
74
82
  describe "#id" do
@@ -163,4 +171,4 @@ describe FreebaseAPI::Topic do
163
171
  topic.image.id.should == topic.id
164
172
  end
165
173
  end
166
- end
174
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freebase-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aymeric Brisse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -50,6 +50,7 @@ files:
50
50
  - spec/attribute_spec.rb
51
51
  - spec/fixtures/img.jpg
52
52
  - spec/fixtures/search.json
53
+ - spec/fixtures/search_with_output.json
53
54
  - spec/fixtures/topic.json
54
55
  - spec/freebase_api_spec.rb
55
56
  - spec/image_spec.rb
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  version: '0'
77
78
  requirements: []
78
79
  rubyforge_project:
79
- rubygems_version: 2.2.1
80
+ rubygems_version: 2.4.4
80
81
  signing_key:
81
82
  specification_version: 4
82
83
  summary: Provides access to both a raw-access and an abstract-layer to the Freebase
@@ -85,6 +86,7 @@ test_files:
85
86
  - spec/attribute_spec.rb
86
87
  - spec/fixtures/img.jpg
87
88
  - spec/fixtures/search.json
89
+ - spec/fixtures/search_with_output.json
88
90
  - spec/fixtures/topic.json
89
91
  - spec/freebase_api_spec.rb
90
92
  - spec/image_spec.rb