Match alternative names in HasPlace filter
This commit is contained in:
parent
dd77bf74d5
commit
2578252d11
@ -90,7 +90,16 @@ class HasPlace(Rule):
|
|||||||
Check each location for a match.
|
Check each location for a match.
|
||||||
"""
|
"""
|
||||||
for place_type, field in self.TYPE2FIELD.items():
|
for place_type, field in self.TYPE2FIELD.items():
|
||||||
name = location.get(place_type, '')
|
name_list = location.get(place_type, [''])
|
||||||
if not self.match_substring(field, name):
|
if not self.match_name(field, name_list):
|
||||||
return False
|
return False
|
||||||
return True
|
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
|
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):
|
def set_longitude(self, longitude):
|
||||||
"""
|
"""
|
||||||
Set the longitude of the Place object.
|
Set the longitude of the Place object.
|
||||||
|
@ -64,14 +64,14 @@ def get_locations(db, place):
|
|||||||
containing dictionaries of place types and names.
|
containing dictionaries of place types and names.
|
||||||
"""
|
"""
|
||||||
locations = []
|
locations = []
|
||||||
todo = [(place, [(int(place.get_type()), place.get_name())])]
|
todo = [(place, [(int(place.get_type()), place.get_all_names())])]
|
||||||
while len(todo):
|
while len(todo):
|
||||||
place, tree = todo.pop()
|
place, tree = todo.pop()
|
||||||
if len(place.get_placeref_list()):
|
if len(place.get_placeref_list()):
|
||||||
for parent in place.get_placeref_list():
|
for parent in place.get_placeref_list():
|
||||||
parent_place = db.get_place_from_handle(parent.ref)
|
parent_place = db.get_place_from_handle(parent.ref)
|
||||||
parent_tree = tree + [(int(parent_place.get_type()),
|
parent_tree = tree + [(int(parent_place.get_type()),
|
||||||
parent_place.get_name())]
|
parent_place.get_all_names())]
|
||||||
todo.append((parent_place, parent_tree))
|
todo.append((parent_place, parent_tree))
|
||||||
else:
|
else:
|
||||||
locations.append(dict(tree))
|
locations.append(dict(tree))
|
||||||
|
Loading…
Reference in New Issue
Block a user