indico 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,39 +8,28 @@ module Indico
8
8
 
9
9
  HEADERS = { "Content-Type" => "application/json", "Accept" => "text/plain" }
10
10
 
11
- def self.political(test_text)
12
- data_dict = JSON.dump({ text: test_text})
13
- response = make_request(base_url("political"), data_dict, HEADERS)
14
- JSON.parse(response.body)
11
+ def self.political(test_text, api="remote")
12
+ api_handler('text', test_text, api, "political")
15
13
  end
16
14
 
17
- def self.posneg(test_text)
18
- data_dict = JSON.dump({ text: test_text})
19
- response = make_request(base_url("sentiment"), data_dict, HEADERS)
20
- JSON.parse(response.body)
15
+ def self.posneg(test_text, api="remote")
16
+ api_handler('text', test_text, api, "sentiment")
21
17
  end
22
18
 
23
19
  def self.sentiment(*args)
24
20
  self.posneg(*args)
25
21
  end
26
22
 
27
- def self.language(test_text)
28
- data_dict = JSON.dump({ text: test_text })
29
- response = make_request(base_url("language"), data_dict, HEADERS)
30
- JSON.parse(response.body)
23
+ def self.language(test_text, api="remote")
24
+ api_handler('text', test_text, api, "language")
31
25
  end
32
26
 
33
- def self.fer(face)
34
- data_dict = JSON.dump({ face: face})
35
- response = make_request(base_url("fer"), data_dict, HEADERS)
36
- JSON.parse(response.body)
27
+ def self.fer(face, api="remote")
28
+ api_handler('face', face, api, "fer")
37
29
  end
38
30
 
39
- def self.facial_features(face)
40
- data_dict = JSON.dump({ face: face})
41
- response = make_request(base_url("facialfeatures"), data_dict, HEADERS)
42
- response_dict = JSON.parse(response.body)
43
- response_dict['response']
31
+ def self.facial_features(face, api="remote")
32
+ api_handler('face', face, api, "facialfeatures")['response']
44
33
  end
45
34
 
46
35
  end
@@ -1,8 +1,20 @@
1
1
  module Indico
2
2
  private
3
3
 
4
- def self.base_url(c)
5
- "http://api.indico.io/%s" % c
4
+ def self.url_join(root, api)
5
+ if root == 'local'
6
+ "http://localhost:9438/%s" % api
7
+ else
8
+ "http://api.indico.io/%s" % api
9
+ end
10
+ end
11
+
12
+ def self.api_handler(name, data, server, api)
13
+ d = {}
14
+ d[name] = data
15
+ data_dict = JSON.dump(d)
16
+ response = make_request(url_join(server, api), data_dict, HEADERS)
17
+ JSON.parse(response.body)
6
18
  end
7
19
 
8
20
  def self.make_request(url, data_dict, headers)
@@ -1,3 +1,3 @@
1
1
  module Indico
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require "indico"
2
+
3
+ module IndicoLocal
4
+
5
+ def self.political(test_text)
6
+ Indico.political(test_text, "local")
7
+ end
8
+
9
+ def self.posneg(test_text)
10
+ Indico.posneg(test_text, "local")
11
+ end
12
+
13
+ def self.sentiment(*args)
14
+ self.posneg(*args)
15
+ end
16
+
17
+ def self.language(test_text)
18
+ Indico.language(test_text, "local")
19
+ end
20
+
21
+ def self.fer(face)
22
+ Indico.fer(face, "local")
23
+ end
24
+
25
+ def self.facial_features(face)
26
+ Indico.facial_features(face, "local")
27
+ end
28
+
29
+ end
@@ -0,0 +1,77 @@
1
+ require 'indico_local'
2
+ require 'set'
3
+
4
+ describe Indico do
5
+
6
+ it "should tag text with correct political tags" do
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.
9
+
10
+ expect(Set.new(response.keys)).to eql(expected_keys)
11
+ end
12
+
13
+ it "should tag text with correct sentiment tags" do
14
+ expected_keys = Set.new(["Sentiment"])
15
+ response = IndicoLocal.sentiment("Worst movie ever.")
16
+
17
+ expect(Set.new(response.keys)).to eql(expected_keys)
18
+ end
19
+
20
+ it "should tag text with correct language tags" do
21
+ expected_keys = Set.new([
22
+ 'English',
23
+ 'Spanish',
24
+ 'Tagalog',
25
+ 'Esperanto',
26
+ 'French',
27
+ 'Chinese',
28
+ 'French',
29
+ 'Bulgarian',
30
+ 'Latin',
31
+ 'Slovak',
32
+ 'Hebrew',
33
+ 'Russian',
34
+ 'German',
35
+ 'Japanese',
36
+ 'Korean',
37
+ 'Portuguese',
38
+ 'Italian',
39
+ 'Polish',
40
+ 'Turkish',
41
+ 'Dutch',
42
+ 'Arabic',
43
+ 'Persian (Farsi)',
44
+ 'Czech',
45
+ 'Swedish',
46
+ 'Indonesian',
47
+ 'Vietnamese',
48
+ 'Romanian',
49
+ 'Greek',
50
+ 'Danish',
51
+ 'Hungarian',
52
+ 'Thai',
53
+ 'Finnish',
54
+ 'Norwegian',
55
+ 'Lithuanian'
56
+ ])
57
+ response = IndicoLocal.language('Quis custodiet ipsos custodes')
58
+
59
+ expect(Set.new(response.keys)).to eql(expected_keys)
60
+ end
61
+
62
+ it "should tag face with correct facial expression" do
63
+ 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)
66
+
67
+ expect(Set.new(response.keys)).to eql(expected_keys)
68
+ end
69
+
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)
73
+
74
+ expect(response.length).to eql(48)
75
+ end
76
+
77
+ end
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.2
4
+ version: 0.1.3
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-08-01 00:00:00.000000000 Z
13
+ date: 2014-09-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -78,6 +78,8 @@ files:
78
78
  - lib/indico.rb
79
79
  - lib/indico/helper.rb
80
80
  - lib/indico/version.rb
81
+ - lib/indico_local.rb
82
+ - spec/indico_local_spec.rb
81
83
  - spec/indico_spec.rb
82
84
  - spec/spec_helper.rb
83
85
  homepage: https://github.com/IndicoDataSolutions/IndicoIo-ruby
@@ -106,5 +108,6 @@ signing_key:
106
108
  specification_version: 3
107
109
  summary: A simple Ruby Wrapper for the indico set of APIs.
108
110
  test_files:
111
+ - spec/indico_local_spec.rb
109
112
  - spec/indico_spec.rb
110
113
  - spec/spec_helper.rb