Created
March 14, 2012 14:10
-
-
Save rawrjustin/2036721 to your computer and use it in GitHub Desktop.
Framework to get started.
This file contains 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 "redis" | |
redis = Redis.new | |
INITIAL_FILE = ARGV[0] #the initial file | |
END_FILE = ARGV[1] #the end file | |
def listFriends(user, file) | |
key1 = file + ":" + user + ".to" | |
key2 = file + ":" + user + ".from" | |
return redis.sinter key1, key2 | |
end | |
def listStalkers(user) #unreciprocated followers, who's stalking you | |
key1 = file + ":" + user + ".to" | |
key2 = file + ":" + user + ".from" | |
return redis.sdiff key2, key1 | |
end | |
def listStalkees #unreciprocated follows, who you're stalking | |
key1 = file + ":" + user + ".to" | |
key2 = file + ":" + user + ".from" | |
return redis.sdiff key1, key2 | |
end | |
def listFansOfInterest(user1, user2, file) | |
key1 = file + ":" + user1 + ".to" | |
key2 = file + ":" + user2 + ".to" | |
return redis.sinter key1, key2 | |
end | |
################################################# | |
#START WRITING YOUR FEATURES HERE #ilovefeatures# | |
################################################# | |
def commonNeighbors(a, b) | |
return " not written yet, someone write this shit" | |
end | |
def Jaccard(a,b) | |
return " not written yet, someone write this shit" | |
end | |
def AdamicAdar(a,b) | |
return " not written yet, someone write this shit" | |
end | |
def Katz(a,b) | |
return " is a little bitch, someone write this shit" | |
end | |
def PageRank(a,b) | |
return " not written yet, someone write this shit" | |
end | |
def PrefAttach(a,b) | |
return " not written yet, someone write this shit" | |
end | |
if __FILE__ == $0 #main method | |
a = "first user" | |
b = "second user" | |
puts "Common Neighbors:" + commonNeighbors(a,b) | |
puts "Jaccard:" + Jaccard(a,b) | |
puts "Jaccard:" + Jaccard(a,b) | |
puts "Katz:" + Katz(a,b) | |
puts "PageRank:" + PageRank(a,b) | |
puts "Preferrential Attachment:" + PrefAttach(a,b) | |
end |
This file contains 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
#to account for only newly formed edges we might need to rethink this. | |
require "redis" | |
redis = Redis.new #create new redis instance with default port and localhost, make sure VM is on | |
FILE_IN = ARGV[0] #read in first cmdline argument (filename) | |
fileName = FILE_IN.split(".") #split filename from extension | |
f = File.new(FILE_IN) | |
f.each do |line| | |
lineArray = line.split | |
user = lineArray[0] | |
numValues = lineArray[2].to_i | |
if lineArray[1] == '0' | |
followKey = fileName[0] + ":" + user + ".to" | |
spamKey = fileName[0] + ":" + user + ".numAdded" | |
1.upto(numValues) { |i| redis.sadd followKey, lineArray[i+2] } #add values to the set of people user has added to his circle | |
redis.set spamKey, numValues #how many requests this user makes (is he a spammer?) | |
##IGNORING 1's UNLESS WE NEED THEM (SAVING SPACE) | |
=begin | |
else | |
followKey = fileName[0] + ":" + user + ".from" | |
popularityKey = fileName[0] + ":" + user + ".numAddedBy" | |
1.upto(numValues) { |i| redis.sadd followKey, lineArray[i+2] } #add values to the set of circles user has belongs to | |
redis.set popularityKey, numValues #how popular a user is (how many people have added) | |
end | |
=end | |
listOfUsersKey = fileName[0] + ".users" | |
redis.sadd listOfUsersKey, user #set of users for this particular snapshot (we only care about followbacks not new edges) | |
end | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment