Match alternative names in HasPlace filter
This commit is contained in:
parent
84bde16850
commit
6af8fe607f
@ -90,7 +90,16 @@ class HasPlace(Rule):
|
||||
Check each location for a match.
|
||||
"""
|
||||
for place_type, field in self.TYPE2FIELD.items():
|
||||
name = location.get(place_type, '')
|
||||
if not self.match_substring(field, name):
|
||||
name_list = location.get(place_type, [''])
|
||||
if not self.match_name(field, name_list):
|
||||
return False
|
||||
return True
|
||||
|
||||
def match_name(self, field, name_list):
|
||||
"""
|
||||
Match any name in a list of names.
|
||||
"""
|
||||
for name in name_list:
|
||||
if self.match_substring(field, name):
|
||||
return True
|
||||
return False
|
||||
|
@ -321,6 +321,15 @@ class Place(CitationBase, NoteBase, MediaBase, UrlBase, PrimaryObject):
|
||||
"""
|
||||
return self.name
|
||||
|
||||
def get_all_names(self):
|
||||
"""
|
||||
Return a list of all names of the Place object.
|
||||
|
||||
:returns: Returns a list of all names of the Place
|
||||
:rtype: list
|
||||
"""
|
||||
return [self.name] + self.alt_names
|
||||
|
||||
def set_longitude(self, longitude):
|
||||
"""
|
||||
Set the longitude of the Place object.
|
||||
|
@ -64,14 +64,14 @@ def get_locations(db, place):
|
||||
containing dictionaries of place types and names.
|
||||
"""
|
||||
locations = []
|
||||
todo = [(place, [(int(place.get_type()), place.get_name())])]
|
||||
todo = [(place, [(int(place.get_type()), place.get_all_names())])]
|
||||
while len(todo):
|
||||
place, tree = todo.pop()
|
||||
if len(place.get_placeref_list()):
|
||||
for parent in place.get_placeref_list():
|
||||
parent_place = db.get_place_from_handle(parent.ref)
|
||||
parent_tree = tree + [(int(parent_place.get_type()),
|
||||
parent_place.get_name())]
|
||||
parent_place.get_all_names())]
|
||||
todo.append((parent_place, parent_tree))
|
||||
else:
|
||||
locations.append(dict(tree))
|
||||
|
Loading…
Reference in New Issue
Block a user