open_calais 0.3.2 → 0.4.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.
- checksums.yaml +5 -5
- data/.travis.yml +8 -3
- data/README.md +10 -7
- data/Rakefile +1 -0
- data/lib/open_calais/client.rb +1 -1
- data/lib/open_calais/configuration.rb +2 -2
- data/lib/open_calais/connection.rb +6 -0
- data/lib/open_calais/response.rb +55 -25
- data/lib/open_calais/version.rb +1 -1
- data/test/client_test.rb +12 -12
- data/test/configuration_test.rb +1 -1
- data/test/open_calais_test.rb +7 -7
- data/test/test_helper.rb +0 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 34b051160ea2d22366cacafdcb786d98e7671c49cfd67798095e0563b08766bc
|
4
|
+
data.tar.gz: fc056e88eb523daeaa03d14e5b70ceb5797b352e062dbf15d7807b204dc99491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8765c48314b227bee03d5fd88c7e6e178724574a316b139c651a27da1ad8d992fd33bf54ae419d76a68d88d44bc0535df5195c47ce905e405104adc13f13b08d
|
7
|
+
data.tar.gz: 01b798fb0b54312b077c1ef3cc38fa926dc86ce395323bcfeef4ae24410838bc1b944b6d363c1ac49d36282761eef0f7996f9f0e2aa3e3d2cca6f86ade3c3a21
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -4,15 +4,18 @@
|
|
4
4
|
[](https://travis-ci.org/PRX/open_calais)
|
5
5
|
[](https://codeclimate.com/github/PRX/open_calais)
|
6
6
|
[](https://coveralls.io/r/PRX/open_calais?branch=master)
|
7
|
-
[](https://gemnasium.com/PRX/open_calais)
|
8
7
|
|
9
8
|
_Gem Version 0.1.* supports the original OpenCalais API_
|
10
9
|
|
11
|
-
_Gem Version 0.2.* now uses the upgraded API http://
|
10
|
+
_Gem Version 0.2.* now uses the upgraded API http://www.opencalais.com/_
|
12
11
|
|
13
|
-
|
12
|
+
_Gem Version 0.4.* supports refinitiv API_
|
14
13
|
|
15
|
-
|
14
|
+
Open Calais is now found at: https://developers.refinitiv.com/open-permid/intelligent-tagging-restful-api
|
15
|
+
|
16
|
+
It has a new default endpoint: https://api-eit.refinitiv.com/permid/calais
|
17
|
+
|
18
|
+
This is a ruby gem to access the (formerly OpenCalais) [Refinitiv Intelligent Tagging API](https://developers.refinitiv.com/open-permid/intelligent-tagging-restful-api), using the REST API, and JSON responses.
|
16
19
|
|
17
20
|
It uses [Faraday](https://github.com/lostisland/faraday) to abstract HTTP library (defaults to use excon because it is excellent), and multi_json to abstract JSON parsing.
|
18
21
|
|
@@ -34,7 +37,7 @@ Or install it yourself as:
|
|
34
37
|
|
35
38
|
## Usage
|
36
39
|
|
37
|
-
OpenCalais has one main method, `enrich`, and so does the gem:
|
40
|
+
Intelligent Tagging (OpenCalais) has one main method, `enrich`, and so does the gem:
|
38
41
|
|
39
42
|
```ruby
|
40
43
|
require 'open_calais'
|
@@ -45,7 +48,7 @@ OpenCalais.configure do |c|
|
|
45
48
|
end
|
46
49
|
|
47
50
|
# or you can configure for a single call
|
48
|
-
open_calais = OpenCalais::Client.new(:api_key=>'an api key')
|
51
|
+
open_calais = OpenCalais::Client.new(:api_key => 'an api key')
|
49
52
|
|
50
53
|
# it returns a OpenCalais::Response instance
|
51
54
|
response = open_calais.enrich('Ruby on Rails is a fantastic web framework. It uses MVC, and the Ruby programming language invented by Matz in Japan.')
|
@@ -55,7 +58,7 @@ response.raw
|
|
55
58
|
|
56
59
|
# and has been parsed a bit to get :language, :topics, :tags, :entities, :relations, :locations
|
57
60
|
# as lists of hashes
|
58
|
-
response.tags.each{|t| puts t[:name] }
|
61
|
+
response.tags.each { |t| puts t[:name] }
|
59
62
|
```
|
60
63
|
|
61
64
|
## Contributing
|
data/Rakefile
CHANGED
data/lib/open_calais/client.rb
CHANGED
@@ -17,12 +17,12 @@ module OpenCalais
|
|
17
17
|
DEFAULT_ADAPTER = :excon
|
18
18
|
|
19
19
|
# The api endpoint to get REST info from opencalais
|
20
|
-
DEFAULT_ENDPOINT = 'https://api.
|
20
|
+
DEFAULT_ENDPOINT = 'https://api-eit.refinitiv.com/permid/calais'.freeze
|
21
21
|
|
22
22
|
# The value sent in the http header for 'User-Agent' if none is set
|
23
23
|
DEFAULT_USER_AGENT = "OpenCalais Ruby Gem #{OpenCalais::VERSION}".freeze
|
24
24
|
|
25
|
-
attr_accessor
|
25
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
26
26
|
|
27
27
|
# Convenience method to allow for global setting of configuration options
|
28
28
|
def configure
|
@@ -1,10 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
require 'faraday_middleware'
|
4
|
+
require 'hashie'
|
4
5
|
|
5
6
|
module OpenCalais
|
6
7
|
module Connection
|
7
8
|
|
9
|
+
class HashieWrapper < ::Hashie::Mash
|
10
|
+
disable_warnings
|
11
|
+
end
|
12
|
+
|
8
13
|
ALLOWED_OPTIONS = [
|
9
14
|
:headers,
|
10
15
|
:url,
|
@@ -37,6 +42,7 @@ module OpenCalais
|
|
37
42
|
|
38
43
|
def connection(options={})
|
39
44
|
opts = merge_default_options(options)
|
45
|
+
FaradayMiddleware::Mashify.mash_class = HashieWrapper
|
40
46
|
Faraday::Connection.new(opts) do |connection|
|
41
47
|
connection.request :url_encoded
|
42
48
|
connection.response :mashify
|
data/lib/open_calais/response.rb
CHANGED
@@ -41,38 +41,68 @@ module OpenCalais
|
|
41
41
|
r.each do |k,v|
|
42
42
|
case v._typeGroup
|
43
43
|
when 'topics'
|
44
|
-
self.topics << {
|
44
|
+
self.topics << {
|
45
|
+
:name => humanize_topic(v.name),
|
46
|
+
:score => v.score.to_f,
|
47
|
+
:original => v.name
|
48
|
+
}
|
45
49
|
when 'socialTag'
|
46
|
-
self.tags << {
|
50
|
+
self.tags << {
|
51
|
+
:name => v.name.gsub('_', ' and ').downcase,
|
52
|
+
:score => importance_to_score(v.importance)
|
53
|
+
}
|
47
54
|
when 'entities'
|
48
|
-
|
49
|
-
|
50
|
-
instances = Array(v.instances).select{|i| i.exact.downcase != item[:name].downcase }
|
51
|
-
item[:matches] = instances if instances && instances.size > 0
|
52
|
-
|
53
|
-
if OpenCalais::GEO_TYPES.include?(v._type)
|
54
|
-
if (v.resolutions && v.resolutions.size > 0)
|
55
|
-
r = v.resolutions.first
|
56
|
-
item[:name] = r.shortname || r.name
|
57
|
-
item[:latitude] = r.latitude
|
58
|
-
item[:longitude] = r.longitude
|
59
|
-
item[:country] = r.containedbycountry if r.containedbycountry
|
60
|
-
item[:state] = r.containedbystate if r.containedbystate
|
61
|
-
end
|
62
|
-
self.locations << item
|
63
|
-
else
|
64
|
-
self.entities << item
|
65
|
-
end
|
55
|
+
parse_entity(k, v)
|
66
56
|
when 'relations'
|
67
|
-
|
68
|
-
item[:type] = transliterate(v._type).titleize
|
69
|
-
self.relations << item
|
57
|
+
parse_relation(k, v)
|
70
58
|
end
|
71
59
|
end
|
72
60
|
|
73
61
|
# remove social tags which are in the topics list already
|
74
|
-
topic_names = self.topics.collect{|topic| topic[:name].downcase}
|
75
|
-
self.tags.delete_if{|tag| topic_names.include?(tag[:name]) }
|
62
|
+
topic_names = self.topics.collect { |topic| topic[:name].downcase }
|
63
|
+
self.tags.delete_if { |tag| topic_names.include?(tag[:name]) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def parse_entity(k, v)
|
67
|
+
if v.name.nil?
|
68
|
+
v.name = v.instances.first[:exact]
|
69
|
+
end
|
70
|
+
|
71
|
+
item = {
|
72
|
+
:guid => k,
|
73
|
+
:name => v.name,
|
74
|
+
:type => transliterate(v._type).titleize,
|
75
|
+
:score => v.relevance
|
76
|
+
}
|
77
|
+
|
78
|
+
instances = Array(v.instances).select { |i| i.exact.downcase != item[:name].downcase }
|
79
|
+
if instances && instances.size > 0
|
80
|
+
item[:matches] = instances
|
81
|
+
end
|
82
|
+
|
83
|
+
if OpenCalais::GEO_TYPES.include?(v._type)
|
84
|
+
self.locations << set_location_info(item, v)
|
85
|
+
else
|
86
|
+
self.entities << item
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def set_location_info(item, v)
|
91
|
+
if (v.resolutions && v.resolutions.size > 0)
|
92
|
+
r = v.resolutions.first
|
93
|
+
item[:name] = r.shortname || r.name
|
94
|
+
item[:latitude] = r.latitude
|
95
|
+
item[:longitude] = r.longitude
|
96
|
+
item[:country] = r.containedbycountry if r.containedbycountry
|
97
|
+
item[:state] = r.containedbystate if r.containedbystate
|
98
|
+
end
|
99
|
+
item
|
100
|
+
end
|
101
|
+
|
102
|
+
def parse_relation(k, v)
|
103
|
+
item = v.reject { |key,val| key[0] == '_' || key == 'instances' } || {}
|
104
|
+
item[:type] = transliterate(v._type).titleize
|
105
|
+
self.relations << item
|
76
106
|
end
|
77
107
|
end
|
78
108
|
end
|
data/lib/open_calais/version.rb
CHANGED
data/test/client_test.rb
CHANGED
@@ -4,36 +4,36 @@ describe OpenCalais::Client do
|
|
4
4
|
|
5
5
|
it "is initialized with defaults" do
|
6
6
|
oc = OpenCalais::Client.new
|
7
|
-
oc.current_options.wont_be_nil
|
8
|
-
oc.current_options.must_equal OpenCalais.options
|
7
|
+
_(oc.current_options).wont_be_nil
|
8
|
+
_(oc.current_options).must_equal OpenCalais.options
|
9
9
|
end
|
10
10
|
|
11
11
|
it "is initialized with specific values" do
|
12
12
|
oc = OpenCalais::Client.new(:api_key => 'current')
|
13
|
-
oc.current_options.wont_be_nil
|
14
|
-
oc.current_options.wont_equal OpenCalais.options
|
15
|
-
oc.current_options[:api_key].must_equal 'current'
|
16
|
-
oc.api_key.must_equal 'current'
|
13
|
+
_(oc.current_options).wont_be_nil
|
14
|
+
_(oc.current_options).wont_equal OpenCalais.options
|
15
|
+
_(oc.current_options[:api_key]).must_equal 'current'
|
16
|
+
_(oc.api_key).must_equal 'current'
|
17
17
|
end
|
18
18
|
|
19
19
|
it "gets tags for text" do
|
20
20
|
oc = OpenCalais::Client.new(:api_key => ENV['OPEN_CALAIS_KEY'])
|
21
21
|
response = oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz")
|
22
|
-
response.wont_be_nil
|
23
|
-
response.raw.wont_be_nil
|
22
|
+
_(response).wont_be_nil
|
23
|
+
_(response.raw).wont_be_nil
|
24
24
|
end
|
25
25
|
|
26
26
|
it "passes in header options in client" do
|
27
27
|
oc = OpenCalais::Client.new(:api_key => ENV['OPEN_CALAIS_KEY'], :content_type => OpenCalais::CONTENT_TYPES[:html])
|
28
28
|
response = oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz")
|
29
|
-
response.wont_be_nil
|
30
|
-
response.raw.wont_be_nil
|
29
|
+
_(response).wont_be_nil
|
30
|
+
_(response.raw).wont_be_nil
|
31
31
|
end
|
32
32
|
|
33
33
|
it "passes in header optionsin enrich" do
|
34
34
|
oc = OpenCalais::Client.new(:api_key => ENV['OPEN_CALAIS_KEY'])
|
35
35
|
response = oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz", :headers => {:content_type => OpenCalais::CONTENT_TYPES[:html]})
|
36
|
-
response.wont_be_nil
|
37
|
-
response.raw.wont_be_nil
|
36
|
+
_(response).wont_be_nil
|
37
|
+
_(response.raw).wont_be_nil
|
38
38
|
end
|
39
39
|
end
|
data/test/configuration_test.rb
CHANGED
data/test/open_calais_test.rb
CHANGED
@@ -3,22 +3,22 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
|
3
3
|
describe OpenCalais do
|
4
4
|
|
5
5
|
it "has default configuration options" do
|
6
|
-
OpenCalais.options.wont_be_nil
|
7
|
-
OpenCalais.options[:adapter].must_equal OpenCalais::Configuration::DEFAULT_ADAPTER
|
6
|
+
_(OpenCalais.options).wont_be_nil
|
7
|
+
_(OpenCalais.options[:adapter]).must_equal OpenCalais::Configuration::DEFAULT_ADAPTER
|
8
8
|
end
|
9
9
|
|
10
10
|
it "can be configured" do
|
11
|
-
OpenCalais.must_respond_to(:configure)
|
11
|
+
_(OpenCalais).must_respond_to(:configure)
|
12
12
|
|
13
|
-
OpenCalais.api_key.must_be_nil
|
13
|
+
_(OpenCalais.api_key).must_be_nil
|
14
14
|
|
15
15
|
OpenCalais.configure do |c|
|
16
|
-
c.must_equal OpenCalais
|
16
|
+
_(c).must_equal OpenCalais
|
17
17
|
c.api_key = "this is a test key"
|
18
18
|
end
|
19
19
|
|
20
|
-
OpenCalais.api_key.must_equal "this is a test key"
|
20
|
+
_(OpenCalais.api_key).must_equal "this is a test key"
|
21
21
|
|
22
|
-
OpenCalais.options[:api_key].must_equal "this is a test key"
|
22
|
+
_(OpenCalais.options[:api_key]).must_equal "this is a test key"
|
23
23
|
end
|
24
24
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_calais
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kuklewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -208,8 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
208
|
- !ruby/object:Gem::Version
|
209
209
|
version: '0'
|
210
210
|
requirements: []
|
211
|
-
|
212
|
-
rubygems_version: 2.4.5
|
211
|
+
rubygems_version: 3.1.2
|
213
212
|
signing_key:
|
214
213
|
specification_version: 4
|
215
214
|
summary: This is a gem to call the OpenCalais improved REST API.
|