Class: AylienTextApi::Client
- Inherits:
-
Object
- Object
- AylienTextApi::Client
- Defined in:
- lib/aylien_text_api/client.rb
Overview
The Client class is the main class for calling Text API endpoints
Instance Method Summary collapse
-
#aspect_based_sentiment(value = nil, params = {}) ⇒ Hash?
Detects aspects and sentiment of a body of text.
-
#aspect_based_sentiment!(value = nil, params = {}) ⇒ Object
Same as aspect_based_sentiment, but calls request! so an exception is raised if the request fails.
-
#classify(value = nil, params = {}) ⇒ Hash?
Classifies a piece of text according to IPTC NewsCode standard.
-
#classify!(value = nil, params = {}) ⇒ Object
Same as classify, but calls request! so an exception is raised if the request fails.
-
#classify_by_taxonomy(value = nil, params = {}) ⇒ Hash?
Classifies a piece of text according to the specified taxonomy.
-
#classify_by_taxonomy!(value = nil, params = {}) ⇒ Object
Same as classify_by_taxonomy, but calls request! so an exception is raised if the request fails.
-
#combined(value = nil, params = {}) ⇒ Hash?
Runs multiple analysis operations in one API call.
-
#combined!(value = nil, params = {}) ⇒ Object
Same as combined, but calls request! so an exception is raised if the request fails.
-
#concepts(value = nil, params = {}) ⇒ Hash?
Extracts named entities mentioned in a document, disambiguates and cross-links them to DBPedia and Linked Data entities, along with their semantic types (including DBPedia and schema.org).
-
#concepts!(value = nil, params = {}) ⇒ Object
Same as concepts, but calls request! so an exception is raised if the request fails.
-
#elsa(value = nil, params = {}) ⇒ Hash?
Extracts named entities (people, organizations and locations) and applies a sentiment analysis to them.
-
#elsa!(value = nil, params = {}) ⇒ Object
Same as elsa, but calls request! so an exception is raised if the request fails.
-
#entities(value = nil, params = {}) ⇒ Hash?
Extracts named entities (people, organizations and locations) and values (URLs, emails, telephone numbers, currency amounts and percentages) mentioned in a body of text.
-
#entities!(value = nil, params = {}) ⇒ Object
Same as entities, but calls request! so an exception is raised if the request fails.
-
#extract(value = nil, params = {}) ⇒ Hash?
Extracts the main body of article, including embedded media such as images & videos from a URL and removes all the surrounding clutter.
-
#extract!(value = nil, params = {}) ⇒ Object
Same as extract, but calls request! so an exception is raised if the request fails.
-
#hashtags(value = nil, params = {}) ⇒ Hash?
Suggests hashtags describing the document.
-
#hashtags!(value = nil, params = {}) ⇒ Object
Same as hashtags, but calls request! so an exception is raised if the request fails.
-
#image_tags(value = nil, params = {}) ⇒ Hash?
Assigns relevant tags to an image.
-
#image_tags!(value = nil, params = {}) ⇒ Object
Same as image_tags, but calls request! so an exception is raised if the request fails.
-
#initialize(options = {}) ⇒ Client
constructor
Creates a Client object.
-
#language(value = nil, params = {}) ⇒ Hash?
Detects the main language a document is written in and returns it in ISO 639-1 format.
-
#language!(value = nil, params = {}) ⇒ Object
Same as language, but calls request! so an exception is raised if the request fails.
-
#rate_limits ⇒ Hash?
Returns current client’s rate limit values.
-
#sentiment(value = nil, params = {}) ⇒ Hash?
Detects sentiment of a document in terms of polarity (“positive” or “negative”) and subjectivity (“subjective” or “objective”).
-
#sentiment!(value = nil, params = {}) ⇒ Object
Same as sentiment, but calls request! so an exception is raised if the request fails.
-
#summarize(value = nil, params = {}) ⇒ Hash?
Summarizes an article into a few key sentences.
-
#summarize!(value = nil, params = {}) ⇒ Object
Same as summarize, but calls request! so an exception is raised if the request fails.
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a Client object.
29 30 31 32 33 34 35 |
# File 'lib/aylien_text_api/client.rb', line 29 def initialize(={}) = AylienTextApi..merge() Configuration::VALID_CONFIG_KEYS.each do |key| send("#{key}=", [key]) end end |
Instance Method Details
#aspect_based_sentiment(value = nil, params = {}) ⇒ Hash?
Detects aspects and sentiment of a body of text. Given a review for a product or service, analyzes the sentiment of the review towards each of the aspects of the product or review that are mentioned in it.
426 427 428 429 430 431 |
# File 'lib/aylien_text_api/client.rb', line 426 def aspect_based_sentiment(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:absa]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#aspect_based_sentiment!(value = nil, params = {}) ⇒ Object
Same as aspect_based_sentiment, but calls request! so an exception is raised if the request fails.
436 437 438 439 440 441 |
# File 'lib/aylien_text_api/client.rb', line 436 def aspect_based_sentiment!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:absa]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#classify(value = nil, params = {}) ⇒ Hash?
Classifies a piece of text according to IPTC NewsCode standard.
112 113 114 115 116 117 |
# File 'lib/aylien_text_api/client.rb', line 112 def classify(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:classify]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#classify!(value = nil, params = {}) ⇒ Object
Same as classify, but calls request! so an exception is raised if the request fails.
122 123 124 125 126 127 |
# File 'lib/aylien_text_api/client.rb', line 122 def classify!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:classify]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#classify_by_taxonomy(value = nil, params = {}) ⇒ Hash?
Classifies a piece of text according to the specified taxonomy.
81 82 83 84 85 86 |
# File 'lib/aylien_text_api/client.rb', line 81 def classify_by_taxonomy(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:classify_by_taxonomy]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#classify_by_taxonomy!(value = nil, params = {}) ⇒ Object
Same as classify_by_taxonomy, but calls request! so an exception is raised if the request fails.
91 92 93 94 95 96 |
# File 'lib/aylien_text_api/client.rb', line 91 def classify_by_taxonomy!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:classify_by_taxonomy]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#combined(value = nil, params = {}) ⇒ Hash?
Runs multiple analysis operations in one API call.
368 369 370 371 372 373 |
# File 'lib/aylien_text_api/client.rb', line 368 def combined(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:combined]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#combined!(value = nil, params = {}) ⇒ Object
Same as combined, but calls request! so an exception is raised if the request fails.
378 379 380 381 382 383 |
# File 'lib/aylien_text_api/client.rb', line 378 def combined!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:combined]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#concepts(value = nil, params = {}) ⇒ Hash?
Extracts named entities mentioned in a document, disambiguates and cross-links them to DBPedia and Linked Data entities, along with their semantic types (including DBPedia and schema.org).
145 146 147 148 149 150 |
# File 'lib/aylien_text_api/client.rb', line 145 def concepts(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:concepts]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#concepts!(value = nil, params = {}) ⇒ Object
Same as concepts, but calls request! so an exception is raised if the request fails.
155 156 157 158 159 160 |
# File 'lib/aylien_text_api/client.rb', line 155 def concepts!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:concepts]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#elsa(value = nil, params = {}) ⇒ Hash?
Extracts named entities (people, organizations and locations) and applies a sentiment analysis to them
238 239 240 241 242 243 |
# File 'lib/aylien_text_api/client.rb', line 238 def elsa(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:elsa]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#elsa!(value = nil, params = {}) ⇒ Object
Same as elsa, but calls request! so an exception is raised if the request fails.
248 249 250 251 252 253 |
# File 'lib/aylien_text_api/client.rb', line 248 def elsa!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:elsa]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#entities(value = nil, params = {}) ⇒ Hash?
Extracts named entities (people, organizations and locations) and values (URLs, emails, telephone numbers, currency amounts and percentages) mentioned in a body of text.
209 210 211 212 213 214 |
# File 'lib/aylien_text_api/client.rb', line 209 def entities(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:entities]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#entities!(value = nil, params = {}) ⇒ Object
Same as entities, but calls request! so an exception is raised if the request fails.
219 220 221 222 223 224 |
# File 'lib/aylien_text_api/client.rb', line 219 def entities!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:entities]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#extract(value = nil, params = {}) ⇒ Hash?
Extracts the main body of article, including embedded media such as images & videos from a URL and removes all the surrounding clutter.
50 51 52 53 54 55 |
# File 'lib/aylien_text_api/client.rb', line 50 def extract(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:extract]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#extract!(value = nil, params = {}) ⇒ Object
Same as extract, but calls request! so an exception is raised if the request fails.
60 61 62 63 64 65 |
# File 'lib/aylien_text_api/client.rb', line 60 def extract!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:extract]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#hashtags(value = nil, params = {}) ⇒ Hash?
Suggests hashtags describing the document.
176 177 178 179 180 181 |
# File 'lib/aylien_text_api/client.rb', line 176 def (value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:hashtags]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#hashtags!(value = nil, params = {}) ⇒ Object
Same as hashtags, but calls request! so an exception is raised if the request fails.
186 187 188 189 190 191 |
# File 'lib/aylien_text_api/client.rb', line 186 def (value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:hashtags]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#image_tags(value = nil, params = {}) ⇒ Hash?
Assigns relevant tags to an image.
394 395 396 397 398 399 |
# File 'lib/aylien_text_api/client.rb', line 394 def (value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:image_tags]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#image_tags!(value = nil, params = {}) ⇒ Object
Same as image_tags, but calls request! so an exception is raised if the request fails.
404 405 406 407 408 409 |
# File 'lib/aylien_text_api/client.rb', line 404 def (value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:image_tags]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#language(value = nil, params = {}) ⇒ Hash?
Detects the main language a document is written in and returns it in ISO 639-1 format.
267 268 269 270 271 272 |
# File 'lib/aylien_text_api/client.rb', line 267 def language(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:language]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#language!(value = nil, params = {}) ⇒ Object
Same as language, but calls request! so an exception is raised if the request fails.
277 278 279 280 281 282 |
# File 'lib/aylien_text_api/client.rb', line 277 def language!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:language]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#rate_limits ⇒ Hash?
Returns current client’s rate limit values. If it gets failed, nil will be returned.
449 450 451 452 453 |
# File 'lib/aylien_text_api/client.rb', line 449 def rate_limits self.language text: "Hello world!" unless defined?(@connection) (@connection || {}).rate_limits end |
#sentiment(value = nil, params = {}) ⇒ Hash?
Detects sentiment of a document in terms of polarity (“positive” or “negative”) and subjectivity (“subjective” or “objective”).
299 300 301 302 303 304 |
# File 'lib/aylien_text_api/client.rb', line 299 def sentiment(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:sentiment]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#sentiment!(value = nil, params = {}) ⇒ Object
Same as sentiment, but calls request! so an exception is raised if the request fails.
309 310 311 312 313 314 |
# File 'lib/aylien_text_api/client.rb', line 309 def sentiment!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:sentiment]) @connection = Connection.new(endpoint, params, config) @connection.request! end |
#summarize(value = nil, params = {}) ⇒ Hash?
Summarizes an article into a few key sentences.
339 340 341 342 343 344 |
# File 'lib/aylien_text_api/client.rb', line 339 def summarize(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:summarize]) @connection = Connection.new(endpoint, params, config) @connection.request end |
#summarize!(value = nil, params = {}) ⇒ Object
Same as summarize, but calls request! so an exception is raised if the request fails.
349 350 351 352 353 354 |
# File 'lib/aylien_text_api/client.rb', line 349 def summarize!(value=nil, params={}) endpoint, params, config = common_endpoint(value, params, Configuration::ENDPOINTS[:summarize]) @connection = Connection.new(endpoint, params, config) @connection.request! end |