Exemplo n.º 1
0
def batch_codify(filelist):
    # batch upload to database / codifier
    sys.path.insert(0, '../3gm')
    import codifier
    import apply_links
    import pparser
    new_laws = {}
    try:
        if (isinstance(filelist, str)):
            filelist = [filelist]
        if not (filelist and isinstance(filelist, list)
                and all(isinstance(file, str) for file in filelist)):
            raise TypeError('filelist must be a list of one or more strings.')

        tmp_codifier = codifier.LawCodifier()
        for f in filelist:
            issue = pparser.IssueParser(filename=f)
            tmp_codifier.issues.append(issue)
            new_laws.update(issue.detect_new_laws())

        tmp_codifier.codify_new_laws()
        tmp_codifier.create_law_links()

        print('Laws added and links created')
        print('Applying links')
        print(new_laws)
        apply_links.apply_all_links(identifiers=None)
    except Exception as e:
        logging.error("Exception occurred while codifying file %s to txt",
                      ''.join(filelist),
                      exc_info=True)
Exemplo n.º 2
0
def test_operations():
    cod = codifier.LawCodifier()
    law = cod.laws['ν. 4511/2018']

    law.remove_paragraph('1', '2')
    assert ('2' not in law.sentences['1'])

    law.add_paragraph('1', '1', 'Lorem. Ipsum')
    print(law.sentences['1'])
    assert (law.sentences['1']['1'] == ['Lorem', 'Ipsum'])

    law.replace_phrase('Lorem', 'Example', '1', '1')
    assert (law.sentences['1']['1'] == ['Example', 'Ipsum'])

    law.remove_phrase('Example', '1', '1')
    assert (law.sentences['1']['1'] == ['', 'Ipsum'])

    law.remove_period('', 0, '1', '1')
    assert (law.sentences['1']['1'] == ['Ipsum'])

    print(law.sentences['1'])

    law.add_article('4AA', '1. Foo. 2. Moo')
    assert (law.sentences['4AA'] == {'1': ['Foo.'], '2': ['Moo']})

    law.replace_period(' Ipsum', 'Lipsum', None, '1', '1')
    assert (law.sentences['1']['1'] == ['Ipsum'])

    law.replace_period('', 'Lipsum2', 0, '1', '1')

    assert (law.sentences['1']['1'] == ['Lipsum2'])

    law.insert_period('after', 'Lipsum2', 'Lipsum after', '1', '1')
    assert (law.sentences['1']['1'] == ['Lipsum2', 'Lipsum after'])
Exemplo n.º 3
0
def batch_upload(filelist):
    # batch upload to database / codifier
    sys.path.insert(0, '../3gm')
    import codifier
    import apply_links

    tmp_codifier = codifier.LawCodifier()
    for f in filelist:
        tmp_codifier.issues.append(f)

    tmp_codifier.codify_new_laws()
    tmp_codifier.create_law_links()

    print('Laws added and links created')
    print('Applying links')

    apply_links.apply_all_links(identifiers=None, rollback=False)
Exemplo n.º 4
0
def test_phrase():
    cod = codifier.LawCodifier()
    law = cod.laws['ν. 4511/2018']
    test = law.sentences['1']['1']

    test1 = phrase_fun.replace_phrase(test, 'επίδοσής της στο αντίδικο μέρος',
                                      'foo')
    tmp = '. '.join(test1)
    assert ('επίδοσής της στο αντίδικο μέρος' not in tmp and 'foo' in tmp)

    test2 = phrase_fun.remove_phrase(test1, 'foo')
    assert ('foo' not in '. '.join(test2))

    test3 = phrase_fun.insert_phrase(test1, 'appended')
    assert (test3[-1].endswith('appended'))

    test4 = phrase_fun.insert_phrase(test1, 'prepended', position='prepend')
    assert (test4[0].startswith('prepended'))

    test5 = phrase_fun.insert_phrase(test1,
                                     'boo',
                                     position='before',
                                     old_phrase='foo')
    tmp = '. '.join(test5)
    assert ('boo foo' in tmp)

    test6 = phrase_fun.insert_phrase(test1,
                                     'boo',
                                     position='after',
                                     old_phrase='foo')
    tmp = '. '.join(test6)
    assert ('foo boo' in tmp)

    test7 = law.insert_phrase('boo',
                              position='before',
                              old_phrase='επίδοσής της στο αντίδικο μέρος',
                              article='1',
                              paragraph='1')
    assert ('boo επίδοσής της στο αντίδικο μέρος'
            in '. '.join(test7['articles']['1']['1']))
