alchemy_api 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.
@@ -0,0 +1,4 @@
1
+ 0.1.1
2
+ -----
3
+ * Content tagging API added [jjulian, GH-1]
4
+ * Added support for content-is-empty errors.
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/dbalatero/alchemy_api"
12
12
  gem.authors = ["David Balatero"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency 'typhoeus_spec_cache', '>= 0.2.2'
14
15
  gem.add_dependency "monster_mash", ">= 0.1.1"
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{alchemy_api}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Balatero"]
12
- s.date = %q{2010-05-17}
12
+ s.date = %q{2010-09-12}
13
13
  s.description = %q{Provides a client API library for AlchemyAPI's awesome NLP services. Allows you to make parallel or serial requests.}
14
14
  s.email = %q{dbalatero@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.files = [
21
21
  ".document",
22
22
  ".gitignore",
23
+ "CHANGELOG.markdown",
23
24
  "LICENSE",
24
25
  "README.markdown",
25
26
  "Rakefile",
@@ -28,11 +29,13 @@ Gem::Specification.new do |s|
28
29
  "lib/alchemy_api.rb",
29
30
  "lib/alchemy_api/base.rb",
30
31
  "lib/alchemy_api/categorization.rb",
32
+ "lib/alchemy_api/concept_tagging.rb",
31
33
  "lib/alchemy_api/language_detection.rb",
32
34
  "lib/alchemy_api/term_extraction.rb",
33
35
  "lib/alchemy_api/text_extraction.rb",
34
36
  "spec/alchemy_api/base_spec.rb",
35
37
  "spec/alchemy_api/categorization_spec.rb",
38
+ "spec/alchemy_api/concept_tagging_spec.rb",
36
39
  "spec/alchemy_api/language_detection_spec.rb",
37
40
  "spec/alchemy_api/term_extraction_spec.rb",
38
41
  "spec/alchemy_api/text_extraction_spec.rb",
@@ -40,6 +43,9 @@ Gem::Specification.new do |s|
40
43
  "spec/cache/categorization/get_categorization_from_html/ddc3cf50efe5bd5c2159abfb49121cfa2314ca88.cache",
41
44
  "spec/cache/categorization/get_categorization_from_text/8b476a3b532afd2da646b145e9dde07570c27352.cache",
42
45
  "spec/cache/categorization/get_categorization_from_url/7536a34e1d54a95d8ee07d2a98036362761e1621.cache",
46
+ "spec/cache/concept_tagging/get_concepts_from_html/7da223513abcfe2fd3d253fff60894829f858667.cache",
47
+ "spec/cache/concept_tagging/get_concepts_from_text/3e56901d7f01729b79ef73fc6d34fa97148eb35c.cache",
48
+ "spec/cache/concept_tagging/get_concepts_from_url/488c7dbb9b844b072cb284425b4ca8356b08dd15.cache",
43
49
  "spec/cache/language_detection/get_language_from_html/0faf7be978647b611d9c59e1efa497dd76e542f5.cache",
44
50
  "spec/cache/language_detection/get_language_from_text/1ad3f50c1fda37000e24c196f12212ea9d536cb4.cache",
45
51
  "spec/cache/language_detection/get_language_from_url/d077a95e60be0876bb7650ad213f5f43e83454d4.cache",
@@ -66,6 +72,7 @@ Gem::Specification.new do |s|
66
72
  s.test_files = [
67
73
  "spec/alchemy_api/base_spec.rb",
68
74
  "spec/alchemy_api/categorization_spec.rb",
75
+ "spec/alchemy_api/concept_tagging_spec.rb",
69
76
  "spec/alchemy_api/language_detection_spec.rb",
70
77
  "spec/alchemy_api/term_extraction_spec.rb",
71
78
  "spec/alchemy_api/text_extraction_spec.rb",
@@ -79,13 +86,16 @@ Gem::Specification.new do |s|
79
86
 
80
87
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
81
88
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
89
+ s.add_development_dependency(%q<typhoeus_spec_cache>, [">= 0.2.2"])
82
90
  s.add_runtime_dependency(%q<monster_mash>, [">= 0.1.1"])
83
91
  else
84
92
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
93
+ s.add_dependency(%q<typhoeus_spec_cache>, [">= 0.2.2"])
85
94
  s.add_dependency(%q<monster_mash>, [">= 0.1.1"])
86
95
  end
87
96
  else
88
97
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
98
+ s.add_dependency(%q<typhoeus_spec_cache>, [">= 0.2.2"])
89
99
  s.add_dependency(%q<monster_mash>, [">= 0.1.1"])
90
100
  end
91
101
  end
@@ -26,4 +26,5 @@ module AlchemyApi
26
26
  class PageIsNotValidHtmlError < StandardError; end
27
27
  class ContentExceedsMaxLimitError < StandardError; end
28
28
  class InvalidHtmlError < StandardError; end
29
+ class ContentIsEmptyError < StandardError; end
29
30
  end
@@ -28,6 +28,8 @@ module AlchemyApi
28
28
  raise ContentExceedsMaxLimitError, "The page at #{json['url']} is larger than 600KB!"
29
29
  when 'invalid-html'
30
30
  raise InvalidHtmlError, "The HTML sent was invalid!"
31
+ when 'content-is-empty'
32
+ raise ContentIsEmptyError, "The content you provided was empty!"
31
33
  else
32
34
  raise UnknownError, "Got an unknown error: #{json['statusInfo']}"
33
35
  end
@@ -0,0 +1,60 @@
1
+ # TODO: add support for linkedData return fields
2
+ module AlchemyApi
3
+ ConceptTaggingResult = Struct.new(:concepts, :language, :url, :source_text)
4
+ Concept = Struct.new(:text, :relevance)
5
+
6
+ class ConceptTagging < Base
7
+ # http://www.alchemyapi.com/api/concept/textc.html
8
+ post(:get_concepts_from_text) do |text, *args|
9
+ options = args.first || {}
10
+ uri "#{AlchemyApi.base_text_uri}/TextGetRankedConcepts"
11
+ params :text => text,
12
+ :maxRetrieve => options[:max_retrieve] || 10,
13
+ :linkedData => 0,
14
+ :showSourceText => options[:show_source_text] ? 1 : 0
15
+ handler do |response|
16
+ AlchemyApi::ConceptTagging.get_concepts_handler(response)
17
+ end
18
+ end
19
+
20
+ # http://www.alchemyapi.com/api/concept/urls.html
21
+ post(:get_concepts_from_url) do |url, *args|
22
+ options = args.first || {}
23
+ uri "#{AlchemyApi.base_uri}/URLGetRankedConcepts"
24
+ params :url => url,
25
+ :maxRetrieve => options[:max_retrieve] || 10,
26
+ :linkedData => 0,
27
+ :showSourceText => options[:show_source_text] ? 1 : 0,
28
+ :sourceText => options[:source_text] || 'cleaned_or_raw',
29
+ :cquery => options[:cquery],
30
+ :xpath => options[:xpath]
31
+ handler do |response|
32
+ AlchemyApi::ConceptTagging.get_concepts_handler(response)
33
+ end
34
+ end
35
+
36
+ # http://www.alchemyapi.com/api/concept/htmlc.html
37
+ post(:get_concepts_from_html) do |html, *args|
38
+ options = args.first || {}
39
+ uri "#{AlchemyApi.base_html_uri}/HTMLGetRankedConcepts"
40
+ params :html => html,
41
+ :maxRetrieve => options[:max_retrieve] || 10,
42
+ :linkedData => 0,
43
+ :showSourceText => options[:show_source_text] ? 1 : 0,
44
+ :sourceText => options[:source_text] || 'cleaned_or_raw',
45
+ :cquery => options[:cquery],
46
+ :xpath => options[:xpath]
47
+ handler do |response|
48
+ AlchemyApi::ConceptTagging.get_concepts_handler(response)
49
+ end
50
+ end
51
+
52
+ def self.get_concepts_handler(response)
53
+ json = get_json(response)
54
+ concepts = json['concepts'].map do |c|
55
+ Concept.new(c['text'], c['relevance'].to_f)
56
+ end
57
+ ConceptTaggingResult.new(concepts, json['language'], json['url'], json['text'])
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe AlchemyApi::ConceptTagging do
4
+ typhoeus_spec_cache('spec/cache/concept_tagging/get_concepts_from_text') do |hydra|
5
+ describe "#get_concepts_from_text" do
6
+ before(:each) do
7
+ @url = "http://test.com"
8
+ text = fixture_for('article.txt')
9
+
10
+ @results = AlchemyApi::ConceptTagging.
11
+ get_concepts_from_text(text)
12
+ end
13
+
14
+ it "should return at least one concept" do
15
+ @results.concepts.should_not be_empty
16
+ end
17
+ end
18
+ end
19
+
20
+ typhoeus_spec_cache('spec/cache/concept_tagging/get_concepts_from_url') do |hydra|
21
+ describe "#get_concepts_from_url" do
22
+ before(:each) do
23
+ @url = 'http://www.macrumors.com/2010/04/30/apples-discontinuation-of-lala-streaming-music-service-not-likely-leading-to-imminent-launch-of-web-focused-itunes/'
24
+ @results = AlchemyApi::ConceptTagging.
25
+ get_concepts_from_url(@url,
26
+ :source_text => 'cleaned_or_raw')
27
+ end
28
+
29
+ it "should return at least one concept" do
30
+ @results.concepts.should_not be_empty
31
+ end
32
+ end
33
+ end
34
+
35
+ typhoeus_spec_cache('spec/cache/concept_tagging/get_concepts_from_html') do |hydra|
36
+ describe "#get_concepts_from_html" do
37
+ before(:each) do
38
+ @url = "http://www.businessweek.com/news/2010-04-29/bp-spill-may-alter-obama-s-offshore-drilling-plans-update1-.html"
39
+ @html = fixture_for('bp_spill.html')
40
+ @results = AlchemyApi::ConceptTagging.
41
+ get_concepts_from_html(@html, :url => @url,
42
+ :source_text => 'cleaned_or_raw')
43
+ end
44
+
45
+ it "should return at least one concept" do
46
+ @results.concepts.should_not be_empty
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,61 @@
1
+ u:Typhoeus::Response�---
2
+ :requested_http_method:
3
+ :headers: |
4
+ HTTP/1.1 100 Continue
5
+
6
+ HTTP/1.1 200 OK
7
+ Server: nginx
8
+ Date: Sat, 11 Sep 2010 03:55:18 GMT
9
+ Content-Type: application/json
10
+ Transfer-Encoding: chunked
11
+ Connection: keep-alive
12
+ Cache-Control: no-cache
13
+ Content-Encoding: gzip
14
+
15
+
16
+ :requested_url:
17
+ :body: |
18
+ {
19
+ "status": "OK",
20
+ "usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html",
21
+ "url": "",
22
+ "language": "english",
23
+ "concepts": [
24
+ {
25
+ "text": "Robert Gibbs",
26
+ "relevance": "0.958553"
27
+ },
28
+ {
29
+ "text": "Bobby Jindal",
30
+ "relevance": "0.856261"
31
+ },
32
+ {
33
+ "text": "Barack Obama",
34
+ "relevance": "0.854173"
35
+ },
36
+ {
37
+ "text": "White House Press Secretary",
38
+ "relevance": "0.820978"
39
+ },
40
+ {
41
+ "text": "Petroleum",
42
+ "relevance": "0.702847"
43
+ },
44
+ {
45
+ "text": "Ken Salazar",
46
+ "relevance": "0.66043"
47
+ },
48
+ {
49
+ "text": "ExxonMobil",
50
+ "relevance": "0.621805"
51
+ },
52
+ {
53
+ "text": "Gulf of Mexico",
54
+ "relevance": "0.590221"
55
+ }
56
+ ]
57
+ }
58
+
59
+ :code: 200
60
+ :start_time:
61
+ :time: 2.276884
@@ -0,0 +1,48 @@
1
+ u:Typhoeus::Responses---
2
+ :requested_http_method:
3
+ :body: |
4
+ {
5
+ "status": "OK",
6
+ "usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html",
7
+ "url": "",
8
+ "language": "english",
9
+ "concepts": [
10
+ {
11
+ "text": "Bed and breakfast",
12
+ "relevance": "0.961337"
13
+ },
14
+ {
15
+ "text": "Hotel",
16
+ "relevance": "0.59768"
17
+ },
18
+ {
19
+ "text": "Breakfast",
20
+ "relevance": "0.536192"
21
+ },
22
+ {
23
+ "text": "Inn",
24
+ "relevance": "0.535763"
25
+ },
26
+ {
27
+ "text": "Lodging",
28
+ "relevance": "0.511123"
29
+ }
30
+ ]
31
+ }
32
+
33
+ :requested_url:
34
+ :start_time:
35
+ :code: 200
36
+ :time: 0.429581
37
+ :headers: |
38
+ HTTP/1.1 100 Continue
39
+
40
+ HTTP/1.1 200 OK
41
+ Server: nginx
42
+ Date: Sat, 11 Sep 2010 03:54:47 GMT
43
+ Content-Type: application/json
44
+ Connection: keep-alive
45
+ Content-Length: 754
46
+ Cache-Control: no-cache
47
+
48
+
@@ -0,0 +1,46 @@
1
+ u:Typhoeus::Response�---
2
+ :requested_http_method:
3
+ :headers: |
4
+ HTTP/1.1 200 OK
5
+ Server: nginx
6
+ Date: Sat, 11 Sep 2010 03:55:16 GMT
7
+ Content-Type: application/json
8
+ Connection: keep-alive
9
+ Content-Length: 921
10
+ Cache-Control: no-cache
11
+
12
+
13
+ :requested_url:
14
+ :body: |
15
+ {
16
+ "status": "OK",
17
+ "usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html",
18
+ "url": "http://www.macrumors.com/2010/04/30/apples-discontinuation-of-lala-streaming-music-service-not-likely-leading-to-imminent-launch-of-web-focused-itunes/",
19
+ "language": "english",
20
+ "concepts": [
21
+ {
22
+ "text": "EMI",
23
+ "relevance": "0.926603"
24
+ },
25
+ {
26
+ "text": "Record label",
27
+ "relevance": "0.917238"
28
+ },
29
+ {
30
+ "text": "Music industry",
31
+ "relevance": "0.754385"
32
+ },
33
+ {
34
+ "text": "ITunes Store",
35
+ "relevance": "0.734244"
36
+ },
37
+ {
38
+ "text": "Streaming media",
39
+ "relevance": "0.655383"
40
+ }
41
+ ]
42
+ }
43
+
44
+ :code: 200
45
+ :start_time:
46
+ :time: 0.313919
@@ -4,6 +4,8 @@ require 'alchemy_api'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
6
 
7
+ AlchemyApi.api_key = '3468d2194732163c69b0ac76079ca9f9c4193226'
8
+
7
9
  require 'typhoeus_spec_cache'
8
10
 
9
11
  Spec::Runner.configure do |config|
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Balatero
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-17 00:00:00 -07:00
17
+ date: 2010-09-12 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -32,9 +32,23 @@ dependencies:
32
32
  type: :development
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: monster_mash
35
+ name: typhoeus_spec_cache
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 2
44
+ - 2
45
+ version: 0.2.2
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: monster_mash
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - ">="
40
54
  - !ruby/object:Gem::Version
@@ -44,7 +58,7 @@ dependencies:
44
58
  - 1
45
59
  version: 0.1.1
46
60
  type: :runtime
47
- version_requirements: *id002
61
+ version_requirements: *id003
48
62
  description: Provides a client API library for AlchemyAPI's awesome NLP services. Allows you to make parallel or serial requests.
49
63
  email: dbalatero@gmail.com
50
64
  executables: []
@@ -58,6 +72,7 @@ extra_rdoc_files:
58
72
  files:
59
73
  - .document
60
74
  - .gitignore
75
+ - CHANGELOG.markdown
61
76
  - LICENSE
62
77
  - README.markdown
63
78
  - Rakefile
@@ -66,11 +81,13 @@ files:
66
81
  - lib/alchemy_api.rb
67
82
  - lib/alchemy_api/base.rb
68
83
  - lib/alchemy_api/categorization.rb
84
+ - lib/alchemy_api/concept_tagging.rb
69
85
  - lib/alchemy_api/language_detection.rb
70
86
  - lib/alchemy_api/term_extraction.rb
71
87
  - lib/alchemy_api/text_extraction.rb
72
88
  - spec/alchemy_api/base_spec.rb
73
89
  - spec/alchemy_api/categorization_spec.rb
90
+ - spec/alchemy_api/concept_tagging_spec.rb
74
91
  - spec/alchemy_api/language_detection_spec.rb
75
92
  - spec/alchemy_api/term_extraction_spec.rb
76
93
  - spec/alchemy_api/text_extraction_spec.rb
@@ -78,6 +95,9 @@ files:
78
95
  - spec/cache/categorization/get_categorization_from_html/ddc3cf50efe5bd5c2159abfb49121cfa2314ca88.cache
79
96
  - spec/cache/categorization/get_categorization_from_text/8b476a3b532afd2da646b145e9dde07570c27352.cache
80
97
  - spec/cache/categorization/get_categorization_from_url/7536a34e1d54a95d8ee07d2a98036362761e1621.cache
98
+ - spec/cache/concept_tagging/get_concepts_from_html/7da223513abcfe2fd3d253fff60894829f858667.cache
99
+ - spec/cache/concept_tagging/get_concepts_from_text/3e56901d7f01729b79ef73fc6d34fa97148eb35c.cache
100
+ - spec/cache/concept_tagging/get_concepts_from_url/488c7dbb9b844b072cb284425b4ca8356b08dd15.cache
81
101
  - spec/cache/language_detection/get_language_from_html/0faf7be978647b611d9c59e1efa497dd76e542f5.cache
82
102
  - spec/cache/language_detection/get_language_from_text/1ad3f50c1fda37000e24c196f12212ea9d536cb4.cache
83
103
  - spec/cache/language_detection/get_language_from_url/d077a95e60be0876bb7650ad213f5f43e83454d4.cache
@@ -129,6 +149,7 @@ summary: Provides a client API library for AlchemyAPI's awesome NLP services. Al
129
149
  test_files:
130
150
  - spec/alchemy_api/base_spec.rb
131
151
  - spec/alchemy_api/categorization_spec.rb
152
+ - spec/alchemy_api/concept_tagging_spec.rb
132
153
  - spec/alchemy_api/language_detection_spec.rb
133
154
  - spec/alchemy_api/term_extraction_spec.rb
134
155
  - spec/alchemy_api/text_extraction_spec.rb