gedcom import export for new name structure

svn: r16022
This commit is contained in:
Benny Malengier 2010-10-22 14:20:01 +00:00
parent 920535e3f6
commit ee91b33a43
5 changed files with 58 additions and 66 deletions

View File

@ -456,39 +456,3 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, SourceBase, NoteBase,
return '%s /%s/' % (firstname, surname) return '%s /%s/' % (firstname, surname)
else: else:
return '%s /%s/ %s' % (firstname, surname, suffix) return '%s /%s/ %s' % (firstname, surname, suffix)
##
## #DEPRECATED METHODS
##
##
## def get_surname_prefix(self):
## """
## Return the prefix (or article) of a surname.
##
## The prefix is not used for sorting or grouping.
## """
## return self.prefix
##
## def set_surname_prefix(self, val):
## """
## Set the prefix (or article) of a surname.
##
## Examples of articles would be 'de' or 'van'.
## """
## self.prefix = val
##
## def get_patronymic(self):
## """Return the patronymic name for the Name instance."""
## return self.patronymic
##
## def set_patronymic(self, name):
## """Set the patronymic name for the Name instance."""
## self.patronymic = name
##
## def get_surname(self):
## """Return the surname (or last name) for the Name instance."""
## return self.surname
##
## def set_surname(self, name):
## """Set the surname (or last name) for the Name instance."""
## self.surname = name

View File

@ -185,7 +185,7 @@ class Surname(SecondaryObject):
"""Return if this surname is the primary surname""" """Return if this surname is the primary surname"""
return self.primary return self.primary
def set_primary(self, primary): def set_primary(self, primary=True):
"""Set if this surname is the primary surname.replace """Set if this surname is the primary surname.replace
Use :class:`~gen.lib.surname.SurnameBase` to set the primary surname Use :class:`~gen.lib.surname.SurnameBase` to set the primary surname
via :method:`~gen.lib.surname.SurnameBase.set_primary_surname` via :method:`~gen.lib.surname.SurnameBase.set_primary_surname`

View File

