wise 0.1.1
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README +62 -0
- data/bin/wise.rb +51 -0
- data/ext/restclient-ext.rb +41 -0
- data/lib/wise.rb +39 -0
- data/lib/wise/client.rb +99 -0
- data/lib/wise/project.rb +94 -0
- data/lib/wise/version.rb +29 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc66c5ea74b929be6c2faec1ac32aa51d09e0e34
|
4
|
+
data.tar.gz: ab3381a13ea13cc82f18dbd2eda3c982332bb320
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: daa4e6c22314bfc025b66999a8f2ea461d467d0961fe99ab1673fc7465780f66afa2c5790933a372bb06236897f57b9cbaa489417d89092a79101eb3774918b4
|
7
|
+
data.tar.gz: e19178c20e087d9ba69589f39c32277d7f644916ce79e5ecbf9b587442a07f3f0a1df4e9ee17a4ef5979e140d5e6c84fd90fe5b3669f4d8cce6911eb9018f9d3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) <2013>, <wise.io LLC>
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
- Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
14
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
19
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
20
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
21
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= Wise.io for Ruby
|
2
|
+
|
3
|
+
== Usage
|
4
|
+
The following outlines the basic usage of the wise.io ruby library.
|
5
|
+
|
6
|
+
=== Assumptions and limitations.
|
7
|
+
At the moment, only predictions on already existent models in already existent
|
8
|
+
projects are supported. The library has been tested in Ruby 1.8.7p358 as well as
|
9
|
+
in Ruby 2.0.0p0.
|
10
|
+
|
11
|
+
=== Basic usage
|
12
|
+
Connecting to a wise.io project can be done in two ways. The Wise::project method suffices, as illustrated by the following example:
|
13
|
+
|
14
|
+
Wise.project 'robin/quasars', :user => 'robin', :password => '...' do |p|
|
15
|
+
p.predict 'train', 'quasarsTest.csv'
|
16
|
+
end
|
17
|
+
|
18
|
+
Alternately, a project handle may be created using Wise::Project.new:
|
19
|
+
|
20
|
+
p = Wise::Project.new 'robin/quasars', :user => 'robin', :password => '...'
|
21
|
+
p.predict 'train', 'quasarsTest.csv'
|
22
|
+
|
23
|
+
=== Setting up a local wise.io profile
|
24
|
+
To avoid having to supply user name and password every time a project handle is
|
25
|
+
created, the +wise.rb+ binary supplied with the gem can be used to store
|
26
|
+
credentials in a local wise.io profile. To do this, simply run
|
27
|
+
<tt>wise.rb --setup</tt> as follows:
|
28
|
+
|
29
|
+
$ wise.rb --setup
|
30
|
+
User: robin
|
31
|
+
Password:
|
32
|
+
OK, wrote wise.io profile.
|
33
|
+
|
34
|
+
If the supplied credentials are valid, connecting to a project and performing
|
35
|
+
predictions on a model is as simple as:
|
36
|
+
|
37
|
+
Wise.project 'robin/quasars' do |p|
|
38
|
+
p.predict 'train', :dataset => 'test'
|
39
|
+
end
|
40
|
+
|
41
|
+
== License
|
42
|
+
Copyright (c) <2013>, <wise.io LLC>
|
43
|
+
All rights reserved.
|
44
|
+
|
45
|
+
Redistribution and use in source and binary forms, with or without modification,
|
46
|
+
are permitted provided that the following conditions are met:
|
47
|
+
|
48
|
+
- Redistributions of source code must retain the above copyright notice,
|
49
|
+
this list of conditions and the following disclaimer.
|
50
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
51
|
+
this list of conditions and the following disclaimer in the documentation
|
52
|
+
and/or other materials provided with the distribution.
|
53
|
+
|
54
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
55
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
56
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
57
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
58
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
59
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
60
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
61
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
62
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/bin/wise.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'etc'
|
4
|
+
require 'optparse'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
require 'wise/version'
|
8
|
+
|
9
|
+
optparse = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: wise.rb [options]"
|
11
|
+
|
12
|
+
opts.on_tail("-s", "--setup", "Setup wise.rb with username and password.") do
|
13
|
+
home = Etc.getpwuid.dir
|
14
|
+
wisedir = File.join home, ".wise"
|
15
|
+
profile = File.join wisedir, "profile"
|
16
|
+
|
17
|
+
FileUtils.mkdir_p wisedir, :mode => 0700
|
18
|
+
|
19
|
+
File.open(profile, "w") do |f|
|
20
|
+
print "User: "
|
21
|
+
user = gets.chomp
|
22
|
+
|
23
|
+
print "Password: "
|
24
|
+
|
25
|
+
system "stty -echo"
|
26
|
+
password = gets.chomp
|
27
|
+
system "stty echo"
|
28
|
+
print "\n"
|
29
|
+
|
30
|
+
f.write "#{user}\n#{password}"
|
31
|
+
end
|
32
|
+
|
33
|
+
FileUtils.chmod 0600, profile
|
34
|
+
|
35
|
+
puts "OK, wrote wise.io profile."
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on_tail("-v", "--version", "Show version and exit.") do
|
40
|
+
puts "wise.rb, version #{Wise::VERSION}."
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
optparse.parse!
|
47
|
+
puts optparse
|
48
|
+
rescue OptionParser::InvalidOption
|
49
|
+
puts optparse
|
50
|
+
exit
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright (c) <2013>, <wise.io LLC>
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
# are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# - Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# - Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
18
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
20
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
21
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
22
|
+
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
|
24
|
+
# REST Client is Copyright (c) 2008-2013 by the REST Client Team. See
|
25
|
+
# https://github.com/rest-client/rest-client for further information.
|
26
|
+
# No ownership of, or affiliation to, REST Client or the REST Client Team is
|
27
|
+
# implied.
|
28
|
+
|
29
|
+
module RestClient # :nodoc:
|
30
|
+
class Resource # :nodoc:
|
31
|
+
def get(additional_headers={}, &block)
|
32
|
+
payload = additional_headers.delete(:payload)
|
33
|
+
headers = (options[:headers] || {}).merge(additional_headers)
|
34
|
+
Request.execute(options.merge(
|
35
|
+
:method => :get,
|
36
|
+
:url => url,
|
37
|
+
:payload => payload,
|
38
|
+
:headers => headers), &(block || @block))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/wise.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
=begin
|
2
|
+
---
|
3
|
+
Copyright (c) <2013>, <wise.io LLC>
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without modification,
|
7
|
+
are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
- Redistributions of source code must retain the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
19
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
21
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
22
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
23
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
24
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
=end
|
26
|
+
module Wise
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rest_client'
|
30
|
+
require 'json'
|
31
|
+
require 'csv'
|
32
|
+
require 'etc'
|
33
|
+
|
34
|
+
$:.unshift(File.dirname(__FILE__))
|
35
|
+
require File.join(File.dirname(__FILE__), '..', 'ext', 'restclient-ext.rb')
|
36
|
+
|
37
|
+
require 'wise/client'
|
38
|
+
require 'wise/project'
|
39
|
+
require 'wise/version'
|
data/lib/wise/client.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
=begin
|
2
|
+
---
|
3
|
+
Copyright (c) <2013>, <wise.io LLC>
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without modification,
|
7
|
+
are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
- Redistributions of source code must retain the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
19
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
21
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
22
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
23
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
24
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
=end
|
26
|
+
|
27
|
+
module Wise
|
28
|
+
class AuthenticationError < StandardError # :nodoc:
|
29
|
+
end
|
30
|
+
class ResourceError < StandardError # :nodoc:
|
31
|
+
end
|
32
|
+
|
33
|
+
class Client # :nodoc:
|
34
|
+
attr_reader :rest
|
35
|
+
|
36
|
+
def initialize path, options
|
37
|
+
address = options[:address] || "https://wise.io"
|
38
|
+
owner, project = path.split("/")[1..2]
|
39
|
+
|
40
|
+
user, pass = get_credentials options
|
41
|
+
|
42
|
+
@rest = RestClient::Resource.new "#{address}/api", user, pass
|
43
|
+
|
44
|
+
begin
|
45
|
+
raw = @rest['project/'].get(:params => {:name => project,
|
46
|
+
:owner__username => owner, :limit => 1})
|
47
|
+
|
48
|
+
obj = JSON.load(raw)['objects'][0]
|
49
|
+
@owner = obj['owner']
|
50
|
+
@project = obj['id']
|
51
|
+
rescue RestClient::Unauthorized
|
52
|
+
raise AuthenticationError.new "Invalid credentials given."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def resource res
|
57
|
+
@rest[res]
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_credentials options
|
61
|
+
user, pass = nil
|
62
|
+
|
63
|
+
if !options[:user].nil? && !options[:password].nil?
|
64
|
+
user, pass = [options[:user], options[:password]]
|
65
|
+
elsif File.exists?(prf = File.join(Etc.getpwuid.dir, ".wise", "profile"))
|
66
|
+
File.open(prf, "r") do |f|
|
67
|
+
user = f.readline.chomp
|
68
|
+
pass = f.readline.chomp
|
69
|
+
end
|
70
|
+
else
|
71
|
+
raise AuthenticationError.new "Credentials not given and profile not found."
|
72
|
+
end
|
73
|
+
|
74
|
+
return [user, pass]
|
75
|
+
end
|
76
|
+
|
77
|
+
def obj_id resource, obj
|
78
|
+
raw = @rest["#{resource}/"].get(:params => {:name => obj,
|
79
|
+
:ordering => '-created_at', :project => @project, :limit => 1})
|
80
|
+
resp = JSON.load(raw)['objects'][0]
|
81
|
+
|
82
|
+
raise ResourceError.new "Invalid #{resource} '#{obj}'." if resp.nil?
|
83
|
+
resp['id']
|
84
|
+
end
|
85
|
+
|
86
|
+
def model_id obj
|
87
|
+
case obj
|
88
|
+
when Integer
|
89
|
+
obj
|
90
|
+
when String
|
91
|
+
obj_id('model', obj)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def dataset_id dataset
|
96
|
+
obj_id('dataset', dataset)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/wise/project.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
=begin
|
2
|
+
---
|
3
|
+
Copyright (c) <2013>, <wise.io LLC>
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without modification,
|
7
|
+
are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
- Redistributions of source code must retain the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
19
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
21
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
22
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
23
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
24
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
=end
|
26
|
+
|
27
|
+
module Wise
|
28
|
+
# Creates a project handle for a wise.io project with the given path,
|
29
|
+
# yielding the project handle on succesful authentication; see
|
30
|
+
# Wise::Project.new for the supported options.
|
31
|
+
def self.project path, options = {} # :yields: project
|
32
|
+
p = Project.new path, options
|
33
|
+
yield p if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
class Project
|
37
|
+
# Creates a project handle for an existing wise.io project.
|
38
|
+
#
|
39
|
+
# === Parameters:
|
40
|
+
# [path] The project path (e.g. 'robin/quasars').
|
41
|
+
# [options] See below.
|
42
|
+
#
|
43
|
+
# === Options:
|
44
|
+
# [address] The base address to connect to; defaults to \https://wise.io.
|
45
|
+
# [user] Username used for authentication.
|
46
|
+
# [password] Password used for authentication.
|
47
|
+
# Note that user and password can be omitted if a wise.io profile is set up;
|
48
|
+
# if user and password are given as options, however, the profile is
|
49
|
+
# ignored.
|
50
|
+
def initialize path, options = {}
|
51
|
+
@client = Client.new path, options
|
52
|
+
end
|
53
|
+
|
54
|
+
# Makes predictions on a model in the project.
|
55
|
+
#
|
56
|
+
# === Parameters
|
57
|
+
# [model]
|
58
|
+
# The model label or id.
|
59
|
+
# [f]
|
60
|
+
# The data for the model to predict - this may take several forms:
|
61
|
+
# * If f is a *String* corresponding to a path to a file, the contents of
|
62
|
+
# the file is used as the input; this is expected to be in a CSV format
|
63
|
+
# compatible with the model.
|
64
|
+
# * If f is an open *File*, its contents is used as input as above.
|
65
|
+
# * If f is a *Hash*, it is interpreted as a selection. See {the
|
66
|
+
# selection API}[http://docs.wise.io/python.html#wise.project.select]
|
67
|
+
# for more information.
|
68
|
+
# [raw]
|
69
|
+
# If true, returns the result as raw CSV data rather than as an array.
|
70
|
+
#
|
71
|
+
# === Returns
|
72
|
+
# The predictions for the data as an array.
|
73
|
+
def predict model, f, raw = false
|
74
|
+
params = {}
|
75
|
+
|
76
|
+
if (f.is_a? String) && (File.exists? File.join(Dir.pwd, f))
|
77
|
+
data = File.read(f)
|
78
|
+
elsif (f.is_a? File) && !f.closed?
|
79
|
+
data = f.read
|
80
|
+
elsif (f.is_a? Hash) && !f[:dataset].nil?
|
81
|
+
dataset = f.delete(:dataset)
|
82
|
+
data = f.to_json
|
83
|
+
params = {:dataset_id => (@client.dataset_id dataset)}
|
84
|
+
else
|
85
|
+
data = f
|
86
|
+
end
|
87
|
+
|
88
|
+
m_id = @client.model_id model
|
89
|
+
resp = @client.resource("model/#{m_id}/predict").get(:payload => data,
|
90
|
+
:params => params)
|
91
|
+
raw ? resp : CSV.parse(resp)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/wise/version.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
=begin
|
2
|
+
---
|
3
|
+
Copyright (c) <2013>, <wise.io LLC>
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without modification,
|
7
|
+
are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
- Redistributions of source code must retain the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
19
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
21
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
22
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
23
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
24
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
=end
|
26
|
+
|
27
|
+
module Wise
|
28
|
+
VERSION = "0.1.1" # :nodoc:
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wise.io, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.7.7
|
41
|
+
description: A set of ruby bindings for communicating with the wise.io Machine Learning
|
42
|
+
as a Service platform.
|
43
|
+
email: contact@wise.io
|
44
|
+
executables:
|
45
|
+
- wise.rb
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files:
|
48
|
+
- README
|
49
|
+
files:
|
50
|
+
- lib/wise/client.rb
|
51
|
+
- lib/wise/project.rb
|
52
|
+
- lib/wise/version.rb
|
53
|
+
- lib/wise.rb
|
54
|
+
- ext/restclient-ext.rb
|
55
|
+
- bin/wise.rb
|
56
|
+
- LICENSE
|
57
|
+
- README
|
58
|
+
homepage: http://wise.io
|
59
|
+
licenses:
|
60
|
+
- See LICENSE.
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --title
|
65
|
+
- Wise.io for Ruby
|
66
|
+
- --main
|
67
|
+
- README
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.8.7
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Ruby client for the Wise.io platform.
|
86
|
+
test_files: []
|