Finish Finnish date support

svn: r5176
This commit is contained in:
Eero Tamminen 2005-09-04 20:22:39 +00:00
parent e12a0862aa
commit 021141b84f
4 changed files with 46 additions and 15 deletions

View File

@ -1,3 +1,10 @@
2005-09-04 Eero Tamminen <eerot@sf>
* src/DateParser.py: Added support for modifiers being both
before and after a date
* src/dates/Date_fi.py: Completed first version of Finnish
date handling
* src/dates/Makefile.am: Install Date_fi.py
2005-09-03 Don Allingham <don@gramps-project.org> 2005-09-03 Don Allingham <don@gramps-project.org>
* src/GraphLayout.py: use recursion limit to detect db loops * src/GraphLayout.py: use recursion limit to detect db loops
* src/Utils.py: use recursion limit to detect db loops * src/Utils.py: use recursion limit to detect db loops

View File

@ -119,6 +119,7 @@ class DateParser:
unicode(locale.nl_langinfo(locale.ABMON_12),_codeset).lower(): 12, unicode(locale.nl_langinfo(locale.ABMON_12),_codeset).lower(): 12,
} }
# modifiers before the date
modifier_to_int = { modifier_to_int = {
'before' : Date.MOD_BEFORE, 'bef' : Date.MOD_BEFORE, 'before' : Date.MOD_BEFORE, 'bef' : Date.MOD_BEFORE,
'bef.' : Date.MOD_BEFORE, 'after' : Date.MOD_AFTER, 'bef.' : Date.MOD_BEFORE, 'after' : Date.MOD_AFTER,
@ -127,6 +128,9 @@ class DateParser:
'abt' : Date.MOD_ABOUT, 'circa' : Date.MOD_ABOUT, 'abt' : Date.MOD_ABOUT, 'circa' : Date.MOD_ABOUT,
'c.' : Date.MOD_ABOUT, 'around' : Date.MOD_ABOUT, 'c.' : Date.MOD_ABOUT, 'around' : Date.MOD_ABOUT,
} }
# in some languages some of above listed modifiers are after the date,
# in that case the subclass should put them into this dictionary instead
modifier_after_to_int = {}
hebrew_to_int = { hebrew_to_int = {
"tishri" : 1, "heshvan" : 2, "kislev" : 3, "tishri" : 1, "heshvan" : 2, "kislev" : 3,
@ -239,6 +243,9 @@ class DateParser:
self._mod_str = '(' + '|'.join( self._mod_str = '(' + '|'.join(
[ key.replace('.','\.') for key in self.modifier_to_int.keys() ] [ key.replace('.','\.') for key in self.modifier_to_int.keys() ]
) + ')' ) + ')'
self._mod_after_str = '(' + '|'.join(
[ key.replace('.','\.') for key in self.modifier_after_to_int.keys() ]
) + ')'
# Need to reverse-sort the keys, so that April matches before Apr does. # Need to reverse-sort the keys, so that April matches before Apr does.
# Otherwise, 'april 2000' would be matched as 'apr' + garbage ('il 2000') # Otherwise, 'april 2000' would be matched as 'apr' + garbage ('il 2000')
@ -264,6 +271,8 @@ class DateParser:
re.IGNORECASE) re.IGNORECASE)
self._modifier = re.compile('%s\s+(.*)' % self._mod_str, self._modifier = re.compile('%s\s+(.*)' % self._mod_str,
re.IGNORECASE) re.IGNORECASE)
self._modifier_after = re.compile('(.*)\s+%s' % self._mod_after_str,
re.IGNORECASE)
self._abt2 = re.compile('<(.*)>',re.IGNORECASE) self._abt2 = re.compile('<(.*)>',re.IGNORECASE)
self._text = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?' % self._mon_str, self._text = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?' % self._mon_str,
re.IGNORECASE) re.IGNORECASE)
@ -493,6 +502,7 @@ class DateParser:
On success, set the date and return 1. On failure return 0. On success, set the date and return 1. On failure return 0.
""" """
# modifiers before the date
match = self._modifier.match(text) match = self._modifier.match(text)
if match: if match:
grps = match.groups() grps = match.groups()
@ -503,6 +513,17 @@ class DateParser:
else: else:
date.set(qual,mod,cal,start) date.set(qual,mod,cal,start)
return True return True
# modifiers after the date
match = self._modifier_after.match(text)
if match:
grps = match.groups()
start = self._parse_subdate(grps[0])
mod = self.modifier_after_to_int.get(grps[1].lower(),Date.MOD_NONE)
if bc:
date.set(qual,mod,cal,self.invert_year(start))
else:
date.set(qual,mod,cal,start)
return True
match = self._abt2.match(text) match = self._abt2.match(text)
if match: if match:
grps = match.groups() grps = match.groups()

