Created
January 14, 2013 05:15
-
-
Save yannick/4527905 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #require 'set' | |
| infile = "facebook_users_to_youtube_ids_unique.gdf" | |
| outfile = "facebook_users_edges_youtube_network.gdf.part" | |
| users = Hash.new([]) | |
| youtube_ids = Hash.new([]) | |
| friendships = Hash.new([]) | |
| File.open(infile).each do |line| | |
| user_id, youtube_id = line.chomp.split(",") | |
| user_id = user_id.to_i | |
| users[user_id] = users[user_id] | [youtube_id] | |
| youtube_ids[youtube_id] = youtube_ids[youtube_id] | [user_id] | |
| end | |
| puts "found #{users.size} users and #{youtube_ids.size} youtube_ids" | |
| users.keys.each do |uid| | |
| users[uid].each do |ytid| | |
| (youtube_ids[ytid] - [uid]).each do |same_taste_friend_id| | |
| left_node, right_node = [uid,same_taste_friend_id].sort | |
| friendships[left_node] = friendships[left_node] | [right_node] | |
| end | |
| end | |
| end | |
| ofhandle = open(outfile, "w") | |
| puts "sorted #{friendships.count} friendships" | |
| friendships.each do |left_node, right_nodes| | |
| right_nodes.each do |right_node| | |
| ofhandle.puts( [left_node, right_node].sort.join(",")) | |
| end | |
| end | |
| ofhandle.close | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment