Widen the recognizer capabilities for names

This commit is contained in:
Philip Sargent 2022-10-09 02:29:53 +03:00
parent 235bd86af3
commit 3c31c333f2
3 changed files with 88 additions and 48 deletions

View File

@ -182,5 +182,11 @@ def aliases(request, year):
persons = Person.objects.all()
aliasdict = GetPersonExpeditionNameLookup(expo)
res = aliasdict
# invert
invert ={}
for p in res:
invert[res[p]].append(p)
return render(request,'aliases.html', {'year': year, 'aliasdict': aliasdict,'personexpeditions': personexpeditions, 'persons': persons})
return render(request,'aliases.html', {'year': year, 'aliasdict': aliasdict, 'invert': invert,'personexpeditions': personexpeditions, 'persons': persons})

View File

@ -126,11 +126,6 @@ def load_people_expos():
save_carefully(PersonExpedition, lookupAttribs, nonLookupAttribs)
print("", flush=True)
# used in other referencing parser functions
# expedition name lookup cached for speed (it's a very big list)
# should have a LIST of nicknames, just populate the first entry from folk.csv
def who_is_this(year,possibleid):
expo = Expedition.objects.filter(year=year)
personexpedition = GetPersonExpeditionNameLookup(expo)[possibleid.lower()]
@ -145,7 +140,23 @@ def who_is_this(year,possibleid):
Gpersonexpeditionnamelookup = { }
def GetPersonExpeditionNameLookup(expedition):
global Gpersonexpeditionnamelookup
def apply_variations(f, l):
f = f.lower()
l = l.lower()
variations = []
variations.append(f)
variations.append(l)
variations.append(f + " " + l)
variations.append(f + " " + l[0])
variations.append(f + l[0])
variations.append(f[0] + " " + l)
variations.append(f[0] + l)
variations.append(f[0] + l[0]) # initials e.g. gb or bl
return variations
res = Gpersonexpeditionnamelookup.get(expedition.name)
if res:
return res
@ -161,47 +172,62 @@ def GetPersonExpeditionNameLookup(expedition):
f = unidecode(unescape(personexpedition.person.first_name.lower()))
l = unidecode(unescape(personexpedition.person.last_name.lower()))
full = unidecode(unescape(personexpedition.person.fullname.lower()))
if l:
possnames.append(f + " " + l)
possnames.append(f + " " + l[0])
possnames.append(f + l[0])
possnames.append(f[0] + " " + l)
possnames.append(f[0] + l[0]) # initials e.g. gb or bl
possnames.append(f)
# But these aliases do not take advantage of the variations above
if f'{f} {l}' == "Phil Underwood":
possnames.append("Phil Underpants")
if f'{f} {l}' == "Naomi Griffiths":
possnames.append("Naomi Makin")
if f'{f} {l}' == "Cat Hulse":
possnames.append("Catherine Hulse")
possnames.append("Cat Henry")
if f'{f} {l}' == "Jess Stirrups":
possnames.append("Jessica Stirrups")
if f'{f} {l}' == "Nat Dalton":
possnames.append("Nathaniel Dalton")
lim = min(4, len(f)+1) # short form, e.g. Dan for Daniel. May be duplicate, e.g. several Dave
if f[:lim] not in short:
short[f[:lim]]= personexpedition
else:
dellist.append(f[:lim])
n = unidecode(unescape(personexpedition.nickname.lower()))
if full not in possnames:
possnames.append(full)
if personexpedition.nickname not in possnames:
possnames.append(personexpedition.nickname.lower())
if l:
# This allows for nickname to be used for short name
# eg Phil S is adding Phil Sargent to the list
n = personexpedition.nickname.lower()
if str(n + " " + l) not in possnames:
possnames.append(n + " " + l)
if str(n + " " + l[0]) not in possnames:
possnames.append(n + " " + l[0])
if str(n + l[0]) not in possnames:
possnames.append(n + l[0])
if n not in possnames:
possnames.append(n)
if l:
possnames += apply_variations(f,l)
if n:
possnames += apply_variations(n, l)
if f == "Robert".lower():
possnames += apply_variations("Bob", l)
if f == "Andrew".lower():
possnames += apply_variations("Andy", l)
if f == "Andy".lower():
possnames += apply_variations("Andrew", l)
if f == "Michael".lower():
possnames += apply_variations("Mike", l)
if f == "David".lower():
possnames += apply_variations("Dave", l)
if f == "Peter".lower():
possnames += apply_variations("Pete", l)
if f == "Becka".lower():
possnames += apply_variations("Rebecca", l)
if f'{f} {l}' == "Andy Waddington".lower():
possnames += apply_variations("AER", "Waddington")
if f'{f} {l}' == "Phil Underwood".lower():
possnames += apply_variations("Phil", "Underpants")
if f'{f} {l}' == "Naomi Griffiths".lower():
possnames += apply_variations("Naomi", "Makin")
if f'{f} {l}' == "Cat Hulse".lower():
possnames += apply_variations("Catherine", "Hulse")
possnames += apply_variations("Cat", "Henry")
if f'{f} {l}' == "Jess Stirrups".lower():
possnames += apply_variations("Jessica", "Stirrups")
if f'{f} {l}' == "Nat Dalton".lower():
possnames += apply_variations("Nathaniel", "Dalton")
if f'{f} {l}' == "Mike Richardson".lower():
possnames.append("MTA")
possnames.append("Mike the Animal")
possnames.append("Animal")
if f'{f} {l}' == "Eric Landgraf".lower():
possnames.append("Eric C.Landgraf")
possnames.append("Eric C. Landgraf")
for i in [4, 5, 6]:
lim = min(i, len(f)+1) # short form, e.g. Dan for Daniel.
if f[:lim] not in short:
short[f[:lim]]= personexpedition
else:
dellist.append(f[:lim])
possnames = set(possnames) # remove duplicates
for possname in possnames:
if possname in res:
duplicates.add(possname)
@ -216,11 +242,8 @@ def GetPersonExpeditionNameLookup(expedition):
del short[possname]
for shortname in short:
res[shortname] = short[shortname]
print(f'{expedition.name}', end= ' ')
for n in res:
print(f'{n},', end= ' ')
print('')
Gpersonexpeditionnamelookup[expedition.name] = res
return res

View File

@ -26,6 +26,17 @@
</tr>
{% endfor %}
</table>
<table>
<tr><th>who</th><th>aliases</th></tr>
{% for key, value in invert.items %}
<tr>
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
{% endfor %}
</table>
<p>The aliases below are specified in the folk.csv file. Only one alias is possible in that format.
<table>
<tr><th>First</th><th>Last</th><th>Full name</th><th>Nickname</th><th>expo first</th><th>expo last</th></tr>