@ -498,13 +498,11 @@ class GedcomWriter(UpdateCallback):
""" """
Write the names associated with the person to the current level. Write the names associated with the person to the current level.
Since nicknames are now separate from the name structure, we search Since nicknames in version < 3.3 are separate from the name structure,
the attribute list to see if we can find a nickname. Because we do we search the attribute list to see if we can find a nickname.
not know the mappings, we just take the first nickname we find, and Because we do not know the mappings, we just take the first nickname
add it to the primary name. we find, and add it to the primary name.
If a nickname is present in the name structure, it has precedence
All other names are assumed to not have a nickname, even if other
nicknames exist in the attribute list.
""" """
nicknames = [ attr.get_value() for attr in person.get_attribute_list() nicknames = [ attr.get_value() for attr in person.get_attribute_list()
@ -1187,7 +1185,7 @@ class GedcomWriter(UpdateCallback):
elif date.get_text(): elif date.get_text():
self.__writeln(level, 'DATE', date.get_text()) self.__writeln(level, 'DATE', date.get_text())
def __person_name(self, name, nick): def __person_name(self, name, attr_nick):
""" """
n NAME <NAME_PERSONAL> {1:1} n NAME <NAME_PERSONAL> {1:1}
+1 NPFX <NAME_PIECE_PREFIX> {0:1} +1 NPFX <NAME_PIECE_PREFIX> {0:1}
@ -1202,13 +1200,21 @@ class GedcomWriter(UpdateCallback):
gedcom_name = name.get_gedcom_name() gedcom_name = name.get_gedcom_name()
firstname = name.get_first_name().strip() firstname = name.get_first_name().strip()
patron = name.get_patronymic().strip() surns = []
if patron: surprefs = []
firstname = "%s %s" % (firstname, patron) for surn in name.get_surname_list():
surname = name.get_surname().replace('/', '?') surns.append(surn.get_surname().replace('/', '?'))
surprefix = name.get_surname_prefix().replace('/', '?') if surn.get_connector():
#we store connector with the surname
surns[-1] = surns[-1] + ' ' + surn.get_connector()
surprefs.append(surn.get_prefix().replace('/', '?'))
surname = ', '.join(surns)
surprefix = ', '.join(surprefs)
suffix = name.get_suffix() suffix = name.get_suffix()
title = name.get_title() title = name.get_title()
nick = name.get_nick_name()
if nick.strip() == '':
nick = attr_nick
self.__writeln(1, 'NAME', gedcom_name) self.__writeln(1, 'NAME', gedcom_name)
@ -1218,7 +1224,6 @@ class GedcomWriter(UpdateCallback):
self.__writeln(2, 'SPFX', surprefix) self.__writeln(2, 'SPFX', surprefix)
if surname: if surname:
self.__writeln(2, 'SURN', surname) self.__writeln(2, 'SURN', surname)
if name.get_suffix(): if name.get_suffix():
self.__writeln(2, 'NSFX', suffix) self.__writeln(2, 'NSFX', suffix)
if name.get_title(): if name.get_title():

View File

@ -1672,16 +1672,25 @@ class GedcomParser(UpdateCallback):
match = SURNAME_RE.match(text) match = SURNAME_RE.match(text)
if match: if match:
#/surname/ extra, we assume extra is given name
names = match.groups() names = match.groups()
name.set_first_name(names[1].strip()) name.set_first_name(names[1].strip())
name.set_surname(names[0].strip()) surn = gen.lib.Surname()
surn.set_surname(names[0].strip())
surn.set_primary()
name.set_surname_list([surn])
else: else:
try: try:
names = NAME_RE.match(text).groups() names = NAME_RE.match(text).groups()
# given /surname/ extra, we assume extra is suffix
name.set_first_name(names[0].strip()) name.set_first_name(names[0].strip())
name.set_surname(names[2].strip()) surn = gen.lib.Surname()
surn.set_surname(names[2].strip())
surn.set_primary()
name.set_surname_list([surn])
name.set_suffix(names[4].strip()) name.set_suffix(names[4].strip())
except: except:
# something strange, set as first name
name.set_first_name(text.strip()) name.set_first_name(text.strip())
return name return name
@ -2781,7 +2790,7 @@ class GedcomParser(UpdateCallback):
sub_state.name = name sub_state.name = name
sub_state.level = 2 sub_state.level = 2
self.__parse_level(sub_state, self.name_parse_tbl, self.__undefined) self.__parse_level(sub_state, self.name_parse_tbl, self.__undefined)
def __person_object(self, line, state): def __person_object(self, line, state):
""" """
@ -3163,7 +3172,13 @@ class GedcomParser(UpdateCallback):
@param state: The current state @param state: The current state
@type state: CurrentState @type state: CurrentState
""" """
state.name.set_surname_prefix(line.data.strip()) if state.name.get_surname_list():
state.name.get_surname_list()[0].set_prefix(line.data.strip())
else:
surn = gen.lib.Surname()
surn.set_prefix(line.data.strip())
surn.set_primary()
state.name.set_surname_list([surn])
self.__skip_subordinate_levels(state.level+1) self.__skip_subordinate_levels(state.level+1)
def __name_surn(self, line, state): def __name_surn(self, line, state):
@ -3173,7 +3188,13 @@ class GedcomParser(UpdateCallback):
@param state: The current state @param state: The current state
@type state: CurrentState @type state: CurrentState
""" """
state.name.set_surname(line.data.strip()) if state.name.get_surname_list():
state.name.get_surname_list()[0].set_surname(line.data.strip())
else:
surn = gen.lib.Surname()
surn.set_surname(line.data.strip())
surn.set_primary()
state.name.set_surname_list([surn])
self.__skip_subordinate_levels(state.level+1) self.__skip_subordinate_levels(state.level+1)
def __name_marnm(self, line, state): def __name_marnm(self, line, state):
@ -3187,7 +3208,10 @@ class GedcomParser(UpdateCallback):
data = text.split() data = text.split()
if len(data) == 1: if len(data) == 1:
name = gen.lib.Name(state.person.primary_name) name = gen.lib.Name(state.person.primary_name)
name.set_surname(data[0].strip()) surn = gen.lib.Surname()
surn.set_surname(data[0].strip())
surn.set_primary()
name.set_surname_list([surn])
name.set_type(gen.lib.NameType.MARRIED) name.set_type(gen.lib.NameType.MARRIED)
state.person.add_alternate_name(name) state.person.add_alternate_name(name)
elif len(data) > 1: elif len(data) > 1:
@ -3202,8 +3226,12 @@ class GedcomParser(UpdateCallback):
@param state: The current state @param state: The current state
@type state: CurrentState @type state: CurrentState
""" """
if state.name.get_suffix() == "": if state.name.get_suffix() == "" or state.name.get_suffix() == line.data:
#suffix might be set before when parsing name string
state.name.set_suffix(line.data) state.name.set_suffix(line.data)
else:
#previously set suffix different, to not loose information, append
state.name.set_suffix(state.name.get_suffix() + ' ' + line.data)
self.__skip_subordinate_levels(state.level+1) self.__skip_subordinate_levels(state.level+1)
def __name_nick(self, line, state): def __name_nick(self, line, state):
@ -3213,10 +3241,7 @@ class GedcomParser(UpdateCallback):
@param state: The current state @param state: The current state
@type state: CurrentState @type state: CurrentState
""" """
attr = gen.lib.Attribute() state.name.set_nick_name(line.data.strip())
attr.set_type(gen.lib.AttributeType.NICKNAME)
attr.set_value(line.data)
state.person.add_attribute(attr)
self.__skip_subordinate_levels(state.level+1) self.__skip_subordinate_levels(state.level+1)
def __name_aka(self, line, state): def __name_aka(self, line, state):

View File

@ -77,6 +77,7 @@ prefix_list = [
"um", "una", "uno", "der", "ter", "te", "die", "um", "una", "uno", "der", "ter", "te", "die",
] ]
connector_list = ['e', 'y', ]
_title_re = re.compile(r"^ ([A-Za-z][A-Za-z]+\.) \s+ (.+) $", re.VERBOSE) _title_re = re.compile(r"^ ([A-Za-z][A-Za-z]+\.) \s+ (.+) $", re.VERBOSE)
_nick_re = re.compile(r"(.+) \s* [(\"] (.+) [)\"]", re.VERBOSE) _nick_re = re.compile(r"(.+) \s* [(\"] (.+) [)\"]", re.VERBOSE)
@ -308,10 +309,7 @@ class PatchNames(tool.BatchTool, ManagedWindow.ManagedWindow):
name = p.get_primary_name() name = p.get_primary_name()
name.set_first_name(grp[1].strip()) name.set_first_name(grp[1].strip())
nick_name = grp[2].strip() nick_name = grp[2].strip()
attr = gen.lib.Attribute() name.set_nick_name(nick_name)
attr.set_type(gen.lib.AttributeType.NICKNAME)
attr.set_value(nick_name)
p.add_attribute(attr)
self.db.commit_person(p, trans) self.db.commit_person(p, trans)
for grp in self.title_list: for grp in self.title_list: