google-prediction 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/google-prediction.rb +32 -33
- metadata +37 -12
data/lib/google-prediction.rb
CHANGED
@@ -7,38 +7,37 @@
|
|
7
7
|
$:.unshift(File.dirname(__FILE__)) unless
|
8
8
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
9
9
|
|
10
|
-
require 'rubygems'
|
11
10
|
require 'curb'
|
12
11
|
require 'json'
|
13
12
|
|
14
13
|
module GooglePrediction
|
15
|
-
VERSION = '0.1.
|
14
|
+
VERSION = '0.1.1'
|
16
15
|
|
17
16
|
# = Usage
|
18
17
|
#
|
19
|
-
# auth_token = GooglePrediction.
|
18
|
+
# auth_token = GooglePrediction.get_auth_token('foo@gmail.com', 'password')
|
20
19
|
# => long string of letters and numbers
|
21
20
|
#
|
22
21
|
# predictor = GooglePrediction.new(auth_token, 'bucket', 'object')
|
23
22
|
#
|
24
|
-
# predictor.#
|
23
|
+
# predictor.#train
|
25
24
|
# => {"data"=>{"data"=>"bucket/object"}}
|
26
25
|
#
|
27
|
-
# predictor.#
|
26
|
+
# predictor.#check_training
|
28
27
|
# => "Training has not completed"
|
29
28
|
#
|
30
29
|
# wait_some_time
|
31
30
|
#
|
32
|
-
# predictor.#
|
31
|
+
# predictor.#check_training
|
33
32
|
# => "no estimate available" or something between "0.0" and "1.0"
|
34
33
|
#
|
35
|
-
# predictor.#
|
34
|
+
# predictor.#predict "awesome company"
|
36
35
|
# => "Google"
|
37
|
-
# predictor.#
|
36
|
+
# predictor.#predict "awesome nonprofit"
|
38
37
|
# => "InSTEDD"
|
39
|
-
# predictor.#
|
38
|
+
# predictor.#predict 13
|
40
39
|
# => "lucky"
|
41
|
-
# predictor.#
|
40
|
+
# predictor.#predict [3, 5, 7, 11]
|
42
41
|
# => "prime"
|
43
42
|
class GooglePrediction
|
44
43
|
PREDICTION_URL_PREFIX = 'https://www.googleapis.com/prediction/v1/training'
|
@@ -54,7 +53,7 @@ module GooglePrediction
|
|
54
53
|
# instructions at
|
55
54
|
# http://code.google.com/apis/predict/docs/getting-started.html
|
56
55
|
# and pass in the new URL and new arguments using the optional parameters.
|
57
|
-
def self.
|
56
|
+
def self.get_auth_token(email, password, url='https://www.google.com/accounts/ClientLogin', args={})
|
58
57
|
curl = Curl::Easy.new(url)
|
59
58
|
post_args = {
|
60
59
|
"accountType" => "HOSTED_OR_GOOGLE",
|
@@ -69,7 +68,7 @@ module GooglePrediction
|
|
69
68
|
curl.body_str.match('Auth.*')[0][5..-1]
|
70
69
|
end
|
71
70
|
|
72
|
-
# auth_code: the login code generated from self.
|
71
|
+
# auth_code: the login code generated from self.get_auth_token
|
73
72
|
#
|
74
73
|
# bucket: the name of the bucket in Google Storage
|
75
74
|
#
|
@@ -80,24 +79,6 @@ module GooglePrediction
|
|
80
79
|
@object=object
|
81
80
|
end
|
82
81
|
|
83
|
-
# Wrapper. Creates a new object and runs invoke_training on it.
|
84
|
-
def self.invoke_training(auth_code, bucket, object)
|
85
|
-
predictor = GooglePrediction.new(auth_code, bucket, object)
|
86
|
-
predictor.invoke_training
|
87
|
-
end
|
88
|
-
|
89
|
-
# Wrapper. Creates a new object and runs get_training_status on it.
|
90
|
-
def self.get_training_status(auth_code, bucket, object)
|
91
|
-
predictor = GooglePrediction.new(auth_code, bucket, object)
|
92
|
-
predictor.get_training_status
|
93
|
-
end
|
94
|
-
|
95
|
-
# Wrapper. Creates a new object and runs get_prediction on it.
|
96
|
-
def self.get_prediction(auth_code, bucket, object, submission)
|
97
|
-
predictor = GooglePrediction.new(auth_code, bucket, object)
|
98
|
-
predictor.get_prediction(submission)
|
99
|
-
end
|
100
|
-
|
101
82
|
# Starts training on the specified object.
|
102
83
|
#
|
103
84
|
# Returns
|
@@ -105,7 +86,7 @@ module GooglePrediction
|
|
105
86
|
# on success, and
|
106
87
|
# {"errors"=>{"errors"=>[{all of your errors}], "code"=>code, "message"=>message}}
|
107
88
|
# on error.
|
108
|
-
def
|
89
|
+
def train
|
109
90
|
url = PREDICTION_URL_PREFIX + "?data=" + @bucket + "%2F" + @object
|
110
91
|
curl = Curl::Easy.new(url)
|
111
92
|
curl.post_body = JSON.generate({:data => {}})
|
@@ -126,7 +107,7 @@ module GooglePrediction
|
|
126
107
|
# Returns
|
127
108
|
# {"errors"=>{"errors"=>[{all of your errors}], "code"=>code, "message"=>message}}
|
128
109
|
# on error.
|
129
|
-
def
|
110
|
+
def check_training
|
130
111
|
url = PREDICTION_URL_PREFIX + "/" + @bucket + "%2F" + @object
|
131
112
|
curl = Curl::Easy.new(url)
|
132
113
|
curl.headers = {"Authorization" => "GoogleLogin auth=#{@auth_code}"}
|
@@ -148,7 +129,7 @@ module GooglePrediction
|
|
148
129
|
# Returns the prediction on success and
|
149
130
|
# {"errors"=>{"errors"=>[{all of your errors}], "code"=>code, "message"=>message}}
|
150
131
|
# on error.
|
151
|
-
def
|
132
|
+
def predict(submission)
|
152
133
|
url = PREDICTION_URL_PREFIX + "/" + @bucket + "%2F" + @object + "/predict"
|
153
134
|
curl = Curl::Easy.new(url)
|
154
135
|
post_body = {:data => {:input => {}}}
|
@@ -174,6 +155,24 @@ module GooglePrediction
|
|
174
155
|
return response
|
175
156
|
end
|
176
157
|
|
158
|
+
# Wrapper. Creates a new object and runs #train on it.
|
159
|
+
def self.train(auth_code, bucket, object)
|
160
|
+
predictor = GooglePrediction.new(auth_code, bucket, object)
|
161
|
+
predictor.train
|
162
|
+
end
|
163
|
+
|
164
|
+
# Wrapper. Creates a new object and runs #check_training on it.
|
165
|
+
def self.check_training(auth_code, bucket, object)
|
166
|
+
predictor = GooglePrediction.new(auth_code, bucket, object)
|
167
|
+
predictor.check_training
|
168
|
+
end
|
169
|
+
|
170
|
+
# Wrapper. Creates a new object and runs #predict on it.
|
171
|
+
def self.predict(auth_code, bucket, object, submission)
|
172
|
+
predictor = GooglePrediction.new(auth_code, bucket, object)
|
173
|
+
predictor.predict(submission)
|
174
|
+
end
|
175
|
+
|
177
176
|
end
|
178
177
|
|
179
178
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-prediction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Sam King
|
@@ -14,24 +20,37 @@ default_executable:
|
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: curb
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 105
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 7
|
33
|
+
- 7
|
34
|
+
- 1
|
23
35
|
version: 0.7.7.1
|
24
|
-
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
25
38
|
- !ruby/object:Gem::Dependency
|
26
39
|
name: json
|
27
|
-
|
28
|
-
|
29
|
-
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
30
43
|
requirements:
|
31
44
|
- - ">="
|
32
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 1
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 4
|
50
|
+
- 3
|
33
51
|
version: 1.4.3
|
34
|
-
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
35
54
|
description: |-
|
36
55
|
Generates an auth token from a google account
|
37
56
|
Trains using the auth token and data uploaded to Google Storage for Developers
|
@@ -56,21 +75,27 @@ rdoc_options: []
|
|
56
75
|
require_paths:
|
57
76
|
- lib
|
58
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
59
79
|
requirements:
|
60
80
|
- - ">="
|
61
81
|
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
62
85
|
version: "0"
|
63
|
-
version:
|
64
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
65
88
|
requirements:
|
66
89
|
- - ">="
|
67
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
68
94
|
version: "0"
|
69
|
-
version:
|
70
95
|
requirements: []
|
71
96
|
|
72
97
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.3.
|
98
|
+
rubygems_version: 1.3.7
|
74
99
|
signing_key:
|
75
100
|
specification_version: 3
|
76
101
|
summary: Google Prediction API interface for Ruby.
|