add local and historical variants for months

svn: r5628
This commit is contained in:
Jérôme Rapinat 2005-12-23 22:43:05 +00:00
parent e96641fa81
commit c43f8c61a5

View File

@ -48,64 +48,97 @@ from DateDisplay import DateDisplay
#-------------------------------------------------------------------------
class DateParserFR(DateParser):
month_to_int = DateParser.month_to_int
# Add common latin, local and historical variants (now only on east france)
month_to_int[u"januaris"] = 1
month_to_int[u"janer"] = 1
month_to_int[u"jenner"] = 1
month_to_int[u"hartmonat"] = 1
month_to_int[u"hartung"] = 1
month_to_int[u"eismond"] = 1
month_to_int[u"bluviose"] = 1
month_to_int[u"februaris"] = 2
month_to_int[u"hornung"] = 2
month_to_int[u"wintermonat"] = 2
month_to_int[u"taumond"] = 2
month_to_int[u"narrenmond"] = 2
month_to_int[u"vendose"] = 2
month_to_int[u"martius"] = 3
month_to_int[u"aprilis"] = 4
month_to_int[u"wiesenmonat"] = 5
month_to_int[u"maius"] = 5
month_to_int[u"junius"] = 6
month_to_int[u"julius"] = 7
month_to_int[u"augustus"] = 8
month_to_int[u"september"] = 9
month_to_int[u"7bre"] = 9
month_to_int[u"7bris"] = 9
month_to_int[u"october"] = 10
month_to_int[u"8bre"] = 10
month_to_int[u"8bris"] = 10
month_to_int[u"nebelmonat"] = 10
month_to_int[u"november"] = 11
month_to_int[u"9bre"] = 11
month_to_int[u"9bris"] = 11
month_to_int[u"december"] = 12
month_to_int[u"10bre"] = 12
month_to_int[u"10bris"] = 12
month_to_int[u"xbre"] = 12
month_to_int[u"xbris"] = 12
modifier_to_int = {
u'avant' : Date.MOD_BEFORE,
u'av.' : Date.MOD_BEFORE,
u'av' : Date.MOD_BEFORE,
u'après' : Date.MOD_AFTER,
u'avant' : Date.MOD_BEFORE,
u'av.' : Date.MOD_BEFORE,
u'av' : Date.MOD_BEFORE,
u'après' : Date.MOD_AFTER,
u'ap.' : Date.MOD_AFTER,
u'ap' : Date.MOD_AFTER,
u'env.' : Date.MOD_ABOUT,
u'env' : Date.MOD_ABOUT,
u'environ': Date.MOD_ABOUT,
u'circa' : Date.MOD_ABOUT,
u'c.' : Date.MOD_ABOUT,
u'vers' : Date.MOD_ABOUT,
}
calendar_to_int = {
u'grégorien' : Date.CAL_GREGORIAN,
u'grégorien' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'julien' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hébreu' : Date.CAL_HEBREW,
u'hébreu' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamique' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'révolutionnaire': Date.CAL_FRENCH,
u'révolutionnaire' : Date.CAL_FRENCH,
u'r' : Date.CAL_FRENCH,
u'perse' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'estimated' : Date.QUAL_ESTIMATED,
u'estimer' : Date.QUAL_ESTIMATED,
u'estimée' : Date.QUAL_ESTIMATED,
u'est.' : Date.QUAL_ESTIMATED,
u'est' : Date.QUAL_ESTIMATED,
u'environ' : Date.QUAL_ESTIMATED,
u'env' : Date.QUAL_ESTIMATED,
u'env.' : Date.QUAL_ESTIMATED,
u'calculer' : Date.QUAL_CALCULATED,
u'calculée' : Date.QUAL_CALCULATED,
u'calc.' : Date.QUAL_CALCULATED,
u'calc' : Date.QUAL_CALCULATED,
u'compter' : Date.QUAL_CALCULATED,
u'comptée' : Date.QUAL_CALCULATED,
u'compt' : Date.QUAL_CALCULATED,
u'compt.' : Date.QUAL_CALCULATED,
u'calculated' : Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
_span_1 = [u'de']
_span_2 = [u'à']
_range_1 = [u'ent.',u'ent',u'entre']
_range_2 = [u'et']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)),
re.IGNORECASE)
self._span = re.compile("(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)",re.IGNORECASE)
self._range = re.compile("(entre|ent|ent.)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)",re.IGNORECASE)
self._text2 =re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
re.IGNORECASE)
self._jtext2 =re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
re.IGNORECASE)
#-------------------------------------------------------------------------
#
@ -115,19 +148,68 @@ class DateParserFR(DateParser):
class DateDisplayFR(DateDisplay):
calendar = (
"", u" (Julien)", u" (Hébreu)",
"", u" (Julien)", u" (Hébreu)",
u" (Révolutionnaire)", u" (Perse)", u" (Islamique)"
)
_mod_str = ("",u"avant ",u"après ",u"vers ","","","")
_mod_str = ("",u"avant ",u"après ",u"vers ","environ ","circa ","")
_qual_str = ("","estimated ","calculated ")
_qual_str = ("","estimée ","calculée ","environ ")
formats = (
"AAAA-MM-DD (ISO)", "Numérique", "Mois Jour, Année",
"MOI Jour, Année", "Jour Mois, Année", "Jour MOIS Année"
)
def _display_gregorian(self,date_val):
year = self._slash_year(date_val[2],date_val[3])
if self.format == 0:
value = self.display_iso(date_val)
elif self.format == 1:
if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2])
else:
value = self._tformat.replace('%m',str(date_val[1]))
value = value.replace('%d',str(date_val[0]))
value = value.replace('%Y',str(date_val[2]))
elif self.format == 2:
# Month Day, Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._months[date_val[1]],year)
else:
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year)
elif self.format == 3:
# MON Day, Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._MONS[date_val[1]],year)
else:
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year)
elif self.format == 4:
# Day Month Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._months[date_val[1]],year)
else:
value = "%d. %s %s" % (date_val[0],self._months[date_val[1]],year)
else:
# Day MON Year
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s %s" % (self._MONS[date_val[1]],year)
else:
value = "%d. %s %s" % (date_val[0],self._MONS[date_val[1]],year)
return value
def display(self,date):
"""
Returns a text string representing the date.
@ -161,4 +243,4 @@ class DateDisplayFR(DateDisplay):
#
#-------------------------------------------------------------------------
from DateHandler import register_datehandler
register_datehandler(('fr_FR','fr','french'),DateParserFR, DateDisplayFR)
register_datehandler(('fr_FR','fr','french','fr_CA','fr_BE','fr_CH'),DateParserFR,DateDisplayFR)