aylien_text_api 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/README.md +12 -10
  4. data/aylien_text_api.gemspec +3 -3
  5. data/lib/aylien_text_api/client.rb +30 -93
  6. data/lib/aylien_text_api/configuration.rb +2 -4
  7. data/lib/aylien_text_api/version.rb +1 -1
  8. data/spec/fixtures/aylien_text_api/client/{microformats_with_invalid_client.yml → elsa_with_invalid_client.yml} +10 -8
  9. data/spec/fixtures/aylien_text_api/client/{related_with_invalid_params.yml → elsa_with_invalid_params.yml} +15 -24
  10. data/spec/fixtures/aylien_text_api/client/elsa_with_text.yml +98 -0
  11. data/spec/fixtures/aylien_text_api/client/{related_with_unauthenticated_client.yml → elsa_with_unauthenticated_client.yml} +10 -8
  12. data/spec/fixtures/aylien_text_api/client/elsa_with_valid_url.yml +47 -0
  13. data/spec/fixtures/aylien_text_api/client/elsa_with_value_as_text.yml +92 -0
  14. data/spec/fixtures/aylien_text_api/client/elsa_with_value_as_valid_url.yml +53 -0
  15. data/spec/lib/aylien_text_api/client_spec.rb +1 -3
  16. data/spec/lib/aylien_text_api/elsa.rb +81 -0
  17. metadata +14 -152
  18. data/spec/fixtures/aylien_text_api/client/microformats_with_invalid_params.yml +0 -62
  19. data/spec/fixtures/aylien_text_api/client/microformats_with_unauthenticated_client.yml +0 -42
  20. data/spec/fixtures/aylien_text_api/client/microformats_with_valid_url.yml +0 -84
  21. data/spec/fixtures/aylien_text_api/client/microformats_with_value_as_valid_url.yml +0 -84
  22. data/spec/fixtures/aylien_text_api/client/related_with_invalid_client.yml +0 -38
  23. data/spec/fixtures/aylien_text_api/client/related_with_phrase.yml +0 -112
  24. data/spec/fixtures/aylien_text_api/client/related_with_value_as_phrase.yml +0 -112
  25. data/spec/fixtures/aylien_text_api/client/related_with_value_as_valid_url.yml +0 -62
  26. data/spec/fixtures/aylien_text_api/client/unsupervised_classify_with_invalid_client.yml +0 -38
  27. data/spec/fixtures/aylien_text_api/client/unsupervised_classify_with_invalid_params.yml +0 -57
  28. data/spec/fixtures/aylien_text_api/client/unsupervised_classify_with_text.yml +0 -53
  29. data/spec/fixtures/aylien_text_api/client/unsupervised_classify_with_unauthenticated_client.yml +0 -42
  30. data/spec/fixtures/aylien_text_api/client/unsupervised_classify_with_valid_url.yml +0 -97
  31. data/spec/fixtures/aylien_text_api/client/unsupervised_classify_with_value_as_text.yml +0 -57
  32. data/spec/fixtures/aylien_text_api/client/unsupervised_classify_with_value_as_valid_url.yml +0 -97
  33. data/spec/lib/aylien_text_api/microformats.rb +0 -66
  34. data/spec/lib/aylien_text_api/related.rb +0 -80
  35. data/spec/lib/aylien_text_api/unsupervised_classify.rb +0 -87
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 09993e8546c5922ae46dd06032296cecf47f37b7
4
- data.tar.gz: 898af691bf87d6db20eb28fd0dfea314b63de681
2
+ SHA256:
3
+ metadata.gz: 4a3b0fc823371783b3b294300d906988df2fec190a09e919d4bc9d399f07a8e6
4
+ data.tar.gz: 50ffab1f2e1f025131e34fc5d5606acdc5924dea77f7e8fae7754420985d4e00
5
5
  SHA512:
