def parse(text): type_names = ['Decreto-Lei', 'Lei', 'Declaração de Rectificação', 'Portaria'] managers = parser.common_managers + [ parser.ObserverManager(dict((name, DocumentRefObserver) for name in type_names)), parser.ObserverManager(dict((name, ArticleRefObserver) for name in ['artigo', 'artigos']))] terms = {' ', '.', ',', '\n', 'n.os', '«', '»'} for manager in managers: terms |= manager.terms return parser.parse(text, managers, terms)
def test_fails(self): managers = [ObserverManager({'\n': UnnumberedAnnexObserver})] result = parser.parse('\nTítulo\n', managers, {'\n'}) self.assertEqual([Token('\n'), Token('Título'), Token('\n')], result)
def test_simple(self): # document 455149 contains this example managers = parser.common_managers result = parser.parse('\nAnexo\n', managers, {'\n'}) self.assertEqual([Token('\n'), Annex(''), Token('')], result)
def test_fail(self): managers = [ObserverManager({'\n': ClauseObserver})] result = parser.parse('\nImagina\n', managers, {'\n'}) self.assertEqual([Token('\n'), Token('Imagina'), Token('\n')], result)
def test_simple(self): managers = [ObserverManager({'\n': ClauseObserver})] result = parser.parse('\nIV\n', managers, {'\n'}) self.assertEqual([Token('\n'), Clause('IV'), Token('')], result)
def _test(self, string, managers, expected): result = parser.parse(string, managers, {' ', '.', ',', '\n', 'n.os'}) self.assertEqual(string, ''.join(v.as_str() for v in result)) for exp, index, in expected: self.assertEqual(result[index], exp)
def analyse(text, managers, terms): return analyser.analyse(parse(normalize(text), managers, terms))