alchemy-api-rb 0.4.0 → 0.5.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 +4 -4
- data/.rubocop.yml +17 -0
- data/.travis.yml +7 -2
- data/CHANGELOG.md +23 -0
- data/CONTRIBUTING.md +117 -0
- data/README.md +32 -20
- data/Rakefile +6 -3
- data/alchemy-api-rb.gemspec +10 -9
- data/lib/alchemy-api/author_extraction.rb +1 -3
- data/lib/alchemy-api/base.rb +7 -11
- data/lib/alchemy-api/concept_tagging.rb +1 -2
- data/lib/alchemy-api/config.rb +3 -3
- data/lib/alchemy-api/entity_extraction.rb +1 -1
- data/lib/alchemy-api/image_tagging.rb +1 -1
- data/lib/alchemy-api/keyword_extraction.rb +1 -1
- data/lib/alchemy-api/language_detection.rb +0 -2
- data/lib/alchemy-api/relation_extraction.rb +1 -2
- data/lib/alchemy-api/sentiment_analysis.rb +1 -2
- data/lib/alchemy-api/targeted_sentiment_analysis.rb +1 -1
- data/lib/alchemy-api/taxonomy.rb +1 -2
- data/lib/alchemy-api/text_categorization.rb +0 -1
- data/lib/alchemy-api/text_extraction.rb +1 -1
- data/lib/alchemy-api/title_extraction.rb +1 -1
- data/lib/alchemy-api/version.rb +1 -1
- data/lib/alchemy_api.rb +19 -19
- data/spec/alchemy_api_spec.rb +22 -22
- data/spec/author_extraction_spec.rb +8 -19
- data/spec/base_spec.rb +13 -10
- data/spec/concept_tagging_spec.rb +11 -13
- data/spec/entity_extraction_spec.rb +13 -13
- data/spec/image_tagging_spec.rb +13 -11
- data/spec/keyword_extraction_spec.rb +13 -13
- data/spec/language_detection_spec.rb +10 -12
- data/spec/relation_extraction_spec.rb +12 -13
- data/spec/sentiment_analysis_spec.rb +11 -12
- data/spec/spec_helper.rb +3 -2
- data/spec/targeted_sentiment_analysis_spec.rb +16 -14
- data/spec/text_categorization_spec.rb +11 -12
- data/spec/text_extraction_spec.rb +7 -7
- metadata +37 -20
data/lib/alchemy-api/taxonomy.rb
CHANGED
data/lib/alchemy-api/version.rb
CHANGED
data/lib/alchemy_api.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
1
|
+
require 'alchemy-api/version'
|
2
|
+
require 'alchemy-api/config'
|
3
|
+
require 'alchemy-api/base'
|
4
|
+
require 'alchemy-api/keyword_extraction'
|
5
|
+
require 'alchemy-api/text_extraction'
|
6
|
+
require 'alchemy-api/title_extraction'
|
7
|
+
require 'alchemy-api/entity_extraction'
|
8
|
+
require 'alchemy-api/sentiment_analysis'
|
9
|
+
require 'alchemy-api/targeted_sentiment_analysis'
|
10
|
+
require 'alchemy-api/relation_extraction'
|
11
|
+
require 'alchemy-api/concept_tagging'
|
12
|
+
require 'alchemy-api/text_categorization'
|
13
|
+
require 'alchemy-api/language_detection'
|
14
|
+
require 'alchemy-api/author_extraction'
|
15
|
+
require 'alchemy-api/taxonomy'
|
16
|
+
require 'alchemy-api/image_tagging'
|
17
17
|
|
18
18
|
module AlchemyAPI
|
19
|
-
BASE_URL =
|
19
|
+
BASE_URL = 'http://access.alchemyapi.com/calls/'
|
20
20
|
|
21
21
|
def self.config
|
22
22
|
Config
|
@@ -37,8 +37,8 @@ module AlchemyAPI
|
|
37
37
|
def self.search(mode, opts)
|
38
38
|
klass = Config.modes[mode]
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
fail InvalidAPIKey unless Config.apikey
|
41
|
+
fail InvalidSearchMode unless klass
|
42
42
|
|
43
43
|
klass.new.search(opts)
|
44
44
|
end
|
data/spec/alchemy_api_spec.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe AlchemyAPI do
|
4
|
-
subject
|
4
|
+
subject { AlchemyAPI }
|
5
5
|
|
6
|
-
it
|
7
|
-
AlchemyAPI::BASE_URL.must_be :==,
|
6
|
+
it 'knows the alchemy api url' do
|
7
|
+
AlchemyAPI::BASE_URL.must_be :==, 'http://access.alchemyapi.com/calls/'
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
key =
|
10
|
+
it 'allows you to set the key directly' do
|
11
|
+
key = 'xxxxxxxx'
|
12
12
|
AlchemyAPI.key = key
|
13
13
|
|
14
14
|
AlchemyAPI.key.must_be :==, key
|
15
15
|
end
|
16
16
|
|
17
17
|
describe AlchemyAPI::Config do
|
18
|
-
describe
|
19
|
-
it
|
18
|
+
describe '.add_mode' do
|
19
|
+
it 'allows classes to register themselves' do
|
20
20
|
class Foo
|
21
21
|
AlchemyAPI::Config.add_mode :foo, self
|
22
22
|
end
|
@@ -25,14 +25,14 @@ describe AlchemyAPI do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
28
|
+
describe '.output_mode' do
|
29
29
|
after do
|
30
30
|
AlchemyAPI.configure do |config|
|
31
31
|
config.output_mode = :json
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'allows output mode to be set' do
|
36
36
|
AlchemyAPI.configure do |config|
|
37
37
|
config.output_mode = :xml
|
38
38
|
end
|
@@ -40,31 +40,31 @@ describe AlchemyAPI do
|
|
40
40
|
AlchemyAPI.config.output_mode.must_be :==, :xml
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
|
43
|
+
it 'errors on invalid output mode' do
|
44
|
+
lambda do
|
45
45
|
AlchemyAPI.configure do |config|
|
46
46
|
config.output_mode = :xls
|
47
47
|
end
|
48
|
-
|
48
|
+
end.must_raise AlchemyAPI::InvalidOutputMode
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
describe
|
54
|
-
it
|
53
|
+
describe '.search' do
|
54
|
+
it 'needs an api key' do
|
55
55
|
AlchemyAPI::Config.apikey = nil
|
56
56
|
|
57
|
-
|
58
|
-
AlchemyAPI.search(:keyword_extraction, :
|
59
|
-
|
57
|
+
lambda do
|
58
|
+
AlchemyAPI.search(:keyword_extraction, text: 'foo')
|
59
|
+
end.must_raise AlchemyAPI::InvalidAPIKey
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
AlchemyAPI::Config.apikey =
|
62
|
+
it 'needs a valid mode' do
|
63
|
+
AlchemyAPI::Config.apikey = 'xxxxxxxxxxx'
|
64
64
|
|
65
|
-
|
66
|
-
AlchemyAPI.search(:bar, :
|
67
|
-
|
65
|
+
lambda do
|
66
|
+
AlchemyAPI.search(:bar, text: 'hello')
|
67
|
+
end.must_raise AlchemyAPI::InvalidSearchMode
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -1,36 +1,28 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
|
-
describe AlchemyAPI,
|
3
|
+
describe AlchemyAPI, 'author_extraction' do
|
4
4
|
before do
|
5
5
|
AlchemyAPI::Config.apikey = API_KEY
|
6
6
|
end
|
7
7
|
|
8
|
-
subject
|
8
|
+
subject { AlchemyAPI::AuthorExtraction.new }
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe '#search' do
|
11
11
|
{
|
12
|
-
:
|
13
|
-
:
|
14
|
-
}.each do |type,value|
|
12
|
+
html: '<html><body>Google is a large, by Joe Smith</body></html>',
|
13
|
+
url: 'http://blog.alchemyapi.com/'
|
14
|
+
}.each do |type, value|
|
15
15
|
[:json].each do |output_mode|
|
16
16
|
before do
|
17
17
|
AlchemyAPI::Config.output_mode = output_mode
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "#{type} search with #{output_mode} results" do
|
21
|
-
it
|
21
|
+
it 'returns a string result' do
|
22
22
|
VCR.use_cassette("author_basic_#{type}_#{output_mode}_search") do
|
23
23
|
result = subject.search(type => value)
|
24
24
|
|
25
|
-
result.must_be_instance_of
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it "includes the keyword text and relavence" do
|
30
|
-
VCR.use_cassette("author_basic_#{type}_#{output_mode}_search") do
|
31
|
-
result = subject.search(type => value)
|
32
|
-
|
33
|
-
result["author"].wont_be_nil
|
25
|
+
result.must_be_instance_of String
|
34
26
|
end
|
35
27
|
end
|
36
28
|
end
|
@@ -38,6 +30,3 @@ describe AlchemyAPI, "author_extraction" do
|
|
38
30
|
end
|
39
31
|
end
|
40
32
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
data/spec/base_spec.rb
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe AlchemyAPI::Base do
|
4
|
-
subject
|
4
|
+
subject { AlchemyAPI::Base.new }
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe '#connection' do
|
7
|
+
it 'creates a connection' do
|
8
8
|
subject.send(:connection).wont_be_nil
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
12
|
-
it
|
13
|
-
subject
|
11
|
+
describe '#adapter' do
|
12
|
+
it 'uses the excon adapter' do
|
13
|
+
subject
|
14
|
+
.send(:connection)
|
15
|
+
.builder
|
16
|
+
.handlers
|
17
|
+
.must_include Faraday::Adapter::Excon
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
opts = { extra:
|
22
|
+
describe '#merge_options' do
|
23
|
+
it 'combines default options with user provided' do
|
24
|
+
opts = { extra: 'extra' }
|
21
25
|
expected = { outputMode: :json }.merge(opts)
|
22
26
|
|
23
27
|
subject.merged_options(opts).must_be :==, expected
|
24
28
|
end
|
25
29
|
end
|
26
|
-
|
27
30
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
|
-
describe AlchemyAPI,
|
3
|
+
describe AlchemyAPI, 'concept_extraction' do
|
4
4
|
before do
|
5
5
|
AlchemyAPI::Config.apikey = API_KEY
|
6
6
|
end
|
7
7
|
|
8
|
-
subject
|
8
|
+
subject { AlchemyAPI::ConceptTagging.new }
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe '#search' do
|
11
11
|
{
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
}.each do |type,value|
|
12
|
+
text: 'Google is a large company',
|
13
|
+
html: '<html><body>Google is a large company</body></html>',
|
14
|
+
url: 'http://www.alchemy.com'
|
15
|
+
}.each do |type, value|
|
16
16
|
[:json].each do |output_mode|
|
17
17
|
before do
|
18
18
|
AlchemyAPI::Config.output_mode = output_mode
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#{type} search with #{output_mode} results" do
|
22
|
-
it
|
22
|
+
it 'returns an array of results' do
|
23
23
|
VCR.use_cassette("concept_basic_#{type}_#{output_mode}_search") do
|
24
24
|
result = subject.search(type => value)
|
25
25
|
|
@@ -27,12 +27,12 @@ describe AlchemyAPI, "concept_extraction" do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'includes the keyword text and relavence' do
|
31
31
|
VCR.use_cassette("concept_basic_#{type}_#{output_mode}_search") do
|
32
32
|
result = subject.search(type => value)[0]
|
33
33
|
|
34
|
-
result[
|
35
|
-
result[
|
34
|
+
result['text'].wont_be_nil
|
35
|
+
result['relevance'].wont_be_nil
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -40,5 +40,3 @@ describe AlchemyAPI, "concept_extraction" do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
|
@@ -1,25 +1,25 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
|
-
describe AlchemyAPI,
|
3
|
+
describe AlchemyAPI, 'entity_extraction' do
|
4
4
|
before do
|
5
5
|
AlchemyAPI::Config.apikey = API_KEY
|
6
6
|
end
|
7
7
|
|
8
|
-
subject
|
8
|
+
subject { AlchemyAPI::EntityExtraction.new }
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe '#search' do
|
11
11
|
{
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
}.each do |type,value|
|
12
|
+
text: 'Google is a large company',
|
13
|
+
html: '<html><body>Google is a large company</body></html>',
|
14
|
+
url: 'http://www.google.com'
|
15
|
+
}.each do |type, value|
|
16
16
|
[:json].each do |output_mode|
|
17
17
|
before do
|
18
18
|
AlchemyAPI::Config.output_mode = output_mode
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#{type} search with #{output_mode} results" do
|
22
|
-
it
|
22
|
+
it 'returns an array of results' do
|
23
23
|
VCR.use_cassette("entity_basic_#{type}_#{output_mode}_search") do
|
24
24
|
result = subject.search(type => value)
|
25
25
|
|
@@ -27,14 +27,14 @@ describe AlchemyAPI, "entity_extraction" do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'includes the keyword text and relavence' do
|
31
31
|
VCR.use_cassette("entity_basic_#{type}_#{output_mode}_search") do
|
32
32
|
result = subject.search(type => value)[0]
|
33
33
|
|
34
|
-
result[
|
35
|
-
result[
|
36
|
-
result[
|
37
|
-
result[
|
34
|
+
result['text'].wont_be_nil
|
35
|
+
result['type'].wont_be_nil
|
36
|
+
result['count'].wont_be_nil
|
37
|
+
result['relevance'].wont_be_nil
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
data/spec/image_tagging_spec.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
|
-
describe AlchemyAPI,
|
3
|
+
describe AlchemyAPI, 'image_tagging' do
|
4
4
|
before do
|
5
5
|
AlchemyAPI::Config.apikey = API_KEY
|
6
6
|
end
|
7
7
|
|
8
|
-
subject
|
8
|
+
subject { AlchemyAPI::ImageTagging.new }
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe '#search' do
|
11
11
|
{
|
12
|
-
:
|
13
|
-
}.each do |type,value|
|
12
|
+
url: 'http://demo1.alchemyapi.com/images/vision/emaxfpo.jpg'
|
13
|
+
}.each do |type, value|
|
14
14
|
[:json].each do |output_mode|
|
15
15
|
before do
|
16
16
|
AlchemyAPI::Config.output_mode = output_mode
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "#{type} search with #{output_mode} results" do
|
20
|
-
it
|
21
|
-
|
20
|
+
it 'returns an array of results' do
|
21
|
+
cassette_name = "image_tagging_basic_#{type}_#{output_mode}_search"
|
22
|
+
VCR.use_cassette(cassette_name) do
|
22
23
|
result = subject.search(type => value)
|
23
24
|
|
24
25
|
result.must_be_instance_of Array
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
it
|
29
|
-
|
29
|
+
it 'includes the keyword text and score' do
|
30
|
+
cassette_name = "image_tagging_basic_#{type}_#{output_mode}_search"
|
31
|
+
VCR.use_cassette(cassette_name) do
|
30
32
|
result = subject.search(type => value)[0]
|
31
33
|
|
32
|
-
result[
|
33
|
-
result[
|
34
|
+
result['text'].wont_be_nil
|
35
|
+
result['score'].wont_be_nil
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|