From fd56ea2ce1ae2568e1664f5cf0920cea5203450b Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 28 Nov 2004 05:03:29 +0000 Subject: [PATCH] * src/plugins/PatchNames.py: add the ability to detect common surname prefixes * src/plugins/patchnames.glade: clean up description * src/plugins/TimeLine.py: detect invalid date range in report to prevent divide by zero error. svn: r3760 --- ChangeLog | 5 +++ src/plugins/PatchNames.py | 77 ++++++++++++++++++++++++++++++++++-- src/plugins/TimeLine.py | 7 ++++ src/plugins/patchnames.glade | 2 +- 4 files changed, 86 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 30771d045..4149b2503 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ 2004-11-27 Don Allingham + * src/plugins/PatchNames.py: add the ability to detect + common surname prefixes + * src/plugins/patchnames.glade: clean up description + * src/plugins/TimeLine.py: detect invalid date range in + report to prevent divide by zero error. * src/gramps.glade: add privacy fields and fix add/edit/remove buttons * src/Sources.py: add support for privacy flags diff --git a/src/plugins/PatchNames.py b/src/plugins/PatchNames.py index d801dba73..cc7454438 100644 --- a/src/plugins/PatchNames.py +++ b/src/plugins/PatchNames.py @@ -53,9 +53,20 @@ from gettext import gettext as _ # constants # #------------------------------------------------------------------------- + +prefix_list = [ + "de", "van", "von", "di", "le", "du", "dela", "della", + "des", "vande", "ten", "da", "af", "den", "das", "dello", + "del", "en", "ein", "el" "et", "les", "lo", "los", "un", + "um", "una", "uno", + ] + + _title_re = re.compile(r"^([A-Za-z][A-Za-z]+\.)\s+(.*)$") _nick_re = re.compile(r"(.+)\s*[(\"](.*)[)\"]") - +_fn_prefix_re = re.compile("(.*)\s+(%s)\s*$" % '|'.join(prefix_list),re.IGNORECASE) +_sn_prefix_re = re.compile("^\s*(%s)\s+(.*)" % '|'.join(prefix_list),re.IGNORECASE) + #------------------------------------------------------------------------- # # Search each name in the database, and compare the firstname against the @@ -86,21 +97,35 @@ class PatchNames: self.child_windows = {} self.title_list = [] self.nick_list = [] + self.prefix1_list = [] + self.prefix2_list = [] for key in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(key) first = person.get_primary_name().get_first_name() + sname = person.get_primary_name().get_surname() match = _title_re.match(first) if match: groups = match.groups() self.title_list.append((key,groups[0],groups[1])) + continue match = _nick_re.match(first) if match: groups = match.groups() self.nick_list.append((key,groups[0],groups[1])) + continue + match = _fn_prefix_re.match(first) + if match: + groups = match.groups() + self.prefix1_list.append((key,groups[0],groups[1])) + continue + match = _sn_prefix_re.match(sname) + if match: + groups = match.groups() + self.prefix2_list.append((key,groups[1],groups[0])) - if self.nick_list or self.title_list: + if self.nick_list or self.title_list or self.prefix1_list or self.prefix2_list: self.display() else: OkDialog(_('No modifications made'), @@ -153,6 +178,8 @@ class PatchNames: self.nick_hash = {} self.title_hash = {} + self.prefix1_hash = {} + self.prefix2_hash = {} for (id,name,nick) in self.nick_list: p = self.db.get_person_from_handle(id) @@ -176,6 +203,28 @@ class PatchNames: self.model.set_value(handle,4,p.get_primary_name().get_name()) self.title_hash[id] = handle + for (id,prefix,fname) in self.prefix1_list: + p = self.db.get_person_from_handle(id) + gid = p.get_gramps_id() + handle = self.model.append() + self.model.set_value(handle,0,1) + self.model.set_value(handle,1,gid) + self.model.set_value(handle,2,_('Prefix')) + self.model.set_value(handle,3,fname) + self.model.set_value(handle,4,p.get_primary_name().get_name()) + self.prefix1_hash[id] = handle + + for (id,prefix,fname) in self.prefix2_list: + p = self.db.get_person_from_handle(id) + gid = p.get_gramps_id() + handle = self.model.append() + self.model.set_value(handle,0,1) + self.model.set_value(handle,1,gid) + self.model.set_value(handle,2,_('Prefix')) + self.model.set_value(handle,3,fname) + self.model.set_value(handle,4,p.get_primary_name().get_name()) + self.prefix2_hash[id] = handle + self.add_itself_to_menu() self.window.show() @@ -221,6 +270,26 @@ class PatchNames: name.set_title(grp[1].strip()) self.db.commit_person(p,self.trans) + for grp in self.prefix1_list: + handle = self.prefix1_hash[grp[0]] + val = self.model.get_value(handle,0) + if val: + p = self.db.get_person_from_handle(grp[0]) + name = p.get_primary_name() + name.set_first_name(grp[1].strip()) + name.set_surname_prefix(grp[2].strip()) + self.db.commit_person(p,self.trans) + + for grp in self.prefix2_list: + handle = self.prefix2_hash[grp[0]] + val = self.model.get_value(handle,0) + if val: + p = self.db.get_person_from_handle(grp[0]) + name = p.get_primary_name() + name.set_surname(grp[1].strip()) + name.set_surname_prefix(grp[2].strip()) + self.db.commit_person(p,self.trans) + self.db.transaction_commit(self.trans,_("Extract information from names")) self.close(obj) self.cb(1) @@ -237,6 +306,6 @@ register_tool( _("Extract information from names"), category=_("Database Processing"), description=_("Searches the entire database and attempts to " - "extract titles and nicknames that may be embedded " - "in a person's given name field.") + "extract titles, nicknames and surname prefixes ", + "that may be embedded in a person's given name field.") ) diff --git a/src/plugins/TimeLine.py b/src/plugins/TimeLine.py index 56fc91ed8..68023d9b9 100644 --- a/src/plugins/TimeLine.py +++ b/src/plugins/TimeLine.py @@ -157,6 +157,13 @@ class TimeLine: (low,high) = self.find_year_range() + if low == high: + if self.standalone: + self.d.close() + ErrorDialog(_("Report could not be created"), + _("The range of dates chosen was not valid")) + return + st_size = self.name_size() font = self.d.style_list['TLG-Name'].get_font() diff --git a/src/plugins/patchnames.glade b/src/plugins/patchnames.glade index 043adef55..5ffee75a5 100644 --- a/src/plugins/patchnames.glade +++ b/src/plugins/patchnames.glade @@ -51,7 +51,7 @@ True - Below is a list of the nicknames and titles that GRAMPS can extract from the + Below is a list of the nicknames, titles and family name prefixes that GRAMPS can extract from the current database. If you accept the changes, GRAMPS will modify the entries that have been selected. False