iskr 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/iskr.rb +266 -0
  2. metadata +67 -0
@@ -0,0 +1,266 @@
1
+ require "xmlrpc/client"
2
+
3
+ # ruby binding for isk v0.9.3
4
+ # not all function implemented
5
+ # 2012-02-06 cvigny
6
+
7
+ class Isk
8
+ # Make an object to represent the XML-RPC @server.
9
+
10
+ #default values
11
+ @@host = "solr1"
12
+ @@path = "/RPC"
13
+ @@port = 31128
14
+ @@db_id = 1
15
+
16
+ def initialize(db_id=@@db_id,host=@@host, path=@@path, port=@@port, proxy_host=nil, proxy_port=nil, user=nil, password=nil, use_ssl=nil, timeout=nil)
17
+ @db_id = db_id
18
+ @server = XMLRPC::Client.new( host, path,port,proxy_host,proxy_port,user,password,use_ssl,timeout)
19
+ end
20
+
21
+ def db_id
22
+ @db_id
23
+ end
24
+
25
+ # isk mapping
26
+
27
+ #queryImgID(dbId, id, numres=12, sketch=0, fast=False)
28
+ #
29
+ #
30
+ #Return the most similar images to the supplied one. The supplied image must be already indexed, and is referenced by its ID.
31
+ #
32
+ #Parameters:
33
+ #
34
+ # dbId (number) - Database space id.
35
+ # id (number) - Target image id.
36
+ # numres (number) - Number of results to return. The target image is on the result list.
37
+ # sketch (number) - 0 for photographs, 1 for hand-sketched images or low-resolution vector images.
38
+ # fast (boolean) - if true, only the average color for each image is considered. Image geometry/features are ignored. Search is faster this way.
39
+ #
40
+ #Returns: array
41
+ # array of arrays: [[image id 1, score],[image id 2, score],[image id 3, score], ...] (id is Integer, score is Double)
42
+ def query_img_id(id,numres=12, sketch=0, fast=false)
43
+ if is_img_on_db(id)
44
+ @server.call("queryImgID",db_id,id,numres,sketch,fast)
45
+ else
46
+ puts "not in image database #{id}"
47
+ end
48
+ end
49
+ def query_img_blob(data,numres=12, sketch=0, fast=False)
50
+ @server.call("queryImgBlob",db_id,data,numres,sketch,fast)
51
+ end
52
+ def query_img_path(path,numres=12, sketch=0, fast=False)
53
+ @server.call("queryImgPath",db_id,path,numres,sketch,fast)
54
+ end
55
+
56
+ def add_img_blog(id,data)
57
+ @server.call("addImgBlob",db_id, id, data)
58
+ end
59
+
60
+ # add image id et file
61
+ def add_img(id, file)
62
+ @server.call("addImg",db_id,id,file)
63
+ end
64
+
65
+ def save_db()
66
+ @server.call("saveDb",db_id)
67
+ end
68
+
69
+ def save_db_as(filename)
70
+ @server.call("saveDbAs",db_id, filename)
71
+ end
72
+
73
+ def load_db(id)
74
+ @server.call("loadDb",db_id, id, data)
75
+ end
76
+
77
+ def remove_img(id)
78
+ @server.call("removeImg",db_id,id)
79
+ end
80
+
81
+
82
+ def reset_db(id)
83
+ @server.call("resetDb",db_id)
84
+ end
85
+
86
+ def create_db()
87
+ @server.call("createDb",db_id)
88
+ end
89
+
90
+ def shutdown_server()
91
+ @server.call("shutdownServer")
92
+ end
93
+
94
+ # img count
95
+ def get_db_img_count
96
+ @server.call("getDbImgCount",db_id)
97
+ end
98
+
99
+ def is_img_on_db(id)
100
+ @server.call("isImgOnDb",db_id,id)
101
+ end
102
+
103
+ def get_img_dimensions(id)
104
+ @server.call("getImgDimensions",db_id,id)
105
+ end
106
+
107
+ def calc_img_avg_ldif(id1,id2)
108
+ @server.call("calcImgAvglDiff",db_id,id1,id2)
109
+ end
110
+
111
+ def cacl_img_diff(id1,id2)
112
+ @server.call("calcImgDiff",db_id,id1,id2)
113
+ end
114
+
115
+ def get_img_avgl(id)
116
+ @server.call("calcImgDiff",db_id,id)
117
+ end
118
+
119
+ def get_db_list
120
+ @server.call("getDbList")
121
+ end
122
+
123
+
124
+ def get_db_img_id_list
125
+ @server.call("getDbImgIdList",db_id)
126
+ end
127
+
128
+ def get_db_detailed_list
129
+ @server.call("getDbDetailedList",db_id)
130
+ end
131
+
132
+ def save_all_dbs_as(path)
133
+ @server.call("saveAllDbsAs",db_id)
134
+ end
135
+
136
+ def add_keyword_img(id,keyword)
137
+ @server.call("addKeywordImg",db_id,id,keyword)
138
+ end
139
+
140
+
141
+ # getAllImgsByKeywords(dbId, numres, kwJoinType, keywords)
142
+ #
143
+ #
144
+ #Return all images with the given keywords
145
+ #
146
+ #Parameters:
147
+ #
148
+ # dbId (number) - Database space id.
149
+ # kwJoinType (number) - Logical operator for target keywords: 1 for AND, 0 for OR
150
+ # keywords (string) - comma separated list of keyword ids. An empty string will return random images.
151
+ #
152
+ #Returns: array
153
+ # array of image ids
154
+
155
+ def get_all_imgs_by_keywords(numres,kwjointype,keywords)
156
+ @server.call("getAllImgsByKeywords",db_id,numres,kwjointype,keywords)
157
+ end
158
+
159
+ def query_img_id_fast_keywords(id,numers,kwjointype,keywords)
160
+ @server.call("queryImgIDFastKeywords",db_id,numres,kwjointype,keywords)
161
+ end
162
+ # queryImgIDKeywords(dbId, imgId, numres, kwJoinType, keywords)
163
+ #
164
+ #
165
+ #Query for similar images considering keywords. The input keywords are used for narrowing the search space.
166
+ #
167
+ #Parameters:
168
+ #
169
+ # dbId (number) - Database space id.
170
+ # imgId (number) - Target image id. If '0', random images containing the target keywords will be returned.
171
+ # numres (number) - Number of results desired
172
+ # kwJoinType (number) - logical operator for keywords: 1 for AND, 0 for OR
173
+ # keywords (string) - comma separated list of keyword ids.
174
+ #
175
+ #Returns: array
176
+ # array of arrays: [[image id 1, score],[image id 2, score],[image id 3, score], ...] (id is Integer, score is Double)
177
+
178
+
179
+ def query_img_id_keywords(id,numers,kwjointype,keywords)
180
+ @server.call("queryImgIDKeywords",db_id,numres,kwjointype,keywords)
181
+ end
182
+
183
+ #mostPopularKeywords(dbId, imgs, excludedKwds, count, mode)
184
+ #
185
+ #
186
+ #Returns the most frequent keywords associated with a given set of images
187
+ #
188
+ #Parameters:
189
+ #
190
+ # imgs (string) - Comma separated list of target image ids
191
+ # excludedKwds (string) - Comma separated list of keywords ids to be excluded from the frequency count
192
+ # mode (number) - ignored, will be used on future versions.
193
+ # dbId (number @param dbId Database space id.)
194
+ # count (number @param count Number of keyword results desired)
195
+ #
196
+ #Returns: array
197
+ # array of keyword ids and frequencies: [kwd1_id, kwd1_freq, kwd2_id, kwd2_freq, ...]
198
+ def most_popular_keywords(imgs,exclude_keywords,count,mode)
199
+ @server.call("mostPopularKeywords",db_id,imgs,exclude_keywords,count,mode)
200
+ end
201
+
202
+ def get_keywords_img(id)
203
+ @server.call("getKeywordsImg",db_id,id)
204
+ end
205
+
206
+ def remove_all_keyword_img(id)
207
+ @server.call("removeAllKeywordImg",db_id,id)
208
+ end
209
+
210
+ #addKeywordsImg(dbId, imgId, hashes)
211
+ #
212
+ #
213
+ #Associate keywords to image
214
+ #
215
+ #Parameters:
216
+ #
217
+ # dbId (number) - Database space id.
218
+ # imgId (number) - Target image id.
219
+ # hashes (list of number) - Keyword hashes to associate
220
+ #
221
+ #Returns: boolean
222
+ # true if image id exists
223
+ def add_keywords_img(id,hashes)
224
+ @server.call("addKeywordsImg",db_id,hashes)
225
+ end
226
+
227
+ def add_dir(path,recurse)
228
+ @server.call("addDir",db_id,path,recurse)
229
+ end
230
+
231
+ def load_all_dbs_as(path)
232
+ @server.call("loadAllDbs",path)
233
+ end
234
+
235
+ def save_all_dbs
236
+ @server.call("saveAllDbs")
237
+ end
238
+
239
+ def load_all_dbs
240
+ @server.call("loadAllDbs")
241
+ @load_all_dbs = true
242
+ end
243
+
244
+ def remove_db()
245
+ @server.call("removeDb")
246
+ end
247
+
248
+
249
+ def get_global_server_stat
250
+ @server.call("getGlobalServerStats")
251
+ end
252
+
253
+ def is_valid_db()
254
+ @server.call("isValidDb",db_id)
255
+ end
256
+
257
+ def get_isk_log(window=30)
258
+ @server.call("getIskLog",window)
259
+ end
260
+
261
+
262
+
263
+
264
+
265
+
266
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iskr
3
+ version: !ruby/object:Gem::Version
4
+ hash: 59
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
+ platform: ruby
12
+ authors:
13
+ - Christophe Vigny
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-07 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: simple ruby mapper for isk-daemon, isk daemon search image with similarity http://www.imgseek.net/isk-daemon
23
+ email: cvigny@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/iskr.rb
32
+ has_rdoc: true
33
+ homepage: https://github.com/tophe/iskr
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.7
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: simple ruby mapper for isk-daemon
66
+ test_files: []
67
+