indico 0.0.1.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +25 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/indico.gemspec +24 -0
- data/lib/indico/helper.rb +25 -0
- data/lib/indico/version.rb +3 -0
- data/lib/indico.rb +46 -0
- data/spec/indico_spec.rb +42 -0
- data/spec/spec_helper.rb +80 -0
- metadata +111 -0
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
|
24
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
25
|
+
.rvmrc
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 IndicoDataSolutions
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# IndicoIo-ruby
|
2
|
+
|
3
|
+
A simple Ruby Wrapper for the indico set of APIs
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'indico'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install indico
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Indico.political("Guns don't kill people. People kill people.")
|
23
|
+
|
24
|
+
Indico.spam("Guns don't kill people. People kill people.")
|
25
|
+
|
26
|
+
Indico.posneg("Guns don't kill people. People kill people.")
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/[my-github-username]/indico/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/indico.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'indico/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "indico"
|
8
|
+
spec.version = Indico::VERSION
|
9
|
+
spec.authors = ["Amit Ambardekar"]
|
10
|
+
spec.email = ["amitamb@gmail.com"]
|
11
|
+
spec.summary = %q{A simple Ruby Wrapper for the indico set of APIs.}
|
12
|
+
spec.description = %q{A simple Ruby Wrapper for the indico set of APIs.}
|
13
|
+
spec.homepage = "https://github.com/IndicoDataSolutions/IndicoIo-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Indico
|
2
|
+
private
|
3
|
+
|
4
|
+
def self.base_url(c)
|
5
|
+
"http://indico.io/api/%s" % c
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.make_request(url, data_dict, headers)
|
9
|
+
uri = URI(url)
|
10
|
+
|
11
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
12
|
+
|
13
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
14
|
+
# request.set_form_data({})
|
15
|
+
request.body = data_dict
|
16
|
+
|
17
|
+
headers.each do |key, val|
|
18
|
+
request[key] = val
|
19
|
+
end
|
20
|
+
|
21
|
+
response = http.request(request)
|
22
|
+
|
23
|
+
response
|
24
|
+
end
|
25
|
+
end
|
data/lib/indico.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "indico/version"
|
2
|
+
require "indico/helper"
|
3
|
+
require "uri"
|
4
|
+
require "json"
|
5
|
+
require "net/https"
|
6
|
+
|
7
|
+
module Indico
|
8
|
+
|
9
|
+
HEADERS = { "Content-Type" => "application/json", "Accept" => "text/plain" }
|
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)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.spam(test_text)
|
18
|
+
data_dict = JSON.dump({ text: test_text})
|
19
|
+
response = make_request(base_url("spam"), data_dict, HEADERS)
|
20
|
+
JSON.parse(response.body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.posneg(test_text)
|
24
|
+
data_dict = JSON.dump({ text: test_text})
|
25
|
+
response = make_request(base_url("sentiment"), data_dict, HEADERS)
|
26
|
+
JSON.parse(response.body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.sentiment(*args)
|
30
|
+
self.posneg(*args)
|
31
|
+
end
|
32
|
+
|
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)
|
37
|
+
end
|
38
|
+
|
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']
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/indico_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
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 = Indico.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 spam tags" do
|
14
|
+
expected_keys = Set.new(["Ham", "Spam"])
|
15
|
+
response = Indico.spam("Free car!")
|
16
|
+
|
17
|
+
expect(Set.new(response.keys)).to eql(expected_keys)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should tag text with correct sentiment tags" do
|
21
|
+
expected_keys = Set.new(["Sentiment"])
|
22
|
+
response = Indico.sentiment("Worst movie ever.")
|
23
|
+
|
24
|
+
expect(Set.new(response.keys)).to eql(expected_keys)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should tag face with correct faciel expression" do
|
28
|
+
expected_keys = Set.new(["Angry", "Sad", "Neutral", "Surprise", "Fear", "Happy"])
|
29
|
+
test_face = 0.step(50, 50.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
|
30
|
+
response = Indico.fer(test_face)
|
31
|
+
|
32
|
+
expect(Set.new(response.keys)).to eql(expected_keys)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should tag face with correct faciel features" do
|
36
|
+
test_face = 0.step(50, 50.0/(48.0*48.0)).to_a[0..-2].each_slice(48).to_a
|
37
|
+
response = Indico.facial_features(test_face)
|
38
|
+
|
39
|
+
expect(response.length).to eql(48)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'indico'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
6
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
7
|
+
#
|
8
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
9
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
10
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
11
|
+
# individual file that may not need all of that loaded. Instead, make a
|
12
|
+
# separate helper file that requires this one and then use it only in the specs
|
13
|
+
# that actually need it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# The settings below are suggested to provide a good initial experience
|
21
|
+
# with RSpec, but feel free to customize to your heart's content.
|
22
|
+
=begin
|
23
|
+
# These two settings work together to allow you to limit a spec run
|
24
|
+
# to individual examples or groups you care about by tagging them with
|
25
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
26
|
+
# get run.
|
27
|
+
config.filter_run :focus
|
28
|
+
config.run_all_when_everything_filtered = true
|
29
|
+
|
30
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
31
|
+
# file, and it's useful to allow more verbose output when running an
|
32
|
+
# individual spec file.
|
33
|
+
if config.files_to_run.one?
|
34
|
+
# Use the documentation formatter for detailed output,
|
35
|
+
# unless a formatter has already been configured
|
36
|
+
# (e.g. via a command-line flag).
|
37
|
+
config.default_formatter = 'doc'
|
38
|
+
end
|
39
|
+
|
40
|
+
# Print the 10 slowest examples and example groups at the
|
41
|
+
# end of the spec run, to help surface which specs are running
|
42
|
+
# particularly slow.
|
43
|
+
config.profile_examples = 10
|
44
|
+
|
45
|
+
# Run specs in random order to surface order dependencies. If you find an
|
46
|
+
# order dependency and want to debug it, you can fix the order by providing
|
47
|
+
# the seed, which is printed after each run.
|
48
|
+
# --seed 1234
|
49
|
+
config.order = :random
|
50
|
+
|
51
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
52
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
53
|
+
# test failures related to randomization by passing the same `--seed` value
|
54
|
+
# as the one that triggered the failure.
|
55
|
+
Kernel.srand config.seed
|
56
|
+
|
57
|
+
# rspec-expectations config goes here. You can use an alternate
|
58
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
59
|
+
# assertions if you prefer.
|
60
|
+
config.expect_with :rspec do |expectations|
|
61
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
62
|
+
# For more details, see:
|
63
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
64
|
+
expectations.syntax = :expect
|
65
|
+
end
|
66
|
+
|
67
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
68
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
69
|
+
config.mock_with :rspec do |mocks|
|
70
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
71
|
+
# For more details, see:
|
72
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
73
|
+
mocks.syntax = :expect
|
74
|
+
|
75
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
76
|
+
# a real object. This is generally recommended.
|
77
|
+
mocks.verify_partial_doubles = true
|
78
|
+
end
|
79
|
+
=end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: indico
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Amit Ambardekar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: A simple Ruby Wrapper for the indico set of APIs.
|
63
|
+
email:
|
64
|
+
- amitamb@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- indico.gemspec
|
76
|
+
- lib/indico.rb
|
77
|
+
- lib/indico/helper.rb
|
78
|
+
- lib/indico/version.rb
|
79
|
+
- spec/indico_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
homepage: https://github.com/IndicoDataSolutions/IndicoIo-ruby
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: 190206259
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>'
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.3.1
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.8.24
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: A simple Ruby Wrapper for the indico set of APIs.
|
109
|
+
test_files:
|
110
|
+
- spec/indico_spec.rb
|
111
|
+
- spec/spec_helper.rb
|