예제 #1
0
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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    def test_fail(self):
        managers = [ObserverManager({'\n': ClauseObserver})]
        result = parser.parse('\nImagina\n', managers, {'\n'})

        self.assertEqual([Token('\n'), Token('Imagina'), Token('\n')], result)
예제 #5
0
    def test_simple(self):
        managers = [ObserverManager({'\n': ClauseObserver})]
        result = parser.parse('\nIV\n', managers, {'\n'})

        self.assertEqual([Token('\n'), Clause('IV'), Token('')], result)
예제 #6
0
    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)
예제 #7
0
def analyse(text, managers, terms):
    return analyser.analyse(parse(normalize(text), managers, terms))