indico 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # IndicoIo-ruby
2
2
 
3
- A simple Ruby Wrapper for the indico set of APIs
3
+ A Ruby wrapper for indico's APIs.
4
4
 
5
5
  ## Installation
6
6
 
@@ -35,6 +35,10 @@ Or install it yourself as:
35
35
 
36
36
  => {"Swedish"=>0.00033330636691921914, "Vietnamese"=>0.0002686116137658802, "Romanian"=>8.133913804076592e-06, "Dutch"=>0.09380619821813883, "Korean"=>0.00272046505489883, "Danish"=>0.0012556466207667206, "Indonesian"=>6.623391878530033e-07, "Latin"=>0.8230599921384231, "Hungarian"=>0.0012793617391960567, "Persian (Farsi)"=>0.0019848504383980473, "Lithuanian"=>0.007328693814717631, "French"=>0.00016792646226101638, "Norwegian"=>0.0009179030069742254, "Russian"=>0.0002643396088456642, "Thai"=>7.746466749651003e-05, "Finnish"=>0.0026367338676522643, "Hebrew"=>3.70933525938127e-05, "Bulgarian"=>3.746416283126873e-05, "Turkish"=>0.0004606965429738638, "Greek"=>0.027456554742563633, "Tagalog"=>0.0005143018200605518, "English"=>0.00013517846159760138, "Arabic"=>0.00013589586110619373, "Italian"=>2.650711180999111e-06, "Portuguese"=>0.013193681336032896, "Chinese"=>0.008818957727120736, "German"=>0.00011732494215411359, "Japanese"=>0.0005885208894664065, "Czech"=>9.916434007248934e-05, "Slovak"=>8.869445598583308e-05, "Spanish"=>0.011844579596827902, "Polish"=>9.900290296255447e-05, "Esperanto"=>0.0002599482830232367}
37
37
 
