def testNoTranslation(self): t = translators.CategoryNameTranslator(['foo', 'bar']) tr = t.translateWithReport('baz') self.assertFalse(tr.changed) self.assertFalse(tr.didQuotes) self.assertFalse(tr.didDashes) self.assertFalse(tr.didManual) self.assertEqual(tr.oldName, 'baz') self.assertEqual(tr.newName, 'baz')
def doTestDashTranslation(self, n1, n2): t = translators.CategoryNameTranslator() tr = t.translateWithReport(n1) self.assertTrue(tr.changed) self.assertFalse(tr.didQuotes) self.assertTrue(tr.didDashes) self.assertFalse(tr.didManual) self.assertEqual(tr.oldName, n1) self.assertEqual(tr.newName, n2)
def testUnusedManualTranslations(self): t = translators.CategoryNameTranslator([ 'foo', 'bar', 'qwe', 'rty', 'asd', 'fgh', ]) tr = t.translateWithReport('qwe') self.assertEqual(t.getUnusedManualTranslations(), {'foo', 'asd'})
def getDocumentPriority(documentNumber): "priority to resolve name collisions for section/category/type codes" document=next(d for d in documents if d['documentNumber']==documentNumber) if document['amendmentFlag']==2: priority=30 # law, published by fincom elif document['amendmentFlag']==0: priority=20 # law project, published by fincom else: priority=10 # amendment, published by assembly, often contains typos priority+=document['stageNumber'] # prefer latter stage return priority ys2014=dataSets.YearSet(2014,inputDirectory,getDocumentPriority) ys2015=dataSets.YearSet(2015,inputDirectory,getDocumentPriority) with open('categoryNameTranslations.txt',encoding='utf8') as file1, open('categoryNameTypos.txt',encoding='utf8') as file2: translator=translators.CategoryNameTranslator(itertools.chain(file1,file2)) iys=dataSets.InterYearSet([ys2014,ys2015],translator) print('== unused manual translations ==') for k in sorted(translator.getUnusedManualTranslations()): print(k) ### write sql ### sql=open(outputFilename,'w',encoding='utf8') sql.write("-- бюджет Санкт-Петербурга на 2014-2017 гг.\n") def putValue(v): if type(v) is str: return "'"+v+"'" elif type(v) is int: return str(v)