open_calais 0.0.2 → 0.1.0

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.
data/lib/open_calais.rb CHANGED
@@ -5,6 +5,8 @@ require 'open_calais/version'
5
5
  require 'open_calais/configuration'
6
6
  require 'open_calais/client'
7
7
 
8
+ require 'active_support/all'
9
+
8
10
  module OpenCalais
9
11
  extend Configuration
10
12
 
@@ -28,14 +28,15 @@ module OpenCalais
28
28
  end
29
29
 
30
30
  def setup(options={})
31
- options = OpenCalais.options.merge(options)
32
- self.current_options = options
31
+ opts = Hash[options.map{ |k, v| [k.to_sym, v] }]
32
+ opts = OpenCalais.options.merge(opts)
33
+ self.current_options = opts
33
34
  Configuration.keys.each do |key|
34
- send("#{key}=", options[key])
35
+ send("#{key}=", opts[key])
35
36
  end
36
37
  end
37
38
 
38
- def enrich(text, opts={})
39
+ def analyze(text, opts={})
39
40
  raise 'Specify a value for the text' unless (text && text.length > 0)
40
41
  options = current_options.merge(opts)
41
42
 
@@ -44,6 +45,11 @@ module OpenCalais
44
45
  end
45
46
  OpenCalais::Response.new(response)
46
47
  end
48
+
49
+ # using analyze as a standard method name
50
+ # enrich is more OpenCalais specific
51
+ alias_method :enrich, :analyze
52
+
47
53
  end
48
54
 
49
55
  end
@@ -18,7 +18,7 @@ module OpenCalais
18
18
  end
19
19
 
20
20
  def humanize_topic(topic)
21
- topic.gsub('_', ' and ')
21
+ topic.gsub('_', ' & ').titleize.remove_formatting
22
22
  end
23
23
 
24
24
  def importance_to_score(imp)
@@ -37,11 +37,11 @@ module OpenCalais
37
37
  r.each do |k,v|
38
38
  case v._typeGroup
39
39
  when 'topics'
40
- self.topics << {:name => humanize_topic(v.categoryName), :score => v.score, :original => v.categoryName}
40
+ self.topics << {:name => humanize_topic(v.categoryName), :score => v.score.to_f, :original => v.categoryName}
41
41
  when 'socialTag'
42
- self.tags << {:name => v.name, :score => importance_to_score(v.importance)}
42
+ self.tags << {:name => v.name.gsub('_', ' and ').downcase, :score => importance_to_score(v.importance)}
43
43
  when 'entities'
44
- item = {:guid => k, :name => v.name, :type => v._type}
44
+ item = {:guid => k, :name => v.name, :type => v._type.remove_formatting.titleize, :score => 1.0}
45
45
 
46
46
  instances = Array(v.instances).select{|i| i.exact.downcase != item[:name].downcase }
47
47
  item[:matches] = instances if instances && instances.size > 0
@@ -49,7 +49,7 @@ module OpenCalais
49
49
  if OpenCalais::GEO_TYPES.include?(v._type)
50
50
  if (v.resolutions && v.resolutions.size > 0)
51
51
  r = v.resolutions.first
52
- item[:name] = r.shortname
52
+ item[:name] = r.shortname || r.name
53
53
  item[:latitude] = r.latitude
54
54
  item[:longitude] = r.longitude
55
55
  item[:country] = r.containedbycountry if r.containedbycountry
@@ -60,13 +60,15 @@ module OpenCalais
60
60
  self.entities << item
61
61
  end
62
62
  when 'relations'
63
- item = v.reject_if{|k,v| k[0] == '_' || k == 'instances'}
64
- item[:type] = v._type
63
+ item = v.reject{|k,v| k[0] == '_' || k == 'instances'} || {}
64
+ item[:type] = v._type.remove_formatting.titleize
65
65
  self.relations << item
66
66
  end
67
67
  end
68
68
 
69
- # remove social tags which are in the topics list already
69
+ # remove social tags which are in the topics list already
70
+ topic_names = self.topics.collect{|topic| topic[:name].downcase}
71
+ self.tags.delete_if{|tag| topic_names.include?(tag[:name]) }
70
72
  end
71
73
  end
72
74
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module OpenCalais
4
- VERSION = "0.0.2"
4
+ VERSION = "0.1.0"
5
5
  end
data/open_calais.gemspec CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |gem|
24
24
  gem.add_runtime_dependency('multi_xml')
25
25
  gem.add_runtime_dependency('excon')
26
26
  gem.add_runtime_dependency('hashie', '>= 0.4.0')
27
+ gem.add_runtime_dependency('activesupport')
28
+ gem.add_runtime_dependency('stringex')
27
29
 
28
30
  gem.add_development_dependency('rake')
29
31
  gem.add_development_dependency('minitest')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_calais
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
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-04-09 00:00:00.000000000 Z
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -119,6 +119,38 @@ dependencies:
119
119
  - - ! '>='
120
120
  - !ruby/object:Gem::Version
121
121
  version: 0.4.0
122
+ - !ruby/object:Gem::Dependency
123
+ name: activesupport
124
+ requirement: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ - !ruby/object:Gem::Dependency
139
+ name: stringex
140
+ requirement: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
122
154
  - !ruby/object:Gem::Dependency
123
155
  name: rake
124
156
  requirement: !ruby/object:Gem::Requirement
@@ -189,7 +221,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
221
  version: '0'
190
222
  segments:
191
223
  - 0
192
- hash: -4380033744204018911
224
+ hash: -2805080082593624096
193
225
  required_rubygems_version: !ruby/object:Gem::Requirement
194
226
  none: false
195
227
  requirements:
@@ -198,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
230
  version: '0'
199
231
  segments:
200
232
  - 0
201
- hash: -4380033744204018911
233
+ hash: -2805080082593624096
202
234
  requirements: []
203
235
  rubyforge_project:
204
236
  rubygems_version: 1.8.23