-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_match.rb
More file actions
45 lines (38 loc) · 1.32 KB
/
image_match.rb
File metadata and controls
45 lines (38 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'neo4j'
require 'phashion'
require 'open-uri'
require 'parallel'
neo4j = Neo4j::Session.open(:server_db, 'http://localhost:7777')
def images_for(site)
Dir.glob("avatars/#{site}/*").select do |path|
File.size(path) > 0
end.map do |path|
[path, Phashion::Image.new(path)]
end
end
Parallel.each(images_for(:github), :in_processes=>4) do |github_avatar_path, github_img|
putc '-'
images_for(:stackoverflow).each do |stackoverflow_avatar_path, stackoverflow_img|
begin
if github_img.duplicate? stackoverflow_img
puts
puts "#{github_avatar_path} SAME AS #{stackoverflow_avatar_path}"
stackoverflow_user_id = File.basename(stackoverflow_avatar_path)
github_login = File.basename(github_avatar_path)
params = {
stackoverflow_user_id: stackoverflow_user_id.to_i,
github_login: github_login,
distance: github_img.distance_from(stackoverflow_img)
}
puts 'params', params.inspect
neo4j.query("MATCH
(sou:User:StackOverflow {user_id: {stackoverflow_user_id}}),
(ghu:User:GitHub {login: {github_login}})
MERGE sou-[r:SIMILAR_IMAGE_TO]->ghu
SET r.distance = {distance}", params)
end
rescue => e
raise e unless e.message == 'Unknown pHash error'
end
end
end