Exemplo n.º 5
0
from entities import *
import parser
import codifier
import tokenizer
import helpers
import syntax
import os
import sys
sys.path.insert(0, '../3gm')

if __name__ == '__main__':
    counter = 0
    cod = codifier.LawCodifier(sys.argv[1])
    f = open(sys.argv[2], 'w+')
    cod.codify_new_laws()
    for identifier, law in cod.laws.items():
        for article in law.sentences:
            print(article)
            for s in law.get_paragraphs(article):
                global actions
                global whats
                trees = []
                try:
                    extracts, non_extracts = helpers.get_extracts(s)
                except:
                    counter += 1
                    continue
                non_extracts = ' '.join(non_extracts)
                non_extracts = tokenizer.tokenizer.split(non_extracts,
                                                         delimiter='. ')
Exemplo n.º 6
0
def test_codifier():
    cod = codifier.LawCodifier()
    law = cod.laws['ν. 4511/2018']
    s = '''Οι παράγραφοι 3 και 4 του άρθρου 1 του ν. 4511/2018 αντικαθίστανται ως εξής: «3. Lorem Ipsum 4. Dolor sir amet»'''
    law.apply_amendment(s)

    assert (law.sentences['1']['3'] == ['Lorem Ipsum '])
    assert (law.sentences['1']['4'] == ['Dolor sir amet'])

    print(law.sentences['1']['3'])
    s = 'Στην παράγραφο 3 του άρθρου 1 η φράση «Lorem» αντικαθίσταται από τη φράση «Lorem Lorem»'

    tree = syntax.ActionTreeGenerator.generate_action_tree_from_string(s)

    for t in tree:
        law.query_from_tree(t)

    assert (law.sentences['1']['3'] == ['Lorem Lorem Ipsum '])

    s = 'Στην παράγραφο 3 του άρθρου 1 μετά τη φράση «Ipsum» προστίθεται η φράση «Amet»'
    tree = syntax.ActionTreeGenerator.generate_action_tree_from_string(s)

    for t in tree:
        law.query_from_tree(t)

    assert (law.sentences['1']['3'] == ['Lorem Lorem Ipsum Amet '])

    s = 'Στην παράγραφο 3 του άρθρου 1 διαγράφεται η φράση «Ipsum Amet»'
    tree = syntax.ActionTreeGenerator.generate_action_tree_from_string(s)

    for t in tree:
        law.query_from_tree(t)

    assert (law.sentences['1']['3'] == ['Lorem Lorem  '])

    s = 'Στο ν. 4511/2018 προστίθεται άρθρο 15 ως εξής: « 1. This is a paragraph 2. This is another paragraph»'
    tree = syntax.ActionTreeGenerator.generate_action_tree_from_string(s)

    for t in tree:
        law.query_from_tree(t)

    assert (law.sentences['15'])

    s = 'Στην παράγραφο 1 του άρθρου 15 ν. 4511/2018 προστίθεται δεύτερο εδάφιο ως εξής «This is a period being added»'

    tree = syntax.ActionTreeGenerator.generate_action_tree_from_string(s)

    for t in tree:
        law.query_from_tree(t)

    assert (law.sentences['15']['1'][1] == 'This is a period being added')

    s = 'Στην παράγραφο 1 του άρθρου 15 ν. 4511/2018 το πρώτο εδάφιο αντικαθίσταται ως εξής «This is a period being replaced»'

    tree = syntax.ActionTreeGenerator.generate_action_tree_from_string(s)

    for t in tree:
        law.query_from_tree(t)

    assert (law.sentences['15']['1'][0] == 'This is a period being replaced')

    s = 'Στο ν. 4511/2018 διαγράφεται το άρθρο 15.'

    trees = syntax.ActionTreeGenerator.generate_action_tree_from_string(s)
    for t in trees:
        law.query_from_tree(t)

    assert ('15' not in law.sentences.keys())