lsh 0.1.6-java → 0.2.0-java

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 +21 -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'
data/lib/lsh/index.rb CHANGED
@@ -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
data/lib/lsh/web.rb ADDED
@@ -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
@@ -2,14 +2,14 @@
2
2
  name: lsh
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.2.0
6
6
  platform: java
7
7
  authors:
8
8
  - Yves Raimond
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: jblas-ruby
@@ -65,6 +65,24 @@ dependencies:
65
65
  none: false
66
66
  prerelease: false
67
67
  type: :runtime
68
+ - !ruby/object:Gem::Dependency
69
+ name: sinatra
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: !binary |-
75
+ MA==
76
+ none: false
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: !binary |-
82
+ MA==
83
+ none: false
84
+ prerelease: false
85
+ type: :runtime
68
86
  description: An implementation of LSH in Ruby, using JBLAS for JRuby and GSL for MRI
69
87
  email: yves.raimond@bbc.co.uk
70
88
  executables: []
@@ -75,6 +93,7 @@ files:
75
93
  - lib/lsh/index.rb
76
94
  - lib/lsh/math_util_gsl.rb
77
95
  - lib/lsh/math_util_jblas.rb
96
+ - lib/lsh/web.rb
78
97
  - lib/lsh/storage/memory.rb
79
98
  - lib/lsh/storage/redis_backend.rb
80
99
  homepage: https://github.com/bbcrd/ruby-lsh