yahoo_content_analysis 0.1.0 → 0.1.1
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.
@@ -32,8 +32,8 @@ module YahooContentAnalysis
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def analyze(content, opts={})
|
36
|
-
|
35
|
+
def analyze(content, opts={})
|
36
|
+
content = content.to_s.squish
|
37
37
|
response = connection.post do |request|
|
38
38
|
request.body = options(content)
|
39
39
|
end
|
@@ -15,15 +15,19 @@ module YahooContentAnalysis
|
|
15
15
|
@relations = []
|
16
16
|
@locations = []
|
17
17
|
|
18
|
-
parse(response)
|
18
|
+
parse(response) if response
|
19
19
|
end
|
20
20
|
|
21
21
|
def humanize_topic(topic)
|
22
22
|
topic.titleize.remove_formatting
|
23
23
|
end
|
24
24
|
|
25
|
-
def parse(response)
|
26
|
-
|
25
|
+
def parse(response=raw)
|
26
|
+
return if (response.nil?)
|
27
|
+
return if (!response.respond_to?(:body))
|
28
|
+
return if (!response.body['query'] || !response.body['query']['results'])
|
29
|
+
|
30
|
+
r = response.body['query']['results']
|
27
31
|
@language = get_language(r['lang'])
|
28
32
|
|
29
33
|
yahoo_categories = (r['yctCategories'] || {})['yctCategory'] || []
|
@@ -35,6 +39,7 @@ module YahooContentAnalysis
|
|
35
39
|
yahoo_entities = (r['entities'] || {})['entity'] || []
|
36
40
|
yahoo_entities = [yahoo_entities] unless yahoo_entities.is_a?(Array)
|
37
41
|
entities_hash = yahoo_entities.inject({}) do |hash, ent|
|
42
|
+
# puts "entity: #{ent.inspect}"
|
38
43
|
name = ent['text']['content']
|
39
44
|
if hash.has_key?(name)
|
40
45
|
existing = hash[name]
|
@@ -67,9 +72,12 @@ module YahooContentAnalysis
|
|
67
72
|
end
|
68
73
|
|
69
74
|
def extract_type(h)
|
75
|
+
# puts "extract_type: #{h.inspect}"
|
70
76
|
return nil unless (h && h['type'])
|
71
77
|
type = h['type'].is_a?(Array) ? h['type'].first : h['type']
|
72
|
-
(type['content'] || '').split('/')
|
78
|
+
content = (type['content'] || '').split('/')
|
79
|
+
content = (content[1] || content[0]).remove_formatting.titleize
|
80
|
+
content.blank? ? nil : content
|
73
81
|
end
|
74
82
|
|
75
83
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yahoo_content_analysis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -233,7 +233,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
233
233
|
version: '0'
|
234
234
|
segments:
|
235
235
|
- 0
|
236
|
-
hash:
|
236
|
+
hash: -652491989169488750
|
237
237
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
238
|
none: false
|
239
239
|
requirements:
|
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
242
|
version: '0'
|
243
243
|
segments:
|
244
244
|
- 0
|
245
|
-
hash:
|
245
|
+
hash: -652491989169488750
|
246
246
|
requirements: []
|
247
247
|
rubyforge_project:
|
248
248
|
rubygems_version: 1.8.23
|