lsh 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/lsh.rb +1 -0
  2. data/lib/lsh/index.rb +1 -1
  3. data/lib/lsh/web.rb +51 -0
  4. metadata +19 -2
data/lib/lsh.rb CHANGED
@@ -22,3 +22,4 @@ if RUBY_PLATFORM == 'java'
22
22
  else
23
23
  require_relative 'lsh/math_util_gsl.rb'
24
24
  end
25
+ require_relative 'lsh/web.rb'
@@ -150,7 +150,7 @@ module LSH
150
150
  end
151
151
 
152
152
  def inspect
153
- "#<LSH index; dimension: #{storage.parameters.dim}; window size: #{storage.parameters.window}; #{storage.parameters.number_of_random_vectors} random vectors; #{storage.parameters.number_of_independent_projections} independent projections>"
153
+ "#<LSH index; dimension: #{storage.parameters[:dim]}; window size: #{storage.parameters[:window]}; #{storage.parameters[:number_of_random_vectors]} random vectors; #{storage.parameters[:number_of_independent_projections]} independent projections>"
154
154
  end
155
155
 
156
156
  end
@@ -0,0 +1,51 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+ require 'time'
4
+
5
+ module LSH
6
+
7
+ class Web < Sinatra::Base
8
+
9
+ attr_reader :index
10
+
11
+ def initialize(index)
12
+ super
13
+ @index = index
14
+ end
15
+
16
+ get '/' do
17
+ content_type :json
18
+ { :index => index.inspect }.to_json
19
+ end
20
+
21
+ post '/query' do
22
+ raise "Missing query" unless params[:data]
23
+ mime_type = (params[:mime_type] || 'application/json')
24
+ if mime_type == 'application/json'
25
+ t0 = Time.now
26
+ vector = JSON.parse(params[:data])
27
+ results = index.query(vector)
28
+ content_type :json
29
+ { "time" => Time.now - t0, "results" => results }.to_json
30
+ else
31
+ raise "Unrecognised mime-type"
32
+ end
33
+ end
34
+
35
+ post '/index' do
36
+ raise "Missing data" unless params[:data]
37
+ mime_type = (params[:mime_type] || 'application/json')
38
+ if mime_type == 'application/json'
39
+ t0 = Time.now
40
+ vector = JSON.parse(params[:data])
41
+ index.add(vector)
42
+ content_type :json
43
+ { "time" => Time.now - t0, "status" => "indexed" }.to_json
44
+ else
45
+ raise "Unrecognised mime-type"
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lsh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
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: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gsl
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sinatra
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: An implementation of LSH in Ruby, using JBLAS for JRuby and GSL for MRI
63
79
  email: yves.raimond@bbc.co.uk
64
80
  executables: []
@@ -69,6 +85,7 @@ files:
69
85
  - lib/lsh/index.rb
70
86
  - lib/lsh/math_util_gsl.rb
71
87
  - lib/lsh/math_util_jblas.rb
88
+ - lib/lsh/web.rb
72
89
  - lib/lsh/storage/memory.rb
73
90
  - lib/lsh/storage/redis_backend.rb
74
91
  homepage: https://github.com/bbcrd/ruby-lsh