6
- metadata.gz: f4621c72ee93f2170b6f3852b6db64ac31c8ec5a05319774d97847e3bee607d275b7b1d4d67a5cc55c30702093596e5ebc038111a8b6fcc86226a7c38fc37455
7
- data.tar.gz: a0be785b22f55687fb1e33c15ee639dd5abf02e2948e66fa5bfc1a5d5297be3269f9e584abbb69c569cc76cd17ac548c8953a50513ecd7adb0595bd79e59a463
6
+ metadata.gz: 39bbd804b19d4441e4b417e1f72d532b8c0c60b72651a947cd805948ddbb29f07aa04c5f15e324638bb21d3f557ac3047b1934441ee72e0e5a0592d1d9188779
7
+ data.tar.gz: efd1038da6269bc13909969409c933d66ca9fedad7248bfe635ace65b6c49a55148d57cbbe01ee440a4756ab83a0617d2d97064917b73e0fe14625370225505e
data/.gitignore CHANGED
@@ -2,4 +2,7 @@ config/app_config.yml
2
2
  doc/
3
3
  .yardoc/
4
4
  *.gem
5
+ .idea
6
+ *.iml
7
+ .bundle
5
8
  Gemfile.lock
data/README.md CHANGED
@@ -1,18 +1,18 @@
1
- About
1
+ AYLIEN Text API (Ruby)
2
2
  =====
