Module: GetRelated
- Included in:
- Linkedin::Profile, LinkedinData
- Defined in:
- lib/get_related.rb
Instance Method Summary collapse
-
#addPointsToProfile(profile_scores, data_item, person) ⇒ Object
Adds points to a profile for showing up in related people.
-
#downloadRelated(item, hop_count) ⇒ Object
Scrapes the related profiles for one result item.
-
#fullProfileList(data) ⇒ Object
Make list of profiles for score tracking.
-
#getList(html) ⇒ Object
Get the list of names of related people.
-
#getRelatedProfiles ⇒ Object
Get all profiles within numhops of original(s).
-
#relScore(data) ⇒ Object
Add a score to each profile based on the # of times it appears in “people also viewed”.
Instance Method Details
#addPointsToProfile(profile_scores, data_item, person) ⇒ Object
Adds points to a profile for showing up in related people
50 51 52 53 54 55 56 57 |
# File 'lib/get_related.rb', line 50 def addPointsToProfile(profile_scores, data_item, person) if profile_scores[person[:url]] # Calculate degree- (2/d*2) except when degree is 0 degree_divide = data_item[:degree] == 0 ? 1 : data_item[:degree]*2 profile_scores[person[:url]] += (2.0/degree_divide) end return profile_scores end |
#downloadRelated(item, hop_count) ⇒ Object
Scrapes the related profiles for one result item
30 31 32 33 34 35 36 37 |
# File 'lib/get_related.rb', line 30 def (item, hop_count) item[:related_people].each do || # Check if it has been scraped already if @output.select { |person| [:name] == person[:name] }.empty? scrape([:url], hop_count+1) end end end |
#fullProfileList(data) ⇒ Object
Make list of profiles for score tracking
41 42 43 44 45 46 47 |
# File 'lib/get_related.rb', line 41 def fullProfileList(data) profiles = Hash.new data.each do |d| profiles[d[:profile_url]] = 0 end return profiles end |
#getList(html) ⇒ Object
Get the list of names of related people
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/get_related.rb', line 3 def getList(html) namelist = Array.new # Save each person's name and url html.css("div.insights-browse-map").each do |d| if d.css("h3").text == "People Also Viewed" d.css("li").each do |l| namelist.push({name: l.css("h4").text, url: l.css("a")[0]['href']}) end end end return namelist end |
#getRelatedProfiles ⇒ Object
Get all profiles within numhops of original(s)
21 22 23 24 25 26 27 |
# File 'lib/get_related.rb', line 21 def @numhops.times do |hop_count| @output.select { |profile| profile[:degree] == hop_count }.each do |item| (item, hop_count) if item[:related_people] end end end |
#relScore(data) ⇒ Object
Add a score to each profile based on the # of times it appears in “people also viewed”
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/get_related.rb', line 60 def relScore(data) profile_scores = fullProfileList(data) # Get degree and calculate score for each profile data.each do |data_item| if data_item[:related_people] data_item[:related_people].each do |person| profile_scores = addPointsToProfile(profile_scores, data_item, person) end end end # Merge scores back into dataset data.each do |m| m.merge!(score: profile_scores[m[:profile_url]]) end return data end |