def make_annotation_from_pattrn(self, locale: str, ptrn: PatternFound,
                                 phrase: LineOrPhrase) -> TextAnnotation:
     ant = CopyrightAnnotation(name=ptrn.name,
                               coords=(ptrn.start, ptrn.end),
                               text=phrase.text[ptrn.start:ptrn.end],
                               locale=locale)
     ant.company = ptrn.company  # pattern in in fact CopyrightPatternFound
     ant.year_start = ptrn.start_year
     ant.year_end = ptrn.end_year
     return ant
    def split_copyright_date(cls, ant: CopyrightAnnotation) -> None:
        if not ant.date:
            return
        years = [int(y.group()) for y in cls.copyright_dates_re.finditer(ant.date)]
        if len(years) == 2:
            if 10000 > years[0] > 100 and years[1] >= years[0]:
                ant.year_start = years[0]
                ant.year_end = years[1]
                return

        if len(years) == 1 and 10000 > years[0] > 100:
            ant.year_start = years[0]
    def test_format_copyright_annotation(self):
        cp = CopyrightAnnotation(name='Siemens',
                                 coords=(0, 100),
                                 text='text text',
                                 locale='locale',
                                 company='Siemens',
                                 year_start=1996)
        s = cp.get_cite()  # '/copyright/Siemens/1996'
        self.assertGreater(s.find('copyright'), -1)
        self.assertGreater(s.find('Siemens'), -1)
        self.assertGreater(s.find('1996'), -1)

        cp.year_end = 2019
        cp.locale = 'en'
        s = cp.get_cite()  # '/en/copyright/Siemens/1996/2019'
        self.assertGreater(s.find('copyright'), -1)
        self.assertGreater(s.find('Siemens'), -1)
        self.assertGreater(s.find('1996'), -1)
        self.assertGreater(s.find('2019'), -1)