veritable 0.1.2.30 → 0.1.3.31

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,7 @@
1
+ veritable-ruby 0.1.3 - July 12, 2012
2
+ * Support for similar API call to retrieve rows similar to a target row
3
+ * Implemented count-batching for predictions
4
+
1
5
  veritable-ruby 0.1.2 - July 9, 2012
2
6
  * Added check for maximum count value (100000)
3
7
 
data/lib/veritable/api.rb CHANGED
@@ -554,8 +554,8 @@ module Veritable
554
554
  # Scores how related columns are to a column of interest
555
555
  #
556
556
  # ==== Arguments
557
- # * +column_id+ -- the id of the column of interest
558
- # * +start+ -- the column id from which to start the cursor. Columns with related scores greater than or equal to the score of column +start+ will be returned by the cursor. Default is +nil+, in which case all columns in the table will be returned by the cursor.
557
+ # * +column_id+ -- the name of the column of interest
558
+ # * +start+ -- the column name from which to start the cursor. Columns with related scores greater than or equal to the score of column +start+ will be returned by the cursor. Default is +nil+, in which case all columns in the table will be returned by the cursor.
559
559
  # * +limit+ -- optionally limits the number of columns returned by the cursor. Default is +nil+, in which case the number of columns returned will not be limited.
560
560
  #
561
561
  # ==== Returns
@@ -578,6 +578,45 @@ module Veritable
578
578
  end
579
579
  end
580
580
 
581
+ # Returns rows which are similar to a target row in the context
582
+ # of a particular column of interest.
583
+ #
584
+ # ==== Arguments
585
+ # * +row+ -- either a row '_id' string or a row hash corrsponding to the target row. If a row hash is provided, it must contain an '_id' key whose value is the '_id' of a row present in the table at the time of the analysis
586
+ # * +column_id+ -- the name of the column of interest.
587
+ # * +max_rows+ -- the maximum number of similar rows to return. Default is +10+. The actual number of similar rows returned will be less than or equal to max_rows.
588
+ # * +return_data+ -- if +true+, the full row content will be returned. If +false+, only the '_id' field for each row will be returned. Default is +true+.
589
+ #
590
+ # ==== Returns
591
+ # An array of row entries ordered from most similar to least similar.
592
+ # Each row entry is an array with the first element being the row and
593
+ # the second element being a relatedness score between 0 to 1.
594
+ #
595
+ # See also: https://dev.priorknowledge.com/docs/client/ruby
596
+ def similar_to(row, column_id, opts={:max_rows => 10, :return_data => true})
597
+ if row.is_a? String
598
+ row = {'_id' => row}
599
+ end
600
+ if not row.is_a? Hash
601
+ raise VeritableError.new("Similar -- Must provide an existing row to get similar!")
602
+ end
603
+ update if running?
604
+ if succeeded?
605
+ doc = post(link('similar'), {:data => row, :column => column_id,
606
+ :max_rows => 10, :return_data => true}.update(opts))
607
+ return doc['data']
608
+ elsif running?
609
+ raise VeritableError.new("Similar -- Analysis with id #{_id} is still running and not yet ready to calculate similar.")
610
+ elsif failed?
611
+ raise VeritableError.new("Similar -- Analysis with id #{_id} has failed and cannot calculate similar.")
612
+ else
613
+ raise VeritableError.new("Similar -- Shouldn't be here -- please let us know at support@priorknowledge.com.")
614
+ end
615
+ end
616
+
617
+
618
+
619
+
581
620
  # Returns a string representation of the analysis resource
582
621
  def inspect; to_s; end
583
622
 
@@ -618,16 +657,22 @@ module Veritable
618
657
 
619
658
  private
620
659
 
621
- def execute_batch(batch, count, preds)
660
+ def execute_batch(batch, count, preds, maxcells)
622
661
  if batch.size == 0
623
662
  return
624
663
  end
625
664
  if batch.size == 1
626
665
  data = batch[0]
666
+ ncols = (data.values.select {|v| v.nil?}).size
667
+ max_batch_count = (ncols == 0) ? count : (maxcells/ncols).to_i
668
+ res = []
669
+ while res.size < count do
670
+ batch_count = [max_batch_count, count - res.size].min
671
+ res = res + post(link('predict'), {'data' => data, 'count' => batch_count, 'return_fixed' => false})
672
+ end
627
673
  else
628
- data = batch
674
+ res = post(link('predict'), {'data' => batch, 'count' => count, 'return_fixed' => false})
629
675
  end
630
- res = post(link('predict'), {'data' => data, 'count' => count, 'return_fixed' => false})
631
676
  if not res.is_a? Array
632
677
  begin
633
678
  res.to_s
@@ -661,16 +706,15 @@ module Veritable
661
706
  if tcols > maxcols
662
707
  raise VeritableError.new("Predict -- Cannot predict for row #{row['_request_id']} with more than #{maxcols} combined fixed and predicted values.")
663
708
  end
664
- n = ncols * count
665
- if n > maxcells
666
- raise VeritableError.new("Predict -- Cannot predict for row #{row['_request_id']} with #{ncols} missing values and count #{count}: exceeds predicted cell limit of #{maxcells}.")
709
+ if ncols > maxcells
710
+ raise VeritableError.new("Predict -- Cannot predict for row #{row['_request_id']} with #{ncols} missing values: exceeds predicted cell limit of #{maxcells}.")
667
711
  end
668
712
  }
669
713
  rows.each {|row|
670
714
  ncols = (row.values.select {|v| v.nil?}).size
671
715
  n = ncols * count
672
716
  if (ncells + n) > maxcells
673
- execute_batch(batch, count, preds)
717
+ execute_batch(batch, count, preds, maxcells)
674
718
  ncells = n
675
719
  batch = [row]
676
720
  else
@@ -678,7 +722,7 @@ module Veritable
678
722
  ncells = ncells + n
679
723
  end
680
724
  }
681
- execute_batch(batch, count, preds)
725
+ execute_batch(batch, count, preds, maxcells)
682
726
  return preds
683
727
  else
684
728
  raise VeritableError.new("Predict -- Shouldn't be here -- please let us know at support@priorknowledge.com.")
@@ -1,5 +1,5 @@
1
1
  module Veritable
2
2
 
3
3
  # The current version of veritable-ruby
4
- VERSION = "0.1.2.30"
4
+ VERSION = "0.1.3.31"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veritable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.30
4
+ version: 0.1.3.31
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -173,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  segments:
175
175
  - 0
176
- hash: 810707972233102190
176
+ hash: 4376636797931241119
177
177
  required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  none: false
179
179
  requirements:
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  segments:
184
184
  - 0
185
- hash: 810707972233102190
185
+ hash: 4376636797931241119
186
186
  requirements: []
187
187
  rubyforge_project:
188
188
  rubygems_version: 1.8.24