MCPcopy Index your code
hub / github.com/MoonInTheRiver/DiffSinger / Date

Class Date

utils/text_norm.py:503–558  ·  view source on GitHub ↗

DATE类

Source from the content-addressed store, hash-verified

501
502
503class Date:
504 """
505 DATE类
506 """
507
508 def __init__(self, date=None, chntext=None):
509 self.date = date
510 self.chntext = chntext
511
512 # def chntext2date(self):
513 # chntext = self.chntext
514 # try:
515 # year, other = chntext.strip().split('年', maxsplit=1)
516 # year = Digit(chntext=year).digit2chntext() + '年'
517 # except ValueError:
518 # other = chntext
519 # year = ''
520 # if other:
521 # try:
522 # month, day = other.strip().split('月', maxsplit=1)
523 # month = Cardinal(chntext=month).chntext2cardinal() + '月'
524 # except ValueError:
525 # day = chntext
526 # month = ''
527 # if day:
528 # day = Cardinal(chntext=day[:-1]).chntext2cardinal() + day[-1]
529 # else:
530 # month = ''
531 # day = ''
532 # date = year + month + day
533 # self.date = date
534 # return self.date
535
536 def date2chntext(self):
537 date = self.date
538 try:
539 year, other = date.strip().split('年', 1)
540 year = Digit(digit=year).digit2chntext() + '年'
541 except ValueError:
542 other = date
543 year = ''
544 if other:
545 try:
546 month, day = other.strip().split('月', 1)
547 month = Cardinal(cardinal=month).cardinal2chntext() + '月'
548 except ValueError:
549 day = date
550 month = ''
551 if day:
552 day = Cardinal(cardinal=day[:-1]).cardinal2chntext() + day[-1]
553 else:
554 month = ''
555 day = ''
556 chntext = year + month + day
557 self.chntext = chntext
558 return self.chntext
559
560

Callers 1

normalizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected