def calculate_name_score(query_string, nameids):
    '''
    docstring

    @param query_string:
    @type query_string:
    @param nameids:
    @type nameids:

    @return:
    @rtype:
    '''
    name_personids_list = get_authors_data_from_indexable_name_ids(nameids)
    query_last_name = split_name_parts(query_string)[0]
    query_last_name_len = len(query_last_name)
    name_score_list = list()

    for name, personids in name_personids_list:
        current_last_name = split_name_parts(name)[0]
        current_last_name_len = len(current_last_name)
        if abs(query_last_name_len - current_last_name_len) == 0:
            dist = distance(query_last_name, current_last_name)
            limit = min([query_last_name_len, current_last_name_len])
            name_score = sum([1/float(2**(i+1)) for i in range(limit) if query_last_name[i] == current_last_name[i]])/(dist + 1)
            if name_score > 0.5:
                name_score_list.append((name, name_score, deserialize(personids)))

    return name_score_list
Ejemplo n.º 2
0
def calculate_name_score(query_string, nameids):
    '''
    docstring

    @param query_string:
    @type query_string:
    @param nameids:
    @type nameids:

    @return:
    @rtype:
    '''
    name_personids_list = get_authors_data_from_indexable_name_ids(nameids)
    query_last_name = split_name_parts(query_string)[0]
    query_last_name_len = len(query_last_name)
    name_score_list = list()

    for name, personids in name_personids_list:
        current_last_name = split_name_parts(name)[0]
        current_last_name_len = len(current_last_name)
        if abs(query_last_name_len - current_last_name_len) == 0:
            dist = distance(query_last_name, current_last_name)
            limit = min([query_last_name_len, current_last_name_len])
            name_score = sum([
                1 / float(2**(i + 1)) for i in range(limit)
                if query_last_name[i] == current_last_name[i]
            ]) / (dist + 1)
            if name_score > 0.5:
                name_score_list.append(
                    (name, name_score, deserialize(personids)))

    return name_score_list
Ejemplo n.º 3
0
 def test_simple_distance(self):
     self.assertEqual(distance('aaaaa', 'aaaaa'), 0)
     self.assertEqual(distance('aaaaa', 'aa'), 3)
     self.assertEqual(distance('aaaaa', 'aaaab'), 1)
     self.assertEqual(distance('aaaaa', 'bbbbb'), 5)
     self.assertEqual(distance('eecbr', 'bbbbb'), 4)
 def test_simple_distance(self):
     self.assertEqual(distance('aaaaa','aaaaa'), 0)
     self.assertEqual(distance('aaaaa','aa'), 3)
     self.assertEqual(distance('aaaaa','aaaab'), 1)
     self.assertEqual(distance('aaaaa','bbbbb'), 5)
     self.assertEqual(distance('eecbr','bbbbb'), 4)