datatxt 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NTkzMTBhYWEyYzA5YTE0N2RkYTc3MjQ3MDlmMGY1NWQxNjU1OWRkNA==
5
- data.tar.gz: !binary |-
6
- MGZmOGMzYTYwYWRkNmI4YjU3ZGIxNmU0ODcyOTcyNzEwZGFjNDUyYw==
2
+ SHA1:
3
+ metadata.gz: d63def615925c6d502745b5a0701c2e82b1b5464
4
+ data.tar.gz: a0d911b41057e0c2089f58d440c57caf4a642f8d
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YjI4NzEwNjRlZjM2NGE3MTgxZTk4MDJmZjg4MzE5ZWM0NDcyY2NlNzhhOTQy
10
- YjUwNDgyNzZiNzg5ZmIwMWRmMWJiZmZlODE4NmM2YjI4ZDA2MDk3MDdiMTkx
11
- OWYwYmRmNTUwZTI2YTMyZWE3MjZlYzAyNTA4OTIyMTM2ZmI3MWE=
12
- data.tar.gz: !binary |-
13
- NTExODFhNDg3YTFiNTg5YThhZTdiYzU3OGI2ZDU5Zjc4YmVkZmMxOTgwNTNj
14
- OGEzMWY4YjA0M2U5ZDIwMWUwZDE3ZDcxNjU3NTA0ZTc2ZWIyMDRiYzI3ZDJk
15
- YjIxODE4ZTZhOWMzNWQ3NjUxMjM3NjlhYTU2MGViMDIzM2NjNmI=
6
+ metadata.gz: 8bc1fa0009616376685539d2a20f5f407a858b042dfb1b52dce802e20f7e88e4bd2004fa3c92893fc0145b8d6aa6c53eca3779c12ca55b8631f0ddc99b906d49
7
+ data.tar.gz: 26fbea7bf55ea04871cd4d7a777dab724716ec219bce86582389bcdf01c5ccc1f3ae12aab2b56cb75814a39de96aa8f9c7870f82549bb38ab04f73775a864a64
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # dataTXT [![Code Climate](https://codeclimate.com/github/zenkay/datatxt-ruby/badges/gpa.svg)](https://codeclimate.com/github/zenkay/datatxt-ruby) [![Travis CI](https://travis-ci.org/zenkay/datatxt-ruby.svg?branch=master)](https://travis-ci.org/zenkay/datatxt-ruby)
1
+ # [![Ruby Gem Icon](https://raw.githubusercontent.com/zenkay/datatxt-ruby/master/rubygem.png)](https://rubygems.org/gems/datatxt) dataTXT Ruby Gem
2
2
 
3
- Ruby Gem for interaction with [dataTXT](https://dandelion.eu/products/datatxt/) APIs
3
+ [![Code Climate](https://codeclimate.com/github/zenkay/datatxt-ruby/badges/gpa.svg)](https://codeclimate.com/github/zenkay/datatxt-ruby) [![Travis CI](https://travis-ci.org/zenkay/datatxt-ruby.svg?branch=master)](https://travis-ci.org/zenkay/datatxt-ruby) [![Gem Version](https://badge.fury.io/rb/datatxt.svg)](http://badge.fury.io/rb/datatxt) [![Coverage Status](https://coveralls.io/repos/zenkay/datatxt-ruby/badge.png?branch=master)](https://coveralls.io/r/zenkay/datatxt-ruby?branch=master)
4
4
 
5
5
  ## Installation
6
6
 
@@ -15,3 +15,39 @@ And then execute:
15
15
  ```
16
16
  $ bundle install
17
17
  ```
18
+ ## Setup
19
+
20
+ Setup configuration parameters
21
+
22
+ ```
23
+ Datatxt.configure do |c|
24
+ c.app_id = "your-app-id-for-datatxt-account"
25
+ c.app_key = "your-app-key-for-datatxt-account"
26
+ c.endpoint = https://api.dandelion.eu/"
27
+ end
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ _Methods references are taken from [dataTXT documentation](https://dandelion.eu/docs/)._
33
+
34
+ **dataTXT-NEX**: is a named entity extraction & linking API that performs very well even on short texts, on which many other similar services do not. dataTXT-NEX currently works on English, French, German, Italian and Portuguese texts. With this API you will be able to automatically tag your texts, extracting Wikipedia entities and enriching your data.
35
+
36
+ ```
37
+ element = Datatxt::Nex.new
38
+ response = element.analyze(text: "This is a test")
39
+ ```
40
+
41
+ **dataTXT-SIM**: is a semantic sentence similarity API optimized on short sentences. With this API you will be able to compare two sentences and get a score of their semantic similarity. It works even if the two sentences don't have any word in common.
42
+
43
+ ```
44
+ element = Datatxt::Sim.new
45
+ response = element.analyze(text1: "This is a test", text2: "This is another test")
46
+ ```
47
+
48
+ **dataTXT-LI**: is a simple language identification API; it is a tool that may be useful when dealing with texts, so we decided to open it to all our users. It currently supports more than 50 languages.
49
+
50
+ ```
51
+ element = Datatxt::Li.new
52
+ response = element.analyze(text: "Questo è un test")
53
+ ```
data/datatxt.gemspec CHANGED
@@ -18,13 +18,16 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "faraday", "~> 0.9.0"
22
- spec.add_dependency "faraday_middleware", "~> 0.9.1"
21
+ spec.required_ruby_version = '~> 2.1'
22
+
23
+ spec.add_dependency "faraday", '~> 0.9', '>= 0.9.0'
24
+ spec.add_dependency "faraday_middleware", '~> 0.9', '>= 0.9.1'
23
25
 
24
26
  spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "rake"
27
- spec.add_development_dependency "vcr"
28
- spec.add_development_dependency "webmock"
29
- spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "rspec", "~> 2.12"
28
+ spec.add_development_dependency "rake", "~> 10.1"
29
+ spec.add_development_dependency "vcr", "~> 2.4"
30
+ spec.add_development_dependency "webmock", "~> 1.17"
31
+ spec.add_development_dependency "simplecov", "~> 0.8"
32
+ spec.add_development_dependency "coveralls", "~> 0.7"
30
33
  end
data/lib/datatxt.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "datatxt/version"
2
+ require "datatxt/base"
2
3
  require "datatxt/nex"
4
+ require "datatxt/sim"
5
+ require "datatxt/li"
3
6
 
4
7
  module Datatxt
5
8
 
@@ -0,0 +1,30 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Datatxt
6
+
7
+ class Base
8
+
9
+ protected
10
+
11
+ def call(endpoint, params)
12
+ begin
13
+ params = params.merge(
14
+ :$app_id => Datatxt.config.app_id,
15
+ :$app_key => Datatxt.config.app_key
16
+ )
17
+ conn = Faraday.new(url: Datatxt.config.endpoint) do |faraday|
18
+ faraday.request :url_encoded
19
+ faraday.adapter Faraday.default_adapter
20
+ end
21
+ response = conn.post endpoint, params
22
+ JSON.parse response.body
23
+ rescue Exception => e
24
+ raise Datatxt::BadResponse
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
data/lib/datatxt/li.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Datatxt
6
+
7
+ class Li < Base
8
+
9
+ ENDPOINT = "/datatxt/li/v1"
10
+
11
+ attr_accessor :text, :url, :html, :html_fragment, :clean
12
+
13
+ def analyze(options)
14
+ params = options
15
+ call(ENDPOINT, params)
16
+ end
17
+
18
+ end
19
+
20
+ end
data/lib/datatxt/nex.rb CHANGED
@@ -4,35 +4,17 @@ require "json"
4
4
 
5
5
  module Datatxt
6
6
 
7
- class Nex
7
+ class Nex < Base
8
8
 
9
- attr_accessor :endpoint, :text, :url, :html, :html_fragment, :lang, :min_confidence, :min_length, :social_hashtag, :social_mention, :include, :extra_types, :country, :custom_spots
9
+ ENDPOINT = "/datatxt/nex/v1"
10
10
 
11
- def initialize
12
-
13
- end
11
+ attr_accessor :text, :url, :html, :html_fragment, :lang, :min_confidence, :min_length, :social_hashtag, :social_mention, :include, :extra_types, :country, :custom_spots
14
12
 
15
- def post(options)
16
- call(params)
13
+ def analyze(options)
14
+ params = options
15
+ call(ENDPOINT, params)
17
16
  end
18
17
 
19
- protected
20
-
21
- def call(params)
22
- begin
23
- params = params.merge({api_key: Machinereading.config.api_key})
24
- conn = Faraday.new(url: Machinereading.config.endpoint) do |faraday|
25
- faraday.request :url_encoded
26
- faraday.adapter Faraday.default_adapter
27
- end
28
- response = conn.post "/#{endpoint}", params
29
- response.body
30
- rescue Exception => e
31
- puts e.inspect
32
- end
33
- end
34
-
35
-
36
18
  end
37
19
 
38
20
  end
@@ -0,0 +1,20 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Datatxt
6
+
7
+ class Sim < Base
8
+
9
+ ENDPOINT = "/datatxt/sim/v1"
10
+
11
+ attr_accessor :text1, :url1, :html1, :html_fragment1, :text2, :url2, :html2, :html_fragment2, :lang, :bow
12
+
13
+ def analyze(options)
14
+ params = options
15
+ call(ENDPOINT, params)
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Datatxt
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/rubygem.png ADDED
Binary file
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.dandelion.eu/datatxt/li/v1
6
+ body:
7
+ encoding: UTF-8
8
+ string: "%24app_id=e0bca290&%24app_key=2294c676b8698383764514cc219fad92&text=Mio+padre+che+mi+spinge+a+mangiare+e+guai+se+non+finisco+mio+padre+che+vuol+farmi+guidare+mi+frena+con+il+fischio+il+bambino+pi%C3%B9+grande+mi+mena+davanti+a+tutti+gli+altri+lui+che+passa+per+caso+mi+salva+e+mi+condanna+per+sempre"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Access-Control-Allow-Origin:
24
+ - "*"
25
+ Content-Type:
26
+ - application/json;charset=UTF-8
27
+ Date:
28
+ - Sun, 28 Sep 2014 17:24:54 GMT
29
+ X-Dl-Request-Id:
30
+ - e74cedce-0df6-43fe-4d33-a0a9db6d2a0e
31
+ X-Dl-Units:
32
+ - '0.1'
33
+ X-Dl-Units-Left:
34
+ - '986.9'
35
+ X-Dl-Units-Reset:
36
+ - '2014-09-29 00:00:00 +0000'
37
+ Content-Length:
38
+ - '97'
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"time":1,"detectedLangs":[{"lang":"it","confidence":1.0}],"timestamp":"2014-09-28T17:24:54.478"}'
44
+ http_version:
45
+ recorded_at: Sun, 28 Sep 2014 17:24:55 GMT
46
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,89 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.dandelion.eu/datatxt/sim/v1
6
+ body:
7
+ encoding: UTF-8
8
+ string: "%24app_id=e0bca290&%24app_key=2294c676b8698383764514cc219fad92&text1=Mio+padre+che+mi+spinge+a+mangiare+e+guai+se+non+finisco+mio+padre+che+vuol+farmi+guidare+mi+frena+con+il+fischio+il+bambino+pi%C3%B9+grande+mi+mena+davanti+a+tutti+gli+altri+lui+che+passa+per+caso+mi+salva+e+mi+condanna+per+sempre&text2=Mio+padre+di+spalle+sul+piatto+si+mangia+la+vita+e+poi+sulla+pista+da+ballo+fa+un+valzer+dentro+il+suo+nuovo+vestito"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Access-Control-Allow-Origin:
24
+ - "*"
25
+ Content-Type:
26
+ - application/json;charset=UTF-8
27
+ Date:
28
+ - Sun, 28 Sep 2014 17:14:40 GMT
29
+ X-Dl-Request-Id:
30
+ - b470bd81-ea53-4685-5a3d-cc43d5b00952
31
+ X-Dl-Units:
32
+ - '3.0'
33
+ X-Dl-Units-Left:
34
+ - '991'
35
+ X-Dl-Units-Reset:
36
+ - '2014-09-29 00:00:00 +0000'
37
+ Content-Length:
38
+ - '98'
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"time":2,"similarity":0.0,"lang":"it","langConfidence":1.0,"timestamp":"2014-09-28T17:14:40.710"}'
44
+ http_version:
45
+ recorded_at: Sun, 28 Sep 2014 17:14:41 GMT
46
+ - request:
47
+ method: post
48
+ uri: https://api.dandelion.eu/datatxt/nex/v1
49
+ body:
50
+ encoding: UTF-8
51
+ string: "%24app_id=e0bca290&%24app_key=2294c676b8698383764514cc219fad92&text=Mio+padre+che+mi+spinge+a+mangiare+e+guai+se+non+finisco+mio+padre+che+vuol+farmi+guidare+mi+frena+con+il+fischio+il+bambino+pi%C3%B9+grande+mi+mena+davanti+a+tutti+gli+altri+lui+che+passa+per+caso+mi+salva+e+mi+condanna+per+sempre+mio+padre+di+spalle+sul+piatto+si+mangia+la+vita+e+poi+sulla+pista+da+ballo+fa+un+valzer+dentro+il+suo+nuovo+vestito++Per+sempre+solo+per+sempre+cosa+sar%C3%A0+mai+porvarvi+dentro+solo+tutto+il+tempo+per+sempre+solo+per+sempre+c%27%C3%A8+un+istante+che+rimane+l%C3%AC+piantato+eternamente+E+lei+che+non+si+lascia+afferrare+si+piega+indietro+e+ride+e+lei+che+dice+quanto+mi+ama+e+io+che+mi+fido+e+lei+che+mi+toccava+per+prima+la+sua+mano+bambina+vuole+che+le+giuri+qualcosa+le+si+gonfia+una+vena+e+lei+che+era+troppo+pi%C3%B9+forte+sicura+di+tutto+e+prima+di+andarsene+mi+d%C3%A0+il+profilo+con+un+movimento+perfetto+Per+sempre+solo+per+sempre+cosa+sar%C3%A0+mai+portarvi+dentro+solo+tutto+il+tempo+per+sempre+solo+per+sempre+c%27%C3%A8+un+istante+che+rimane+l%C3%AC+piantato+eternamente+per+sempre+solo+per+sempre+Mia+madre+che+prepara+la+cena+cantando+sanremo+carezza+la+testa+a+mio+padre+gli+dice+vedrai+che+ce+la+faremo+Per+sempre+solo+per+sempre+cosa+sar%C3%A0+mai+portarvi+dentro+solo+tutto+il+tempo+per+sempre+solo+per+sempre+c%27%C3%A8+un+istante+che+rimane+l%C3%AC+piantato+eternamente+per+sempre+solo+per+sempre"
52
+ headers:
53
+ User-Agent:
54
+ - Faraday v0.9.0
55
+ Content-Type:
56
+ - application/x-www-form-urlencoded
57
+ Accept-Encoding:
58
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
59
+ Accept:
60
+ - "*/*"
61
+ response:
62
+ status:
63
+ code: 200
64
+ message: OK
65
+ headers:
66
+ Access-Control-Allow-Origin:
67
+ - "*"
68
+ Content-Type:
69
+ - application/json;charset=UTF-8
70
+ Date:
71
+ - Sun, 28 Sep 2014 17:14:41 GMT
72
+ X-Dl-Request-Id:
73
+ - 0930a7df-fda3-4ea6-5838-05acb4b4b969
74
+ X-Dl-Units:
75
+ - '1.0'
76
+ X-Dl-Units-Left:
77
+ - '990'
78
+ X-Dl-Units-Reset:
79
+ - '2014-09-29 00:00:00 +0000'
80
+ Content-Length:
81
+ - '405'
82
+ Connection:
83
+ - keep-alive
84
+ body:
85
+ encoding: UTF-8
86
+ string: '{"time":14,"annotations":[{"start":309,"end":315,"spot":"valzer","confidence":0.7315,"id":236538,"title":"Valzer","uri":"http://it.wikipedia.org/wiki/Valzer","label":"Valzer"},{"start":1036,"end":1043,"spot":"sanremo","confidence":0.6675,"id":2756642,"title":"Sanremo","uri":"http://it.wikipedia.org/wiki/Sanremo","label":"Sanremo"}],"lang":"it","langConfidence":1.0,"timestamp":"2014-09-28T17:14:41.551"}'
87
+ http_version:
88
+ recorded_at: Sun, 28 Sep 2014 17:14:42 GMT
89
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.dandelion.eu/datatxt/sim/v1
6
+ body:
7
+ encoding: UTF-8
8
+ string: "%24app_id=e0bca290&%24app_key=2294c676b8698383764514cc219fad92&text1=Mio+padre+che+mi+spinge+a+mangiare+e+guai+se+non+finisco+mio+padre+che+vuol+farmi+guidare+mi+frena+con+il+fischio+il+bambino+pi%C3%B9+grande+mi+mena+davanti+a+tutti+gli+altri+lui+che+passa+per+caso+mi+salva+e+mi+condanna+per+sempre&text2=Mio+padre+di+spalle+sul+piatto+si+mangia+la+vita+e+poi+sulla+pista+da+ballo+fa+un+valzer+dentro+il+suo+nuovo+vestito"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Access-Control-Allow-Origin:
24
+ - "*"
25
+ Content-Type:
26
+ - application/json;charset=UTF-8
27
+ Date:
28
+ - Sun, 28 Sep 2014 17:21:49 GMT
29
+ X-Dl-Request-Id:
30
+ - d613fc9c-5f0c-4efe-6f60-330e481d70a5
31
+ X-Dl-Units:
32
+ - '3.0'
33
+ X-Dl-Units-Left:
34
+ - '987'
35
+ X-Dl-Units-Reset:
36
+ - '2014-09-29 00:00:00 +0000'
37
+ Content-Length:
38
+ - '98'
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"time":3,"similarity":0.0,"lang":"it","langConfidence":1.0,"timestamp":"2014-09-28T17:21:49.533"}'
44
+ http_version:
45
+ recorded_at: Sun, 28 Sep 2014 17:21:50 GMT
46
+ recorded_with: VCR 2.9.3
data/spec/li_spec.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ vcr_options = { :cassette_name => "datatxt_li", :record => :new_episodes }
4
+
5
+ describe Datatxt::Li, vcr: vcr_options do
6
+
7
+ before(:each) do
8
+ Datatxt.configure do |c|
9
+ # account: Mario Rossi <datatxt@mailinator.com>
10
+ c.app_id = "e0bca290"
11
+ c.app_key = "2294c676b8698383764514cc219fad92"
12
+ c.endpoint = "https://api.dandelion.eu/"
13
+ end
14
+ end
15
+
16
+ it "initialize a new sim request" do
17
+ request = Datatxt::Li.new
18
+ expect(request).to be_an_instance_of(Datatxt::Li)
19
+ end
20
+
21
+ it "make a request to li using an italian plain texts" do
22
+ element = Datatxt::Li.new
23
+ response = element.analyze(
24
+ text: "Mio padre che mi spinge a mangiare e guai se non finisco mio padre che vuol farmi guidare mi frena con il fischio il bambino più grande mi mena davanti a tutti gli altri lui che passa per caso mi salva e mi condanna per sempre",
25
+ )
26
+ expect(response).not_to be_empty
27
+ expect(response["detectedLangs"]).to be_an_instance_of(Array)
28
+ response["detectedLangs"].each do |a|
29
+ expect(a["confidence"]).not_to be_nil
30
+ expect(a["lang"]).not_to be_nil
31
+ end
32
+ end
33
+
34
+ it "raise exception on wrong config parameters" do
35
+ Datatxt.configure do |c|
36
+ c.app_id = "bad-app-id"
37
+ c.app_key = "bad-app-key"
38
+ c.endpoint = "not-an-url-endpoint"
39
+ end
40
+ element = Datatxt::Li.new
41
+ expect { element.analyze(text: "test") }.to raise_error(Datatxt::BadResponse)
42
+ end
43
+
44
+
45
+ end
data/spec/nex_spec.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ vcr_options = { :cassette_name => "datatxt_nex", :record => :new_episodes }
4
+
5
+ describe Datatxt::Nex, vcr: vcr_options do
6
+
7
+ before(:each) do
8
+ Datatxt.configure do |c|
9
+ # account: Mario Rossi <datatxt@mailinator.com>
10
+ c.app_id = "e0bca290"
11
+ c.app_key = "2294c676b8698383764514cc219fad92"
12
+ c.endpoint = "https://api.dandelion.eu/"
13
+ end
14
+ end
15
+
16
+ it "initialize a new nex request" do
17
+ request = Datatxt::Nex.new
18
+ expect(request).to be_an_instance_of(Datatxt::Nex)
19
+ end
20
+
21
+ it "make a request to nex using italian plain text" do
22
+ element = Datatxt::Nex.new
23
+ response = element.analyze(
24
+ text: "Mio padre che mi spinge a mangiare e guai se non finisco mio padre che vuol farmi guidare mi frena con il fischio il bambino più grande mi mena davanti a tutti gli altri lui che passa per caso mi salva e mi condanna per sempre mio padre di spalle sul piatto si mangia la vita e poi sulla pista da ballo fa un valzer dentro il suo nuovo vestito Per sempre solo per sempre cosa sarà mai porvarvi dentro solo tutto il tempo per sempre solo per sempre c'è un istante che rimane lì piantato eternamente E lei che non si lascia afferrare si piega indietro e ride e lei che dice quanto mi ama e io che mi fido e lei che mi toccava per prima la sua mano bambina vuole che le giuri qualcosa le si gonfia una vena e lei che era troppo più forte sicura di tutto e prima di andarsene mi dà il profilo con un movimento perfetto Per sempre solo per sempre cosa sarà mai portarvi dentro solo tutto il tempo per sempre solo per sempre c'è un istante che rimane lì piantato eternamente per sempre solo per sempre Mia madre che prepara la cena cantando sanremo carezza la testa a mio padre gli dice vedrai che ce la faremo Per sempre solo per sempre cosa sarà mai portarvi dentro solo tutto il tempo per sempre solo per sempre c'è un istante che rimane lì piantato eternamente per sempre solo per sempre"
25
+ )
26
+ expect(response).not_to be_empty
27
+ expect(response["lang"]).to eq("it")
28
+ expect(response["annotations"]).to be_an_instance_of(Array)
29
+ response["annotations"].each do |a|
30
+ expect(a["confidence"]).not_to be_nil
31
+ expect(a["title"]).not_to be_nil
32
+ expect(a["label"]).not_to be_nil
33
+ end
34
+ end
35
+
36
+ it "raise exception on wrong config parameters" do
37
+ Datatxt.configure do |c|
38
+ c.app_id = "bad-app-id"
39
+ c.app_key = "bad-app-key"
40
+ c.endpoint = "not-an-url-endpoint"
41
+ end
42
+ element = Datatxt::Nex.new
43
+ expect { element.analyze(text: "test") }.to raise_error(Datatxt::BadResponse)
44
+ end
45
+
46
+ end
data/spec/sim_spec.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ vcr_options = { :cassette_name => "datatxt_sim", :record => :new_episodes }
4
+
5
+ describe Datatxt::Nex, vcr: vcr_options do
6
+
7
+ before(:each) do
8
+ Datatxt.configure do |c|
9
+ # account: Mario Rossi <datatxt@mailinator.com>
10
+ c.app_id = "e0bca290"
11
+ c.app_key = "2294c676b8698383764514cc219fad92"
12
+ c.endpoint = "https://api.dandelion.eu/"
13
+ end
14
+ end
15
+
16
+ it "initialize a new sim request" do
17
+ request = Datatxt::Sim.new
18
+ expect(request).to be_an_instance_of(Datatxt::Sim)
19
+ end
20
+
21
+ it "make a request to sim using two italian plain texts" do
22
+ element = Datatxt::Sim.new
23
+ response = element.analyze(
24
+ text1: "Mio padre che mi spinge a mangiare e guai se non finisco mio padre che vuol farmi guidare mi frena con il fischio il bambino più grande mi mena davanti a tutti gli altri lui che passa per caso mi salva e mi condanna per sempre",
25
+ text2: "Mio padre di spalle sul piatto si mangia la vita e poi sulla pista da ballo fa un valzer dentro il suo nuovo vestito"
26
+ )
27
+ expect(response).not_to be_empty
28
+ expect(response["lang"]).to eq("it")
29
+ expect(response["similarity"]).not_to be_nil
30
+ end
31
+
32
+ it "raise exception on wrong config parameters" do
33
+ Datatxt.configure do |c|
34
+ c.app_id = "bad-app-id"
35
+ c.app_key = "bad-app-key"
36
+ c.endpoint = "not-an-url-endpoint"
37
+ end
38
+ element = Datatxt::Sim.new
39
+ expect { element.analyze(text: "test") }.to raise_error(Datatxt::BadResponse)
40
+ end
41
+
42
+
43
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'simplecov'
2
2
  SimpleCov.start
3
3
 
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
4
7
  require "datatxt"
5
8
  require 'vcr'
6
9
 
@@ -11,7 +14,9 @@ VCR.configure do |c|
11
14
  end
12
15
 
13
16
  RSpec.configure do |config|
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
18
  config.run_all_when_everything_filtered = true
15
19
  config.filter_run :focus
16
20
  config.order = 'random'
21
+ # config.color_enabled = true
17
22
  end
metadata CHANGED
@@ -1,127 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datatxt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Mostosi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2014-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 0.9.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 0.9.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: faraday_middleware
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ~>
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - - ">="
32
41
  - !ruby/object:Gem::Version
33
42
  version: 0.9.1
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - ~>
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.9'
50
+ - - ">="
39
51
  - !ruby/object:Gem::Version
40
52
  version: 0.9.1
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: bundler
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
- - - ~>
57
+ - - "~>"
46
58
  - !ruby/object:Gem::Version
47
59
  version: '1.6'
48
60
  type: :development
49
61
  prerelease: false
50
62
  version_requirements: !ruby/object:Gem::Requirement
51
63
  requirements:
52
- - - ~>
64
+ - - "~>"
53
65
  - !ruby/object:Gem::Version
54
66
  version: '1.6'
55
67
  - !ruby/object:Gem::Dependency
56
68
  name: rspec
57
69
  requirement: !ruby/object:Gem::Requirement
58
70
  requirements:
59
- - - ! '>='
71
+ - - "~>"
60
72
  - !ruby/object:Gem::Version
61
- version: '0'
73
+ version: '2.12'
62
74
  type: :development
63
75
  prerelease: false
64
76
  version_requirements: !ruby/object:Gem::Requirement
65
77
  requirements:
66
- - - ! '>='
78
+ - - "~>"
67
79
  - !ruby/object:Gem::Version
68
- version: '0'
80
+ version: '2.12'
69
81
  - !ruby/object:Gem::Dependency
70
82
  name: rake
71
83
  requirement: !ruby/object:Gem::Requirement
72
84
  requirements:
73
- - - ! '>='
85
+ - - "~>"
74
86
  - !ruby/object:Gem::Version
75
- version: '0'
87
+ version: '10.1'
76
88
  type: :development
77
89
  prerelease: false
78
90
  version_requirements: !ruby/object:Gem::Requirement
79
91
  requirements:
80
- - - ! '>='
92
+ - - "~>"
81
93
  - !ruby/object:Gem::Version
82
- version: '0'
94
+ version: '10.1'
83
95
  - !ruby/object:Gem::Dependency
84
96
  name: vcr
85
97
  requirement: !ruby/object:Gem::Requirement
86
98
  requirements:
87
- - - ! '>='
99
+ - - "~>"
88
100
  - !ruby/object:Gem::Version
89
- version: '0'
101
+ version: '2.4'
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
93
105
  requirements:
94
- - - ! '>='
106
+ - - "~>"
95
107
  - !ruby/object:Gem::Version
96
- version: '0'
108
+ version: '2.4'
97
109
  - !ruby/object:Gem::Dependency
98
110
  name: webmock
99
111
  requirement: !ruby/object:Gem::Requirement
100
112
  requirements:
101
- - - ! '>='
113
+ - - "~>"
102
114
  - !ruby/object:Gem::Version
103
- version: '0'
115
+ version: '1.17'
104
116
  type: :development
105
117
  prerelease: false
106
118
  version_requirements: !ruby/object:Gem::Requirement
107
119
  requirements:
108
- - - ! '>='
120
+ - - "~>"
109
121
  - !ruby/object:Gem::Version
110
- version: '0'
122
+ version: '1.17'
111
123
  - !ruby/object:Gem::Dependency
112
124
  name: simplecov
113
125
  requirement: !ruby/object:Gem::Requirement
114
126
  requirements:
115
- - - ! '>='
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.8'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '0.8'
137
+ - !ruby/object:Gem::Dependency
138
+ name: coveralls
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
116
142
  - !ruby/object:Gem::Version
117
- version: '0'
143
+ version: '0.7'
118
144
  type: :development
119
145
  prerelease: false
120
146
  version_requirements: !ruby/object:Gem::Requirement
121
147
  requirements:
122
- - - ! '>='
148
+ - - "~>"
123
149
  - !ruby/object:Gem::Version
124
- version: '0'
150
+ version: '0.7'
125
151
  description: Gem for dataTXT API (dandelion.eu)
126
152
  email:
127
153
  - andrea.mostosi@zenkay.net
@@ -129,17 +155,26 @@ executables: []
129
155
  extensions: []
130
156
  extra_rdoc_files: []
131
157
  files:
132
- - .gitignore
133
- - .travis.yml
158
+ - ".gitignore"
159
+ - ".travis.yml"
134
160
  - Gemfile
135
161
  - LICENSE.txt
136
162
  - README.md
137
163
  - Rakefile
138
164
  - datatxt.gemspec
139
165
  - lib/datatxt.rb
166
+ - lib/datatxt/base.rb
167
+ - lib/datatxt/li.rb
140
168
  - lib/datatxt/nex.rb
169
+ - lib/datatxt/sim.rb
141
170
  - lib/datatxt/version.rb
142
- - spec/element_spec.rb
171
+ - rubygem.png
172
+ - spec/cassettes/datatxt_li.yml
173
+ - spec/cassettes/datatxt_nex.yml
174
+ - spec/cassettes/datatxt_sim.yml
175
+ - spec/li_spec.rb
176
+ - spec/nex_spec.rb
177
+ - spec/sim_spec.rb
143
178
  - spec/spec_helper.rb
144
179
  homepage: ''
145
180
  licenses:
@@ -151,12 +186,12 @@ require_paths:
151
186
  - lib
152
187
  required_ruby_version: !ruby/object:Gem::Requirement
153
188
  requirements:
154
- - - ! '>='
189
+ - - "~>"
155
190
  - !ruby/object:Gem::Version
156
- version: '0'
191
+ version: '2.1'
157
192
  required_rubygems_version: !ruby/object:Gem::Requirement
158
193
  requirements:
159
- - - ! '>='
194
+ - - ">="
160
195
  - !ruby/object:Gem::Version
161
196
  version: '0'
162
197
  requirements: []
@@ -166,6 +201,11 @@ signing_key:
166
201
  specification_version: 4
167
202
  summary: Gem for dataTXT API (dandelion.eu)
168
203
  test_files:
169
- - spec/element_spec.rb
204
+ - spec/cassettes/datatxt_li.yml
205
+ - spec/cassettes/datatxt_nex.yml
206
+ - spec/cassettes/datatxt_sim.yml
207
+ - spec/li_spec.rb
208
+ - spec/nex_spec.rb
209
+ - spec/sim_spec.rb
170
210
  - spec/spec_helper.rb
171
211
  has_rdoc:
data/spec/element_spec.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- vcr_options = { :cassette_name => "datatxt_element", :record => :new_episodes }
4
-
5
- describe Datatxt::Nex, vcr: vcr_options do
6
-
7
- before(:all) do
8
- Datatxt.configure do |c|
9
- # account: Mario Rossi <datatxt@mailinator.com>
10
- c.app_id = "e0bca290"
11
- c.app_key = "2294c676b8698383764514cc219fad92"
12
- c.endpoint = "https://api.dandelion.eu/datatxt/"
13
- end
14
- end
15
-
16
- it "initialize a new nex request" do
17
- request = Datatxt::Nex.new
18
- expect(request).to be_an_instance_of(Datatxt::Nex)
19
- end
20
-
21
- end