Finish Finnish date support
svn: r5176
This commit is contained in:
parent
e12a0862aa
commit
021141b84f
@ -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>
|
||||
* src/GraphLayout.py: use recursion limit to detect db loops
|
||||
* src/Utils.py: use recursion limit to detect db loops
|
||||
|
@ -119,6 +119,7 @@ class DateParser:
|
||||
unicode(locale.nl_langinfo(locale.ABMON_12),_codeset).lower(): 12,
|
||||
}
|
||||
|
||||
# modifiers before the date
|
||||
modifier_to_int = {
|
||||
'before' : Date.MOD_BEFORE, 'bef' : Date.MOD_BEFORE,
|
||||
'bef.' : Date.MOD_BEFORE, 'after' : Date.MOD_AFTER,
|
||||
@ -127,6 +128,9 @@ class DateParser:
|
||||
'abt' : Date.MOD_ABOUT, 'circa' : 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 = {
|
||||
"tishri" : 1, "heshvan" : 2, "kislev" : 3,
|
||||
@ -239,6 +243,9 @@ class DateParser:
|
||||
self._mod_str = '(' + '|'.join(
|
||||
[ 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.
|
||||
# Otherwise, 'april 2000' would be matched as 'apr' + garbage ('il 2000')
|
||||
@ -264,6 +271,8 @@ class DateParser:
|
||||
re.IGNORECASE)
|
||||
self._modifier = re.compile('%s\s+(.*)' % self._mod_str,
|
||||
re.IGNORECASE)
|
||||
self._modifier_after = re.compile('(.*)\s+%s' % self._mod_after_str,
|
||||
re.IGNORECASE)
|
||||
self._abt2 = re.compile('<(.*)>',re.IGNORECASE)
|
||||
self._text = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?' % self._mon_str,
|
||||
re.IGNORECASE)
|
||||
@ -493,6 +502,7 @@ class DateParser:
|
||||
|
||||
On success, set the date and return 1. On failure return 0.
|
||||
"""
|
||||
# modifiers before the date
|
||||
match = self._modifier.match(text)
|
||||
if match:
|
||||
grps = match.groups()
|
||||
@ -503,6 +513,17 @@ class DateParser:
|
||||
else:
|
||||
date.set(qual,mod,cal,start)
|
||||
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)
|
||||
if match:
|
||||
grps = match.groups()
|
||||
|
@ -58,15 +58,18 @@ class DateParserFI(DateParser):
|
||||
modifier_to_int = {
|
||||
# examples:
|
||||
# - ennen 1.1.2005
|
||||
# - 1.1.2005 jälkeen
|
||||
# - noin 1.1.2005
|
||||
u'ennen' : 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'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\."]
|
||||
|
||||
@ -97,7 +100,7 @@ class DateParserFI(DateParser):
|
||||
# date, whitespace
|
||||
self._span = re.compile("(?P<start>.+)\s+(-)\s+(?P<stop>.+)",
|
||||
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)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -115,6 +118,8 @@ class DateDisplayFI(DateDisplay):
|
||||
u"(Islamilainen)")
|
||||
|
||||
_qual_str = ("", "arviolta", "laskettuna")
|
||||
|
||||
_bce_str = "%s ekr."
|
||||
|
||||
formats = (
|
||||
"VVVV-KK-PP (ISO)",
|
||||
@ -138,7 +143,7 @@ class DateDisplayFI(DateDisplay):
|
||||
# select numerical date format
|
||||
self.format = 1
|
||||
|
||||
if mod == Date.MOD_SPAN:
|
||||
if mod == Date.MOD_SPAN:
|
||||
d1 = self.display_cal[cal](start)
|
||||
d2 = self.display_cal[cal](date.get_stop_date())
|
||||
text = "%s - %s" % (d1, d2)
|
||||
@ -147,20 +152,19 @@ class DateDisplayFI(DateDisplay):
|
||||
if start[0] == 0 and start[1] == 0 and stop[0] == 0 and stop[1] == 0:
|
||||
d1 = self.display_cal[cal](start)
|
||||
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:
|
||||
d1 = self.display_cal[cal](start)
|
||||
d2 = self.display_cal[cal](stop)
|
||||
text = "%s ja %s väliltä" % (d1, d2)
|
||||
text = "%s ja %s välillä" % (d1, d2)
|
||||
else:
|
||||
text = self.display_cal[date.get_calendar()](start)
|
||||
if mod == Date.MOD_BEFORE:
|
||||
text = "ennen " + text
|
||||
elif mod == Date.MOD_AFTER:
|
||||
# kludge: should be actually after the date
|
||||
text = "jälkeen " + text
|
||||
if mod == Date.MOD_AFTER:
|
||||
text = text + " jälkeen"
|
||||
elif mod == Date.MOD_ABOUT:
|
||||
text = "noin " + text
|
||||
elif mod == Date.MOD_BEFORE:
|
||||
text = "ennen " + text
|
||||
|
||||
if qual:
|
||||
# prepend quality
|
||||
|
@ -9,9 +9,8 @@ pkgdata_PYTHON = \
|
||||
Date_de.py\
|
||||
Date_ru.py\
|
||||
Date_fr.py\
|
||||
Date_es.py
|
||||
|
||||
# Date_fi.py
|
||||
Date_es.py\
|
||||
Date_fi.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/dates
|
||||
pkgpythondir = @pkgpythondir@/dates
|
||||
|
Loading…
x
Reference in New Issue
Block a user