3
3
  [![Gem Version](https://badge.fury.io/rb/aylien_text_api.svg)](http://badge.fury.io/rb/aylien_text_api)
4
4
 
5
5
  This is the Ruby client library for AYLIEN's APIs. If you haven't already done so, you will need to [sign up](https://developer.aylien.com/signup).
6
6
 
7
7
 
8
- Installation
9
- ============
8
+ ## Installation
9
+
10
10
  gem install aylien_text_api
11
11
 
12
12
  See the [Developers Guide](http://docs.aylien.com/docs/ruby-sdk) for additional documentation.
13
13
 
14
- Configuration
15
- =============
14
+ ## Configuration
15
+
16
16
  Aylien Text API needs app_id and app_key which you can get it from [Text API website](https://developer.aylien.com/signup).
17
17
 
18
18
  You can pass configuration options as a block to AylienTextApi.configure.
@@ -35,8 +35,8 @@ require 'aylien_text_api'
35
35
  client = AylienTextApi::Client.new(app_id: "YOUR APP ID", app_key: "YOUR APP KEY")
36
36
  ````
37
37
 
38
- Examples
39
- =====
38
+ ## Examples
39
+
40
40
  After configuring a client, you can do the following things:
41
41
 
42
42
  ````ruby
@@ -50,7 +50,7 @@ client.extract url: "http://techcrunch.com/2014/02/27/aylien-launches-text-analy
50
50
  # }
51
51
  ````
52
52
 
53
- If any errors happen during the call, nil will be returned. If destructive methods are used, an exception corresponding to the error will be returned.
53
+ If any errors happen during the call, `nil` will be returned. If destructive methods are used, an exception corresponding to the error will be returned.
54
54
 
55
55
  ````ruby
56
56
  client.classify! url: "http://www.bbc.com/sport/0/football/25912393"
@@ -60,11 +60,13 @@ client.classify! url: "http://www.bbc.com/sport/0/football/25912393"
60
60
  # }
61
61
  ````
62
62
 
63
- Third Party Libraries and Dependencies
64
- ======================================
63
+ ## Third Party Libraries and Dependencies
64
+
65
65
  For development you will also need the following libraries:
66
66
 
67
67
  * rake
68
68
  * minitest
69
69
  * vcr
70
70
  * webmock
71
+
72
+ To install the dependencies, make sure you have `bundle` installed, then run `bundle install --path=vendor/bundle`. Then, run `bundle exec rake test` to run tests.
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.name = "aylien_text_api"
7
7
  s.version = AylienTextApi::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Aylien Inc.", "Hamed Ramezanian"]
9
+ s.authors = ["Aylien Inc."]
10
10
  s.license = 'Apache-2.0'
11
- s.email = ["support@aylien.com", "hamed.r.nik@gmail.com"]
11
+ s.email = ["support@aylien.com"]
12
12
  s.homepage = "https://github.com/AYLIEN/aylien_textapi_ruby"
13
13
  s.summary = %q{AYLIEN Text Analysis API is a package of Natural Language Processing and Machine Learning-powered tools for analyzing and extracting various kinds of information from text and images.}
14
14
  s.description = %q{AYLIEN Text Analysis API is a package of Natural Language Processing and Machine Learning-powered tools for analyzing and extracting various kinds of information from text and images.}
@@ -23,5 +23,5 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency 'rake', '~> 10.4'
24
24
  s.add_development_dependency 'minitest', '~> 5.4'
25
25
  s.add_development_dependency 'vcr', '~> 2.9'
26
- s.add_development_dependency 'webmock', '~> 1.20'
26
+ s.add_development_dependency 'webmock', '~> 2.3.2'
27
27
  end
@@ -222,6 +222,35 @@ module AylienTextApi
222
222
  @connection = Connection.new(endpoint, params, config)
223
223
  @connection.request!
224
224
  end
225
+
226
+ # Extracts named entities (people, organizations and locations) and
227
+ # applies a sentiment analysis to them
228
+ #
229
+ # @param [String] value (nil) URL or Text
230
+ # @param [Hash] params The entities endpoint options
231
+ # @option params [String] :url The URL
232
+ # @option params [String] :text Text
233
+ #
234
+ # @return [Hash, nil] A hash of result. See
235
+ # http://docs.aylien.com/docs/elsa for more information
236
+ # on the data returned.
237
+ #
238
+ def elsa(value=nil, params={})
239
+ endpoint, params, config = common_endpoint(value, params,
240
+ Configuration::ENDPOINTS[:elsa])
241
+ @connection = Connection.new(endpoint, params, config)
242
+ @connection.request
243
+ end
244
+
245
+ # Same as elsa, but calls request! so an exception is raised
246
+ # if the request fails.
247
+ #
248
+ def elsa!(value=nil, params={})
249
+ endpoint, params, config = common_endpoint(value, params,
250
+ Configuration::ENDPOINTS[:elsa])
251
+ @connection = Connection.new(endpoint, params, config)
252
+ @connection.request!
253
+ end
225
254
 
226
255
  # Detects the main language a document is written in and returns it
227
256
  # in ISO 639-1 format.
@@ -323,97 +352,7 @@ module AylienTextApi
323
352
  @connection = Connection.new(endpoint, params, config)
324
353
  @connection.request!
325
354
  end
326
-
327
- # Returns phrases related to the provided unigram, or bigram.
328
- #
329
- # @param [String] value (nil) URL or Text
330
- # @param [Hash] params The related endpoint options
331
- # @option params [String] :phrase Phrase
332
- # @option params [Integer] :count (20) Number of phrases to return.
333
- # Max is 100.
334
- #
335
- # @return [Hash, nil] A hash of result. See
336
- # http://docs.aylien.com/docs/related for more information
337
- # on the data returned.
338
- #
339
- def related(value=nil, params={})
340
- endpoint, params, config = common_endpoint(value, params,
341
- Configuration::ENDPOINTS[:related])
342
- @connection = Connection.new(endpoint, params, config)
343
- @connection.request
344
- end
345
-
346
- # Same as related, but calls request! so an exception is raised
347
- # if the request fails.
348
- #
349
- def related!(value=nil, params={})
350
- endpoint, params, config = common_endpoint(value, params,
351
- Configuration::ENDPOINTS[:related])
352
- @connection = Connection.new(endpoint, params, config)
353
- @connection.request!
354
- end
355
-
356
- # Return Microformats.
357
- #
358
- # @param [String] value (nil) URL
359
- # @param [Hash] params The microformats endpoint options
360
- # @option params [String] :url The URL
361
- # @option params [String] :language ('en') Language of text.
362
- # Valid options are en, de, fr, es, it, pt, and auto.
363
- # If set to auto, it'll try to detect the language.
364
- #
365
- # @return [Hash, nil] A hash of result. See
366
- # http://docs.aylien.com/docs/microformats for more information
367
- # on the data returned.
368
- #
369
- def microformats(value=nil, params={})
370
- endpoint, params, config = common_endpoint(value, params,
371
- Configuration::ENDPOINTS[:microformats])
372
- @connection = Connection.new(endpoint, params, config)
373
- @connection.request
374
- end
375
-
376
- # Same as microformats, but calls request! so an exception is raised
377
- # if the request fails.
378
- #
379
- def microformats!(value=nil, params={})
380
- endpoint, params, config = common_endpoint(value, params,
381
- Configuration::ENDPOINTS[:microformats])
382
- @connection = Connection.new(endpoint, params, config)
383
- @connection.request!
384
- end
385
-
386
- # Return Unsupervised Classify.
387
- #
388
- # @param [String] value (nil) URL or Text
389
- # @param [Hash] params The Unsupervised Classify endpoint options
390
- # @option params [String] :url The URL
391
- # @option params [String] :text Text
392
- # @option params [Array<String>] :class Array of classes
393
- # @option params [Integer] :number_of_concepts Number of intermediary
394
- # common topics to consider when calculating semantic similarity
395
- #
396
- # @return [Hash, nil] A hash of result. See
397
- # http://docs.aylien.com/docs/classify-unsupervised for more information
398
- # on the data returned.
399
- #
400
- def unsupervised_classify(value=nil, params={})
401
- endpoint, params, config = common_endpoint(value, params,
402
- Configuration::ENDPOINTS[:unsupervised_classify])
403
- @connection = Connection.new(endpoint, params, config)
404
- @connection.request
405
- end
406
-
407
- # Same as unsupervised_classify, but calls request! so an exception is raised
408
- # if the request fails.
409
- #
410
- def unsupervised_classify!(value=nil, params={})
411
- endpoint, params, config = common_endpoint(value, params,
412
- Configuration::ENDPOINTS[:unsupervised_classify])
413
- @connection = Connection.new(endpoint, params, config)
414
- @connection.request!
415
- end
416
-
355
+
417
356
  # Runs multiple analysis operations in one API call.
418
357
  #
419
358
  # @param [String] value (nil) URL or Text
@@ -528,8 +467,6 @@ module AylienTextApi
528
467
  value.strip!
529
468
  if validate_uri(value)
530
469
  params[:url] = value
531
- elsif endpoint == Configuration::ENDPOINTS[:related]
532
- params[:phrase] = value
533
470
  else
534
471
  params[:text] = value
535
472
  end
@@ -33,14 +33,12 @@ module AylienTextApi
33
33
  entities: 'entities',
34
34
  hashtags: 'hashtags',
35
35
  language: 'language',
36
- related: 'related',
37
36
  sentiment: 'sentiment',
38
37
  summarize: 'summarize',
39
- microformats: 'microformats',
40
- unsupervised_classify: 'classify/unsupervised',
41
38
  image_tags: 'image-tags',
42
39
  combined: 'combined',
43
- absa: 'absa/:domain'
40
+ absa: 'absa/:domain',
41
+ elsa: 'elsa'
44
42
  }
45
43
 
46
44
  # Build accessor methods for every config options so we can do this, for example:
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module AylienTextApi
16
- VERSION = "0.7.0" unless defined? AylienTextApi::VERSION
16
+ VERSION = "0.8.0" unless defined? AylienTextApi::VERSION
17
17
  end
@@ -2,17 +2,17 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: https://api.aylien.com/api/v1/microformats
5
+ uri: https://api.aylien.com/api/v1/elsa
6
6
  body:
7
7
  encoding: US-ASCII
8
- string: url=http%3A%2F%2Fcodepen.io%2Fanon%2Fpen%2FZYaKbz.html
8
+ string: text=Barack+Hussein+Obama+II+is+the+44th+and+current%0A++++++President+of+the+United+States%2C+and+the+first%0A++++++African+American+to+hold+the+office.
9
9
  headers:
10
10
  Accept-Encoding:
11
11
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
12
  Accept:
13
13
  - "*/*"
14
14
  User-Agent:
15
- - Aylien Text API Ruby Gem 0.6.0
15
+ - Aylien Text API Ruby Gem 0.7.0
16
16
  Content-Type:
17
17
  - application/x-www-form-urlencoded
18
18
  response:
@@ -21,18 +21,20 @@ http_interactions:
21
21
  message: Forbidden
22
22
  headers:
23
23
  Server:
24
- - openresty/1.9.3.2
24
+ - openresty/1.13.6.1
25
25
  Date:
26
- - Thu, 28 Apr 2016 10:36:05 GMT
26
+ - Thu, 31 May 2018 11:03:08 GMT
27
27
  Content-Type:
28
28
  - text/plain; charset=us-ascii
29
29
  Transfer-Encoding:
30
30
  - chunked
31
- Connection:
32
- - keep-alive
31
+ Via:
32
+ - 1.1 google
33
+ Alt-Svc:
34
+ - clear
33
35
  body:
34
36
  encoding: UTF-8
35
37
  string: Authentication parameters missing
36
38
  http_version:
37
- recorded_at: Thu, 28 Apr 2016 10:36:05 GMT
39
+ recorded_at: Thu, 31 May 2018 11:03:09 GMT
38
40
  recorded_with: VCR 2.9.3
@@ -2,17 +2,17 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: https://api.aylien.com/api/v1/related
5
+ uri: https://api.aylien.com/api/v1/elsa
6
6
  body:
7
7
  encoding: US-ASCII
8
- string: wrong_param=android
8
+ string: wrong_param=Barack+Hussein+Obama+II+is+the+44th+and+current%0A++++++President+of+the+United+States%2C+and+the+first%0A++++++African+American+to+hold+the+office.
9
9
  headers:
10
10
  Accept-Encoding:
11
11
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
12
  Accept:
13
13
  - "*/*"
14
14
  User-Agent:
15
- - Aylien Text API Ruby Gem 0.6.0
15
+ - Aylien Text API Ruby Gem 0.7.0
16
16
  Content-Type:
17
17
  - application/x-www-form-urlencoded
18
18
  X-Aylien-Textapi-Application-Id:
@@ -22,41 +22,32 @@ http_interactions:
22
22
  response:
23
23
  status:
24
24
  code: 400
25
- message: Bad Request
25
+ message: ''
26
26
  headers:
27
27
  Server:
28
- - openresty/1.9.3.2
28
+ - openresty/1.13.6.1
29
29
  Date:
30
- - Thu, 28 Apr 2016 10:44:40 GMT
30
+ - Thu, 31 May 2018 11:03:10 GMT
31
31
  Content-Type:
32
32
  - application/json;charset=UTF-8
33
33
  Content-Length:
34
- - '360'
35
- Connection:
36
- - keep-alive
37
- X-Ratelimit-Limit:
38
- - '207000'
39
- X-Ratelimit-Remaining:
40
- - '173639'
41
- X-Ratelimit-Reset:
42
- - '1461888000'
34
+ - '219'
35
+ Via:
36
+ - 1.1 google
37
+ Alt-Svc:
38
+ - clear
43
39
  body:
44
40
  encoding: UTF-8
45
41
  string: |-
46
42
  {
47
- "error": "requirement failed: Form field 'phrase' Required",
43
+ "error": "requirement failed: either text or url is required",
48
44
  "errors": [{
49
45
  "reason": "required",
50
- "message": "Form field 'phrase' Required",
46
+ "message": "either text or url is required",
51
47
  "locationType": "parameter",
52
- "location": "phrase"
53
- }, {
54
- "reason": "required",
55
- "message": "Query parameter 'phrase' Required",
56
- "locationType": "parameter",
57
- "location": "phrase"
48
+ "location": "text"
58
49
  }]
59
50
  }
60
51
  http_version:
61
- recorded_at: Thu, 28 Apr 2016 10:44:40 GMT
52
+ recorded_at: Thu, 31 May 2018 11:03:10 GMT
62
53
  recorded_with: VCR 2.9.3
@@ -0,0 +1,98 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.aylien.com/api/v1/elsa
6
+ body:
7
+ encoding: US-ASCII
8
+ string: text=Barack+Hussein+Obama+II+is+the+44th+and+current%0A++++++President+of+the+United+States%2C+and+the+first%0A++++++African+American+to+hold+the+office.
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Aylien Text API Ruby Gem 0.7.0
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ X-Aylien-Textapi-Application-Id:
19
+ - "<PASSWORD>"
20
+ X-Aylien-Textapi-Application-Key:
21
+ - "<PASSWORD>"
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: ''
26
+ headers:
27
+ Server:
28
+ - openresty/1.13.6.1
29
+ Date:
30
+ - Thu, 31 May 2018 11:03:11 GMT
31
+ Content-Type:
32
+ - application/json;charset=UTF-8
33
+ Content-Length:
34
+ - '1364'
35
+ X-Ratelimit-Limit:
36
+ - '400000'
37
+ X-Ratelimit-Remaining:
38
+ - '399991'
39
+ X-Ratelimit-Reset:
40
+ - '1527811200'
41
+ Access-Control-Allow-Origin:
42
+ - "*"
43
+ Via:
44
+ - 1.1 google
45
+ Alt-Svc:
46
+ - clear
47
+ body:
48
+ encoding: UTF-8
49
+ string: |-
50
+ {
51
+ "text": "Barack Hussein Obama II is the 44th and current\n President of the United States, and the first\n African American to hold the office.",
52
+ "entities": [{
53
+ "mentions": [{
54
+ "offset": 71,
55
+ "confidence": 1.0,
56
+ "text": "United States",
57
+ "sentiment": {
58
+ "polarity": "neutral",
59
+ "confidence": 0.48
60
+ }
61
+ }],
62
+ "overall_sentiment": {
63
+ "polarity": "neutral",
64
+ "confidence": 0.48
65
+ },
66
+ "type": "Location",
67
+ "links": [{
68
+ "uri": "http://dbpedia.org/resource/United_States",
69
+ "provider": "dbpedia",
70
+ "types": ["http://dbpedia.org/ontology/Country"],
71
+ "confidence": 28.15
72
+ }]
73
+ }, {
74
+ "mentions": [{
75
+ "offset": 0,
76
+ "confidence": 1.0,
77
+ "text": "Barack Hussein Obama II",
78
+ "sentiment": {
79
+ "polarity": "positive",
80
+ "confidence": 0.56
81
+ }
82
+ }],
83
+ "overall_sentiment": {
84
+ "polarity": "positive",
85
+ "confidence": 0.56
86
+ },
87
+ "type": "Person",
88
+ "links": [{
89
+ "uri": "http://dbpedia.org/resource/Barack_Obama",
90
+ "provider": "dbpedia",
91
+ "types": ["http://dbpedia.org/ontology/Person", "http://xmlns.com/foaf/0.1/Person", "http://dbpedia.org/ontology/Agent", "http://www.wikidata.org/entity/Q215627", "http://www.wikidata.org/entity/Q5", "http://schema.org/Person"],
92
+ "confidence": 0.91
93
+ }]
94
+ }]
95
+ }
96
+ http_version:
97
+ recorded_at: Thu, 31 May 2018 11:03:11 GMT
98
+ recorded_with: VCR 2.9.3