textalytics 0.0.4
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 +15 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +1 -0
- data/lib/textalytics.rb +22 -0
- data/lib/textalytics/api.rb +11 -0
- data/lib/textalytics/api/base.rb +60 -0
- data/lib/textalytics/api/entities/classification_entity.rb +42 -0
- data/lib/textalytics/api/entities/language_entity.rb +17 -0
- data/lib/textalytics/api/entities/sentiment_entity.rb +59 -0
- data/lib/textalytics/api/entities/topics_entity.rb +54 -0
- data/lib/textalytics/client.rb +26 -0
- data/lib/textalytics/errors.rb +44 -0
- data/lib/textalytics/helpers.rb +11 -0
- data/lib/textalytics/helpers/request.rb +63 -0
- data/lib/textalytics/version.rb +6 -0
- data/spec/cases/api_spec.rb +29 -0
- data/spec/spec_helper.rb +13 -0
- data/textalytics.gemspec +27 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzczMmViYTA0NmVkZDc1ZTAxNDdhODQ0MmQ2MzRmMWMxMTU3MjU0Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDM2N2Q5YWYxOTRjMTQ0MmNmMGJmZThjZmZjZjU2ZTFjZWFhZGNhNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MGQzNWNjZDk0YjJhODE4NmRiNDYxNTU1Y2I5ZWZjYTA5YTZjM2EwZmNiMzM0
|
10
|
+
MTVkZjJiNzdlOTc4NmViZjkyNTQ5ZWI5N2Q3YjA5OTVkMjlkZTU4MGE0M2Rl
|
11
|
+
MGFmN2ViMWEyZjNiYjNjM2YwZjliMTRhNzQyODFjYmM1ODI1YWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDYzMTk0YjRkZDg2YWQ5YjkyZDVmNjZiMTk3ZmVkZWEzMzI5ZWMyMmI4MDg5
|
14
|
+
MWYwYTczNjdlZTJiZDI1ZDgyMGU2YmI2MzBkYzhmNzFkYjlkYjBjZGZlNTA3
|
15
|
+
ZTQ0NjUwNGRhZDg4NzYzODFmZDY0NWE3ZjU0NDAyZGZmMmJiNDQ=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
0.04
|
2
|
+
---
|
3
|
+
|
4
|
+
* Solving dependency issue
|
5
|
+
|
6
|
+
0.03
|
7
|
+
---
|
8
|
+
|
9
|
+
* First functional version
|
10
|
+
* Support for Language Identification API
|
11
|
+
|
12
|
+
0.02
|
13
|
+
---
|
14
|
+
|
15
|
+
* Some improvements, but still not functional
|
16
|
+
|
17
|
+
0.01
|
18
|
+
---
|
19
|
+
|
20
|
+
* First commit. A little rushed because it is my first public gem
|
21
|
+
* Gem first structure, classes and modules
|
22
|
+
|
23
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gerardo Ortega
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Textalytics
|
2
|
+
|
3
|
+
Ruby wrapper for the [Textalytics APIs](https://textalytics.com/api-core-language-analysis). The Textalytics gem provides an easy-to-use wrapper for Textalytics's REST APIs.
|
4
|
+
|
5
|
+
## Use
|
6
|
+
|
7
|
+
You have two options when creating a new client. Create environment variables for each API key:
|
8
|
+
|
9
|
+
export SENTIMENT_KEY=<your key>
|
10
|
+
export CLASSIFICATION_KEY=<...>
|
11
|
+
export LANGUAGE_KEY=<...>
|
12
|
+
export TOPICS_KEY=<...>
|
13
|
+
|
14
|
+
t = Textalytics::Client.new
|
15
|
+
|
16
|
+
Otherwise you have to pass the keys as arguments:
|
17
|
+
|
18
|
+
t = Textalytics::Client.new(sentiment: "insert your sentiment API key", classification: "insert your classification API key", topics: "...")
|
19
|
+
|
20
|
+
|
21
|
+
#### Using Sentiment API
|
22
|
+
|
23
|
+
# You can read about the parameters that you can send in the request here
|
24
|
+
# https://textalytics.com/core/sentiment-info#doc
|
25
|
+
|
26
|
+
movie_sentiment = t.sentiment(txt: 'The movie was terrible, never see a movie of that director. Even the actors are bad.', model: 'en-general')
|
27
|
+
movie_sentiment.score_tag
|
28
|
+
movie_sentiment.sd_tag #etc, etc...
|
29
|
+
|
30
|
+
#### Using Text Classification API
|
31
|
+
|
32
|
+
# You can read about the parameters that you can send in the request here
|
33
|
+
# https://textalytics.com/core/class-info#doc
|
34
|
+
|
35
|
+
title = 'Computer'
|
36
|
+
text = <<PARAGRAPH
|
37
|
+
A computer is a general purpose device that can be programmed to carry out
|
38
|
+
a set of arithmetic or logical operations automatically. Since a sequence of
|
39
|
+
operations can be readily changed, the computer can solve more than one kind of
|
40
|
+
problem.
|
41
|
+
|
42
|
+
Conventionally, a computer consists of at least one processing element, typically
|
43
|
+
a central processing unit (CPU), and some form of memory. The processing element
|
44
|
+
carries out arithmetic and logic operations, and a sequencing and control unit can
|
45
|
+
change the order of operations in response to stored information. Peripheral devices
|
46
|
+
allow information to be retrieved from an external source, and the result of operations
|
47
|
+
saved and retrieved.
|
48
|
+
PARAGRAPH
|
49
|
+
|
50
|
+
t = Textalytics::Client.new
|
51
|
+
#Model and other parameters can be found in the documentation page of the API
|
52
|
+
classification = t.classification(title: title, txt: text, model: 'IPTC_en')
|
53
|
+
classification.categories #etc
|
54
|
+
|
55
|
+
#### Using Topics Extraction API
|
56
|
+
|
57
|
+
# You can read about the parameters that you can send in the request here
|
58
|
+
# https://textalytics.com/core/topics-info#doc
|
59
|
+
|
60
|
+
t = Textalytics::Client.new
|
61
|
+
|
62
|
+
topics = t.topics(txt: "A computer is a general purpose device that can be programmed to carry out a set of arithmetic or logical operations automatically. Since a sequence of operations can be readily changed, the computer can solve more than one kind of problem.",
|
63
|
+
lang: 'en', tt: 'ectmu')
|
64
|
+
|
65
|
+
topics.concepts
|
66
|
+
topics.entities
|
67
|
+
topics.time_expressions
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
#### Using Language Identification API
|
72
|
+
|
73
|
+
# You can read about the parameters that you can send in the request here
|
74
|
+
# https://textalytics.com/core/lang-info#doc
|
75
|
+
|
76
|
+
t = Textalytics::Client.new
|
77
|
+
|
78
|
+
lang = t.language_list(txt: 'A computer is a general purpose device that can be programmed')
|
79
|
+
lang.first
|
80
|
+
|
81
|
+
TODO: Add some examples
|
82
|
+
|
83
|
+
|
84
|
+
## Installation
|
85
|
+
|
86
|
+
Add this line to your application's Gemfile:
|
87
|
+
|
88
|
+
gem 'textalytics'
|
89
|
+
|
90
|
+
And then execute:
|
91
|
+
|
92
|
+
$ bundle
|
93
|
+
|
94
|
+
Or install it yourself as:
|
95
|
+
|
96
|
+
$ gem install textalytics
|
97
|
+
|
98
|
+
## TODO
|
99
|
+
|
100
|
+
* Write more tests
|
101
|
+
* Write a better documentation
|
102
|
+
|
103
|
+
## Usage
|
104
|
+
|
105
|
+
TODO: Write usage instructions here
|
106
|
+
|
107
|
+
## Contributing
|
108
|
+
|
109
|
+
1. Fork it ( http://github.com/<my-github-username>/textalytics/fork )
|
110
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
111
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
112
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
113
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/textalytics.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# require "textalytics/version"
|
2
|
+
# require "textalytics/client"
|
3
|
+
|
4
|
+
module Textalytics
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
|
9
|
+
def configure
|
10
|
+
yield self
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
autoload :Api, "textalytics/api"
|
17
|
+
autoload :Client, "textalytics/client"
|
18
|
+
autoload :Errors, "textalytics/errors"
|
19
|
+
autoload :Helpers, "textalytics/helpers"
|
20
|
+
autoload :Version, "textalytics/version"
|
21
|
+
autoload :Errors, "textalytics/errors"
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Textalytics
|
2
|
+
module Api
|
3
|
+
|
4
|
+
autoload :Base, "textalytics/api/base"
|
5
|
+
autoload :QueryHelpers, "textalytics/api/query_helpers"
|
6
|
+
autoload :ClassificationEntity, "textalytics/api/entities/classification_entity"
|
7
|
+
autoload :SentimentEntity, "textalytics/api/entities/sentiment_entity"
|
8
|
+
autoload :TopicsEntity, "textalytics/api/entities/topics_entity"
|
9
|
+
autoload :LanguageEntity, "textalytics/api/entities/language_entity"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Textalytics
|
2
|
+
module Api
|
3
|
+
module Base
|
4
|
+
|
5
|
+
include Textalytics::Api::ClassificationEntity
|
6
|
+
include Textalytics::Api::SentimentEntity
|
7
|
+
include Textalytics::Api::TopicsEntity
|
8
|
+
include Textalytics::Api::LanguageEntity
|
9
|
+
include Textalytics::Helpers
|
10
|
+
|
11
|
+
|
12
|
+
# Classification API
|
13
|
+
# @see https://textalytics.com/core/class-info Text Classification API documentation
|
14
|
+
def classification(options={})
|
15
|
+
options[:key] = @classification_key
|
16
|
+
options[:of] = 'json'
|
17
|
+
query = { query: options}
|
18
|
+
response = get(CLASSIFICATION, query)
|
19
|
+
Classification.new(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Sentiment API
|
24
|
+
# @see https://textalytics.com/core/sentiment-info Sentiment Analysis API documentation
|
25
|
+
def sentiment(options = {})
|
26
|
+
options[:key] = @sentiment_key
|
27
|
+
options[:of] = 'json'
|
28
|
+
query = { query: options}
|
29
|
+
response = get(SENTIMENT, query)
|
30
|
+
Sentiment.new(response)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Topics Extraction API
|
34
|
+
# @see https://textalytics.com/core/topics-info Topics Extraction API documentation
|
35
|
+
def topics(options = {})
|
36
|
+
options[:key] = @topics_key
|
37
|
+
options[:of] = 'json'
|
38
|
+
|
39
|
+
unless options.has_key?(:tt)
|
40
|
+
options[:tt] = 'a'
|
41
|
+
end
|
42
|
+
|
43
|
+
query = { query: options}
|
44
|
+
response = get(TOPICS, query)
|
45
|
+
Topics.new(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Language Identification API
|
49
|
+
# @see https://textalytics.com/core/lang-info#doc
|
50
|
+
def language(options = {})
|
51
|
+
options[:key] = @language_key
|
52
|
+
options[:of] = 'json'
|
53
|
+
query = { query: options}
|
54
|
+
response = get(LANGUAGE, query)
|
55
|
+
Language.new(response)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Textalytics
|
2
|
+
module Api
|
3
|
+
module ClassificationEntity
|
4
|
+
|
5
|
+
class Classification
|
6
|
+
attr_reader :category_list, :categories, :all
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@category_list = response["category_list"]
|
10
|
+
@all = response
|
11
|
+
end
|
12
|
+
|
13
|
+
def categories
|
14
|
+
category_array = []
|
15
|
+
|
16
|
+
@category_list.each do |c|
|
17
|
+
cat = Category.new(code: c["code"], label: c["label"], abs_relevance: c["abs_relevance"], relevance: c["relevance"], term_list: c["term_list"] )
|
18
|
+
category_array << cat
|
19
|
+
end
|
20
|
+
|
21
|
+
category_array
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
class Category
|
28
|
+
attr_reader :code, :label, :abs_relevance, :relevance, :term_list
|
29
|
+
|
30
|
+
def initialize(args)
|
31
|
+
@code = args[:code]
|
32
|
+
@label = args[:label]
|
33
|
+
@abs_relevance = args[:abs_relevance]
|
34
|
+
@relevance = args[:relevance]
|
35
|
+
@term_list = term_list
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Textalytics
|
2
|
+
|
3
|
+
module Api
|
4
|
+
|
5
|
+
module SentimentEntity
|
6
|
+
|
7
|
+
class Sentiment
|
8
|
+
attr_reader :subjectivity, :irony, :score,
|
9
|
+
:score_tag, :sd, :sd_tag, :segment_list,
|
10
|
+
:entity_list, :concept_list, :all
|
11
|
+
|
12
|
+
def initialize(response)
|
13
|
+
@all = response
|
14
|
+
end
|
15
|
+
|
16
|
+
def subjectivity
|
17
|
+
@all["subjectivity"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def irony
|
21
|
+
@all["ironi"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def score
|
25
|
+
@all["score"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def score_tag
|
29
|
+
@all["score_tag"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def sd
|
33
|
+
@all["sd"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def sd_tag
|
37
|
+
@all["sd_tag"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def segment_list
|
41
|
+
@all["segment_list"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def entity_list
|
45
|
+
@all["entity_list"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def concept_list
|
49
|
+
@all["concept_list"]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Textalytics
|
2
|
+
module Api
|
3
|
+
module TopicsEntity
|
4
|
+
class Topics
|
5
|
+
attr_reader :entities, :concepts, :time_expressions, :money_expressions,
|
6
|
+
:uris, :phone_expressions, :other_expressions, :quotations,
|
7
|
+
:relations, :all
|
8
|
+
|
9
|
+
def initialize(response)
|
10
|
+
@all = response
|
11
|
+
end
|
12
|
+
|
13
|
+
def entities
|
14
|
+
@all["entity_list"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def concepts
|
18
|
+
@all["concept_list"]
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def time_expressions
|
23
|
+
@all["time_expression_list"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def money_expressions
|
27
|
+
@all["money_expression_list"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def uris
|
31
|
+
@all["uri_list"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def phone_expressions
|
35
|
+
@all["phone_expression_list"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def other_expressions
|
39
|
+
@all["other_expression_list"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def quotations
|
43
|
+
@all["quotation_list"]
|
44
|
+
end
|
45
|
+
|
46
|
+
def relations
|
47
|
+
@all["relation_list"]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Textalytics
|
2
|
+
|
3
|
+
class Client
|
4
|
+
include Helpers::Request
|
5
|
+
include Api::ClassificationEntity
|
6
|
+
include Api::SentimentEntity
|
7
|
+
include Api::LanguageEntity
|
8
|
+
include Api::Base
|
9
|
+
include HTTParty
|
10
|
+
|
11
|
+
base_uri 'https://textalytics.com/core'
|
12
|
+
|
13
|
+
|
14
|
+
attr_reader :sentiment_key, :topics_key, :classification_key, :language_key
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@sentiment_key = options[:sentiment] || ENV['SENTIMENT_KEY']
|
18
|
+
@topics_key = options[:topics] || ENV['TOPICS_KEY']
|
19
|
+
@classification_key = options[:classification] || ENV['CLASSIFICATION_KEY']
|
20
|
+
@language_key = options[:language] || ENV['LANGUAGE_KEY']
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Textalytics
|
2
|
+
module Errors
|
3
|
+
class TextalyticError < StandardError
|
4
|
+
attr_reader :data
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Raised when a 100 code error is received
|
12
|
+
# 100: Operation denied
|
13
|
+
class OperationDeniedError < TextalyticError; end
|
14
|
+
|
15
|
+
# Raised when a 101 code is received
|
16
|
+
# 101: The license has expired
|
17
|
+
class LicenseExpiredError < TextalyticError; end
|
18
|
+
|
19
|
+
# Raised when a 102 code is received
|
20
|
+
# 102: You have exceeded the maximum number of credits per month
|
21
|
+
class MaximumNumberMonthError < TextalyticError; end
|
22
|
+
|
23
|
+
# Raised when a 103 code is received
|
24
|
+
# 103: You have exceeded the maximum number of credits per request
|
25
|
+
class MaximumNumberRequestError < TextalyticError; end
|
26
|
+
|
27
|
+
# Raised when a 104 code is received
|
28
|
+
# 104: You have exceeded the maximum number of requests per second
|
29
|
+
class MaximumNumberSecondError < TextalyticError; end
|
30
|
+
|
31
|
+
# Raised when a 200 code is received
|
32
|
+
# 200: A required parameter is missing
|
33
|
+
class ParameterMissingError < StandardError; end
|
34
|
+
|
35
|
+
# Raised when a 201 code is received
|
36
|
+
# 201: Model not supported
|
37
|
+
class ModelNotSupportedError < StandardError; end
|
38
|
+
|
39
|
+
# Raised when a 202 code is received
|
40
|
+
# 202: No suitable model for the identified text language
|
41
|
+
class NotSuitableModelError < StandardError; end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Textalytics
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
module Request
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def get(path, options={})
|
11
|
+
response = self.class.get(path, options)
|
12
|
+
raise_errors(response)
|
13
|
+
response.to_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
def post(path, body='', options={})
|
17
|
+
response = self.class.post(path, options)
|
18
|
+
raise_errors(response)
|
19
|
+
response.to_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
|
25
|
+
def raise_errors(response)
|
26
|
+
# You can see the errors with their description at
|
27
|
+
# https://textalytics.com/core/sentiment-info
|
28
|
+
# https://textalytics.com/core/class-info
|
29
|
+
# https://textalytics.com/core/topics-info
|
30
|
+
# In status section
|
31
|
+
|
32
|
+
case response["status"]["code"].to_i
|
33
|
+
when 100
|
34
|
+
data = response["status"]
|
35
|
+
raise Textalytics::Errors::OperationDeniedError.new(data), "(#{data["code"]}): #{data["msg"]}"
|
36
|
+
when 101
|
37
|
+
data = response["status"]
|
38
|
+
raise Textalytics::Errors::LicenseExpiredError.new(data), "(#{data["code"]}): #{data["msg"]}"
|
39
|
+
when 102
|
40
|
+
data = response["status"]
|
41
|
+
raise Textalytics::Errors::MaximumNumberMonthError.new(data), "(#{data["code"]}): #{data["msg"]}"
|
42
|
+
when 103
|
43
|
+
data = response["status"]
|
44
|
+
raise Textalytics::Errors::MaximumNumberRequestError.new(data), "(#{data["code"]}): #{data["msg"]}"
|
45
|
+
when 104
|
46
|
+
data = response["status"]
|
47
|
+
raise Textalytics::Errors::MaximumNumberSecondError.new(data), "(#{data["code"]}): #{data["msg"]}"
|
48
|
+
when 200
|
49
|
+
data = response["status"]
|
50
|
+
raise Textalytics::Errors::ParameterMissingError.new(data), "(#{data["code"]}): #{data["msg"]}"
|
51
|
+
when 201
|
52
|
+
data = response["status"]
|
53
|
+
raise Textalytics::Errors::ModelNotSupportedError.new(data), "(#{data["code"]}): #{data["msg"]}"
|
54
|
+
when 202
|
55
|
+
data = response["status"]
|
56
|
+
raise Textalytics::Errors::NotSuitableModelError.new(data), "(#{data["code"]}): #{data["msg"]}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Textalytics::Client do
|
4
|
+
|
5
|
+
it "should initialize the api keys from environment variables" do
|
6
|
+
client = Textalytics::Client.new
|
7
|
+
client.language_key.should_not be_nil
|
8
|
+
client.classification_key.should_not be_nil
|
9
|
+
client.sentiment_key.should_not be_nil
|
10
|
+
client.topics_key.should_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not initialize any api keys from environment variables" do
|
14
|
+
ENV.delete('SENTIMENT_KEY')
|
15
|
+
ENV.delete('TOPICS_KEY')
|
16
|
+
ENV.delete('CLASSIFICATION_KEY')
|
17
|
+
ENV.delete('LANGUAGE_KEY')
|
18
|
+
|
19
|
+
new_client = Textalytics::Client.new
|
20
|
+
new_client.sentiment_key.should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should change the default environment values when arguments are provided" do
|
24
|
+
ENV['SENTIMENT_KEY'] = '87654321'
|
25
|
+
client = Textalytics::Client.new(sentiment: '12345678')
|
26
|
+
expect(client.sentiment_key).to eq('12345678')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'textalytics'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
|
+
config.run_all_when_everything_filtered = true
|
6
|
+
config.filter_run :focus
|
7
|
+
|
8
|
+
# Run specs in random order to surface order dependencies. If you find an
|
9
|
+
# order dependency and want to debug it, you can fix the order by providing
|
10
|
+
# the seed, which is printed after each run.
|
11
|
+
# --seed 1234
|
12
|
+
config.order = 'random'
|
13
|
+
end
|
data/textalytics.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'textalytics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "textalytics"
|
8
|
+
spec.version = Textalytics::VERSION
|
9
|
+
spec.authors = ["Gerardo Ortega"]
|
10
|
+
spec.email = ["geraldavid7@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper the Textalytics API}
|
12
|
+
spec.description = %q{This gem pretends to make easier the process of text analysis through the Textalytics APIs}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.add_dependency 'httparty', '~> 0.12'
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.3.1'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.14.1'
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: textalytics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerardo Ortega
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.3.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.14.1
|
69
|
+
description: This gem pretends to make easier the process of text analysis through
|
70
|
+
the Textalytics APIs
|
71
|
+
email:
|
72
|
+
- geraldavid7@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- lib/textalytics.rb
|
85
|
+
- lib/textalytics/api.rb
|
86
|
+
- lib/textalytics/api/base.rb
|
87
|
+
- lib/textalytics/api/entities/classification_entity.rb
|
88
|
+
- lib/textalytics/api/entities/language_entity.rb
|
89
|
+
- lib/textalytics/api/entities/sentiment_entity.rb
|
90
|
+
- lib/textalytics/api/entities/topics_entity.rb
|
91
|
+
- lib/textalytics/client.rb
|
92
|
+
- lib/textalytics/errors.rb
|
93
|
+
- lib/textalytics/helpers.rb
|
94
|
+
- lib/textalytics/helpers/request.rb
|
95
|
+
- lib/textalytics/version.rb
|
96
|
+
- spec/cases/api_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- textalytics.gemspec
|
99
|
+
homepage: ''
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Ruby wrapper the Textalytics API
|
123
|
+
test_files:
|
124
|
+
- spec/cases/api_spec.rb
|
125
|
+
- spec/spec_helper.rb
|