Class: Veritable::Grouping
- Inherits:
-
Object
- Object
- Veritable::Grouping
- Includes:
- VeritableResource
- Defined in:
- lib/veritable/api.rb
Overview
Represents the resources associated with a grouping resource. Lets you get the status of a grouping and get information about discovered groups.
Attributes
-
column_id– the column id of this grouping -
state– the state of the grouping operation, one of["running", "succeeded", "failed"] -
running?–trueifstateis"running" -
succeeded?–+trueifstateis"succeeded" -
failed?–trueifstateis"failed"
Methods
-
update– refreshes the local representation of the grouping resource -
wait– blocks until the grouping succeeds or fails -
groups– gets an iterator over all groups in the grouping -
rows– get rows and confidence information for a particular group -
row– get group information for a particular row
See also: dev.priorknowledge.com/docs/client/ruby
Instance Method Summary collapse
-
#column_id ⇒ Object
The column id of this grouping.
-
#failed? ⇒ Boolean
trueifstateis"failed", otherwisefalse. -
#groups(opts = {'start' => nil, 'limit' => nil}) ⇒ Object
Gets all groups in the grouping.
-
#row(target_row, opts = {'return_data' => true}) ⇒ Object
Get group information for a particular row.
-
#rows(opts = {'group_id' => nil, 'return_data' => true, 'start' => nil, 'limit' => nil}) ⇒ Object
Get rows and confidence information for a particular group.
-
#running? ⇒ Boolean
trueifstateis"running", otherwisefalse. -
#state ⇒ Object
The state of the analysis.
-
#succeeded? ⇒ Boolean
trueifstateis"succeeded", otherwisefalse. -
#update ⇒ Object
Refreshes the local representation of the grouping.
-
#wait(max_time = nil, poll = 2) ⇒ Object
Blocks until the grouping succeeds or fails.
Methods included from Connection
#delete, #get, #initialize, #post, #put, #request
Methods included from VeritableObject
Instance Method Details
#column_id ⇒ Object
The column id of this grouping
1091 |
# File 'lib/veritable/api.rb', line 1091 def column_id; @doc['column_name']; end |
#failed? ⇒ Boolean
true if state is "failed", otherwise false
1105 |
# File 'lib/veritable/api.rb', line 1105 def failed?; state == 'failed'; end |
#groups(opts = {'start' => nil, 'limit' => nil}) ⇒ Object
Gets all groups in the grouping
Arguments
-
optsA Hash optionally containing the keys-
"start"– the group id from which the cursor should begin returning results. Defaults tonil, in which case the cursor will return result starting with the lexicographically first group id. -
"limit"– the total number of results to return (must be a Fixnum). Defaults tonil, in which case the number of results returned will not be limited.
-
Returns
A Veritable::Cursor. The cursor will return group ids in lexicographic order.
See also: dev.priorknowledge.com/docs/client/ruby
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 |
# File 'lib/veritable/api.rb', line 1151 def groups(opts={'start' => nil, 'limit' => nil}) update if running? if succeeded? return Cursor.new({'collection' => link('groups'), 'start' => opts['start'], 'limit' => opts['limit']}.update(@opts)) { |g| g['group_id'] } elsif running? raise VeritableError.new("Grouping on column #{column_id} is still running and not yet ready to return groups.") elsif failed? raise VeritableError.new("Grouping on column #{column_id} has failed and cannot return groups.") else raise VeritableError.new("Grouping -- Shouldn't be here -- please let us know at [email protected].") end end |
#row(target_row, opts = {'return_data' => true}) ⇒ Object
Get group information for a particular row.
Arguments
-
target_rowThe row hash of interest. The row hash must contain an _id field. All other fields will be ignored. -
optsA Hash optionally containing the keys-
"return_data"– If true, return row data values along with group assignment and confidence info (default: True).
-
Returns
A row data hash with group_id and confidence specified in the _group_id and _confidence keys respectively.
See also: dev.priorknowledge.com/docs/client/ruby
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 |
# File 'lib/veritable/api.rb', line 1212 def row(target_row, opts={'return_data' => true}) update if running? if succeeded? row_id = target_row['_id'] res = get(link('rows') +'/'+row_id, params={:return_data => opts['return_data']}) return res['row'] elsif running? raise VeritableError.new("Grouping on column #{column_id} is still running and not yet ready to return groups.") elsif failed? raise VeritableError.new("Grouping on column #{column_id} has failed and cannot return groups.") else raise VeritableError.new("Grouping -- Shouldn't be here -- please let us know at [email protected].") end end |
#rows(opts = {'group_id' => nil, 'return_data' => true, 'start' => nil, 'limit' => nil}) ⇒ Object
Get rows and confidence information for a particular group.
Arguments
-
optsA Hash optionally containing the keys-
"group_id"– The id of the group of interest. If nil (default), returns all rows in the table -
"return_data"– If true, return row data values along with group assignment and confidence info (default: True). -
"start"– the integer index from which the cursor should begin returning results. Defaults tonil, in which case the cursor will return result starting with the first row. -
"limit"– the total number of results to return (must be a Fixnum). Defaults tonil, in which case the number of rows returned will not be limited.
-
Returns
A Veritable::Cursor. The cursor will return rows from the group.
See also: dev.priorknowledge.com/docs/client/ruby
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 |
# File 'lib/veritable/api.rb', line 1179 def rows(opts={'group_id' => nil, 'return_data' => true, 'start' => nil, 'limit' => nil}) update if running? if succeeded? if not opts['group_id'].nil? collection = link('groups') + '/' + opts['group_id'].to_s else collection = link('rows') end return Cursor.new({'collection' => collection, 'start' => opts['start'], 'limit' => opts['limit'], 'extra_args' => {:return_data => opts['return_data']}}.update(@opts)) elsif running? raise VeritableError.new("Grouping on column #{column_id} is still running and not yet ready to return groups.") elsif failed? raise VeritableError.new("Grouping on column #{column_id} has failed and cannot return groups.") else raise VeritableError.new("Grouping -- Shouldn't be here -- please let us know at [email protected].") end end |
#running? ⇒ Boolean
true if state is "running", otherwise false
1099 |
# File 'lib/veritable/api.rb', line 1099 def running?; state == 'running'; end |
#state ⇒ Object
The state of the analysis
One of ["running", "succeeded", "failed"]
1096 |
# File 'lib/veritable/api.rb', line 1096 def state; @doc['state']; end |
#succeeded? ⇒ Boolean
true if state is "succeeded", otherwise false
1102 |
# File 'lib/veritable/api.rb', line 1102 def succeeded?; state == 'succeeded'; end |
#update ⇒ Object
Refreshes the local representation of the grouping
Returns
nil on success
See also: dev.priorknowledge.com/docs/client/ruby
1113 |
# File 'lib/veritable/api.rb', line 1113 def update; @doc = get(link('self')); nil; end |
#wait(max_time = nil, poll = 2) ⇒ Object
Blocks until the grouping succeeds or fails
Arguments
-
max_time– the maximum time to wait, in seconds. Default isnil, in which case the method will wait indefinitely. -
poll– the number of seconds to wait between polling the API server. Default is2.
Returns
nil on success.
See also: dev.priorknowledge.com/docs/client/ruby
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 |
# File 'lib/veritable/api.rb', line 1125 def wait(max_time=nil, poll=2) elapsed = 0 while running? sleep poll if not max_time.nil? elapsed += poll if elapsed > max_time raise VeritableError.new("Wait for grouping -- Maximum time of #{max_time} second exceeded.") end end update end end |