View File

@ -58,15 +58,18 @@ class DateParserFI(DateParser):
modifier_to_int = { modifier_to_int = {
# examples: # examples:
# - ennen 1.1.2005 # - ennen 1.1.2005
# - 1.1.2005 jälkeen
# - noin 1.1.2005 # - noin 1.1.2005
u'ennen' : Date.MOD_BEFORE, u'ennen' : Date.MOD_BEFORE,
u'e.' : Date.MOD_BEFORE, u'e.' : Date.MOD_BEFORE,
u'jälkeen' : Date.MOD_AFTER,
u'j.' : Date.MOD_AFTER,
u'noin' : Date.MOD_ABOUT, u'noin' : Date.MOD_ABOUT,
u'n.' : Date.MOD_ABOUT, u'n.' : Date.MOD_ABOUT,
} }
modifier_after_to_int = {
# examples:
# - 1.1.2005 jälkeen
u'jälkeen' : Date.MOD_AFTER,
u'j.' : Date.MOD_AFTER,
}
bce = ["ekr", "ekr\."] bce = ["ekr", "ekr\."]
@ -97,7 +100,7 @@ class DateParserFI(DateParser):
# date, whitespace # date, whitespace
self._span = re.compile("(?P<start>.+)\s+(-)\s+(?P<stop>.+)", self._span = re.compile("(?P<start>.+)\s+(-)\s+(?P<stop>.+)",
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+väliltä", self._range = re.compile("(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+välillä",
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -116,6 +119,8 @@ class DateDisplayFI(DateDisplay):
_qual_str = ("", "arviolta", "laskettuna") _qual_str = ("", "arviolta", "laskettuna")
_bce_str = "%s ekr."
formats = ( formats = (
"VVVV-KK-PP (ISO)", "VVVV-KK-PP (ISO)",
"PP.KK.VVVV" "PP.KK.VVVV"
@ -147,20 +152,19 @@ class DateDisplayFI(DateDisplay):
if start[0] == 0 and start[1] == 0 and stop[0] == 0 and stop[1] == 0: if start[0] == 0 and start[1] == 0 and stop[0] == 0 and stop[1] == 0:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](stop) d2 = self.display_cal[cal](stop)
text = "vuosien %s ja %s väliltä" % (d1, d2) text = "vuosien %s ja %s välillä" % (d1, d2)
else: else:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](stop) d2 = self.display_cal[cal](stop)
text = "%s ja %s väliltä" % (d1, d2) text = "%s ja %s välillä" % (d1, d2)
else: else:
text = self.display_cal[date.get_calendar()](start) text = self.display_cal[date.get_calendar()](start)
if mod == Date.MOD_BEFORE: if mod == Date.MOD_AFTER:
text = "ennen " + text text = text + " jälkeen"
elif mod == Date.MOD_AFTER:
# kludge: should be actually after the date
text = "jälkeen " + text
elif mod == Date.MOD_ABOUT: elif mod == Date.MOD_ABOUT:
text = "noin " + text text = "noin " + text
elif mod == Date.MOD_BEFORE:
text = "ennen " + text
if qual: if qual:
# prepend quality # prepend quality

View File

@ -9,9 +9,8 @@ pkgdata_PYTHON = \
Date_de.py\ Date_de.py\
Date_ru.py\ Date_ru.py\
Date_fr.py\ Date_fr.py\
Date_es.py Date_es.py\
Date_fi.py
# Date_fi.py
pkgpyexecdir = @pkgpyexecdir@/dates pkgpyexecdir = @pkgpyexecdir@/dates
pkgpythondir = @pkgpythondir@/dates pkgpythondir = @pkgpythondir@/dates