38
+ > Indico.text_tags('This coconut green tea is amazing!');
39
+
40
+ => { "food"=>0.3713687833244494, "cars"=>0.0037924017632370586, ...}
41
+
38
42
  ```
39
43
 
40
44
  ###Local
data/lib/indico/helper.rb CHANGED
@@ -5,16 +5,21 @@ module Indico
5
5
  if root == 'local'
6
6
  "http://localhost:9438/%s" % api
7
7
  else
8
- "http://api.indico.io/%s" % api
8
+ "http://apiv1.indico.io/%s" % api
9
9
  end
10
10
  end
11
11
 
12
- def self.api_handler(name, data, server, api)
12
+ def self.api_handler(data, server, api)
13
13
  d = {}
14
- d[name] = data
14
+ d['data'] = data
15
15
  data_dict = JSON.dump(d)
16
16
  response = make_request(url_join(server, api), data_dict, HEADERS)
17
- JSON.parse(response.body)
17
+ results = JSON.parse(response.body)
18
+ if results.key?("error")
19
+ results = results["error"]
20
+ else
21
+ results = results["results"]
22
+ end
18
23
  end
19
24
 
20
25
  def self.make_request(url, data_dict, headers)
@@ -23,15 +28,12 @@ module Indico
23
28
  http = Net::HTTP.new(uri.host, uri.port)
24
29
 
25
30
  request = Net::HTTP::Post.new(uri.request_uri)
26
- # request.set_form_data({})
27
31
  request.body = data_dict
28
32
 
29
33
  headers.each do |key, val|
30
34
  request[key] = val
31
35
  end
32
36
 
33
- response = http.request(request)
34
-
35
- response
37
+ http.request(request)
36
38
  end
37
39
  end
@@ -1,3 +1,3 @@
1
1
  module Indico
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/indico.rb CHANGED
@@ -9,11 +9,11 @@ module Indico
9
9
  HEADERS = { "Content-Type" => "application/json", "Accept" => "text/plain" }
10
10
 
11
11
  def self.political(test_text, api="remote")
12
- api_handler('text', test_text, api, "political")
12
+ api_handler(test_text, api, "political")
13
13
  end
14
14
 
15
15
  def self.posneg(test_text, api="remote")
16
- api_handler('text', test_text, api, "sentiment")
16
+ api_handler(test_text, api, "sentiment")
17
17
  end
18
18
 
19
19
  def self.sentiment(*args)
@@ -21,15 +21,24 @@ module Indico
21
21
  end
22
22
 
23
23
  def self.language(test_text, api="remote")
24
- api_handler('text', test_text, api, "language")
24
+ api_handler(test_text, api, "language")
25
25
  end
26
26
 
27
+ def self.text_tags(test_text, api="remote")
28
+ api_handler(test_text, api, "texttags")
29
+ end
30
+
27
31
  def self.fer(face, api="remote")
28
- api_handler('face', face, api, "fer")
32
+ api_handler(face, api, "fer")
29
33
  end
30
34
 
31
35
  def self.facial_features(face, api="remote")
32
- api_handler('face', face, api, "facialfeatures")['response']
36
+ api_handler(face, api, "facialfeatures")
37
+ end
38
+
39
+ def self.image_features(face, api="remote")
40
+ api_handler(face, api, "imagefeatures")
33
41
  end
34
42
 
43
+
35
44
  end
data/lib/indico_local.rb CHANGED
@@ -18,6 +18,10 @@ module IndicoLocal
18
18
  Indico.language(test_text, "local")
19
19
  end
20
20
 
21
+ def self.text_tags(test_text)
22
+ Indico.text_tags(test_text, "local")
23
+ end
24
+
21
25
  def self.fer(face)
22
26
  Indico.fer(face, "local")
23
27
  end
@@ -26,4 +30,8 @@ module IndicoLocal
26
30
  Indico.facial_features(face, "local")
27
31
  end
28
32
 
33
+ def self.image_features(image)
34
+ Indico.image_features(image, "local")
35
+ end
36
+
29
37
  end
@@ -5,18 +5,24 @@ describe Indico do
5
5
 
6
6
  it "should tag text with correct political tags" do
7
7
  expected_keys = Set.new(["Conservative", "Green", "Liberal", "Libertarian"])
8
- response = IndicoLocal.political("Guns don't kill people. People kill people.") # Guns don't kill people. People kill people.
8
+ response = Indico.political("Guns don't kill people. People kill people.") # Guns don't kill people. People kill people.
9
9
 
10
10
  expect(Set.new(response.keys)).to eql(expected_keys)
11
11
  end
12
12
 
13
- it "should tag text with correct sentiment tags" do
14
- expected_keys = Set.new(["Sentiment"])
15
- response = IndicoLocal.sentiment("Worst movie ever.")
13
+ it "should tag text with correct text tags" do
14
+ expected_keys = Set.new(["political", "arts", "products", "news"])
15
+ response = Indico.text_tags("Guns don't kill people. People kill people.") # Guns don't kill people. People kill people.
16
16
 
17
17
  expect(Set.new(response.keys)).to eql(expected_keys)
18
18
  end
19
19
 
20
+ it "should tag text with correct sentiment tags" do
21
+ response = Indico.sentiment("Worst movie ever.")
22
+
23
+ expect(response).to be < 0.5
24
+ end
25
+
20
26
  it "should tag text with correct language tags" do
21
27
  expected_keys = Set.new([
22
28
  'English',
@@ -54,24 +60,48 @@ describe Indico do
54
60
  'Norwegian',
55
61
  'Lithuanian'
56
62
  ])
57
- response = IndicoLocal.language('Quis custodiet ipsos custodes')
63
+ response = Indico.language('Quis custodiet ipsos custodes')
64
+
65
+ expect(Set.new(response.keys)).to eql(expected_keys)
66
+ end
67
+
68
+ it "should tag text with correct text tags" do
69
+ expected_keys = Set.new(['fashion', 'art', 'energy', 'economics', 'entrepreneur',
70
+ 'books', 'politics', 'gardening', 'nba', 'conservative',
71
+ 'technology', 'startups', 'relationships', 'education',
72
+ 'humor', 'psychology', 'bicycling', 'investing', 'travel',
73
+ 'cooking', 'christianity', 'environment', 'religion', 'health',
74
+ 'hockey', 'pets', 'music', 'soccer', 'guns', 'gaming', 'jobs',
75
+ 'business', 'nature', 'food', 'cars', 'photography', 'philosophy',
76
+ 'geek', 'sports', 'baseball', 'news', 'television', 'entertainment',
77
+ 'parenting', 'comics', 'science', 'nfl','programming',
78
+ 'personalfinance', 'atheism', 'movies', 'anime', 'fitness',
79
+ 'military', 'realestate', 'history'])
80
+ response = Indico.text_tags("Guns don't kill people. People kill people.") # Guns don't kill people. People kill people.
58
81
 
59
82
  expect(Set.new(response.keys)).to eql(expected_keys)
60
83
  end
61
84
 
62
85
  it "should tag face with correct facial expression" do
63
86
  expected_keys = Set.new(["Angry", "Sad", "Neutral", "Surprise", "Fear", "Happy"])
64
- test_face = 0.step(50, 50.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
65
- response = IndicoLocal.fer(test_face)
87
+ test_face = 0.step(1, 1.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
88
+ response = Indico.fer(test_face)
66
89
 
67
90
  expect(Set.new(response.keys)).to eql(expected_keys)
68
91
  end
69
92
 
70
- it "should tag face with correct facial features" do
71
- test_face = 0.step(50, 50.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
72
- response = IndicoLocal.facial_features(test_face)
93
+ it "should return a facial feature vector" do
94
+ test_face = 0.step(1, 1.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
95
+ response = Indico.facial_features(test_face)
73
96
 
74
97
  expect(response.length).to eql(48)
75
98
  end
76
99
 
100
+ it "should return an image features vector" do
101
+ test_image = 0.step(1, 1.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
102
+ response = Indico.image_features(test_image)
103
+
104
+ expect(response.length).to eql(2048)
105
+ end
106
+
77
107
  end
data/spec/indico_spec.rb CHANGED
@@ -11,10 +11,9 @@ describe Indico do
11
11
  end
12
12
 
13
13
  it "should tag text with correct sentiment tags" do
14
- expected_keys = Set.new(["Sentiment"])
15
14
  response = Indico.sentiment("Worst movie ever.")
16
15
 
17
- expect(Set.new(response.keys)).to eql(expected_keys)
16
+ expect(response < 0.5).to eql(true)
18
17
  end
19
18
 
20
19
  it "should tag text with correct language tags" do
@@ -59,7 +58,24 @@ describe Indico do
59
58
  expect(Set.new(response.keys)).to eql(expected_keys)
60
59
  end
61
60
 
62
- it "should tag face with correct faciel expression" do
61
+ it "should tag text with correct text tags" do
62
+ expected_keys = Set.new(['fashion', 'art', 'energy', 'economics', 'entrepreneur',
63
+ 'books', 'politics', 'gardening', 'nba', 'conservative',
64
+ 'technology', 'startups', 'relationships', 'education',
65
+ 'humor', 'psychology', 'bicycling', 'investing', 'travel',
66
+ 'cooking', 'christianity', 'environment', 'religion', 'health',
67
+ 'hockey', 'pets', 'music', 'soccer', 'guns', 'gaming', 'jobs',
68
+ 'business', 'nature', 'food', 'cars', 'photography', 'philosophy',
69
+ 'geek', 'sports', 'baseball', 'news', 'television', 'entertainment',
70
+ 'parenting', 'comics', 'science', 'nfl','programming',
71
+ 'personalfinance', 'atheism', 'movies', 'anime', 'fitness',
72
+ 'military', 'realestate', 'history'])
73
+ response = Indico.text_tags("Guns don't kill people. People kill people.") # Guns don't kill people. People kill people.
74
+
75
+ expect(Set.new(response.keys)).to eql(expected_keys)
76
+ end
77
+
78
+ it "should tag face with correct facial expression" do
63
79
  expected_keys = Set.new(["Angry", "Sad", "Neutral", "Surprise", "Fear", "Happy"])
64
80
  test_face = 0.step(50, 50.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
65
81
  response = Indico.fer(test_face)
@@ -67,7 +83,7 @@ describe Indico do
67
83
  expect(Set.new(response.keys)).to eql(expected_keys)
68
84
  end
69
85
 
70
- it "should tag face with correct faciel features" do
86
+ it "should tag face with correct facial features" do
71
87
  test_face = 0.step(50, 50.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
72
88
  response = Indico.facial_features(test_face)
73
89
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-26 00:00:00.000000000 Z
13
+ date: 2014-11-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler