<commit_before>require 'rubygems'
require 'net/http'
require 'open-uri'
require 'uri'
require 'nokogiri'

class Person
  attr_reader :name, :email

  def initialize(name)
    @name = name
    res = Net::HTTP.post_form(URI.parse('http://prod3.server.rpi.edu/peopledirectory/search.do'),
                        {'query'=>name.gsub(' ', ' AND '), 'datasetName' => 'directory', 'qct' => '10'})
    doc = Nokogiri::HTML(open(res['location']))
    people = doc.css('td.listingName a')
    top_hit = people[0]
    person_url = 'http://prod3.server.rpi.edu/peopledirectory/'+top_hit.attribute('href')
<commit_msg>Better name matching in search results<commit_after>require 'rubygems'
require 'net/http'
require 'open-uri'
require 'uri'
require 'nokogiri'

class Person
  attr_reader :name, :email

  def initialize(name)
    @name = name
    res = Net::HTTP.post_form(URI.parse('http://prod3.server.rpi.edu/peopledirectory/search.do'),
                        {'query'=>name.gsub(' ', ' AND '), 'datasetName' => 'directory', 'qct' => '10'})
    doc = Nokogiri::HTML(open(res['location']))
    people = doc.css('td.listingName a')
    top_hit = people.find do |person|
      first_name = name.split(' ')[0]
      last_name = name.split(' ')[1]
      person.content.match(/^#{last_name},\s*#{first_name}/)
    end
    raise "Person not found" unless top_hit
    person_url = 'http://prod3.server.rpi.edu/peopledirectory/'+top_hit.attribute('href')

{'fraction_non_alphanumeric': 0.17581653926337734, 'fraction_numerical': 0.007644197359277276, 'mean_word_length': 3.7058823529411766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4275879', 'n_tokens_mistral': 511, 'n_tokens_neox': 499, 'n_words': 93}