Exemplo n.º 1
0
    def codify_issue(self, filename):
        """Codify certain issue (legacy)
        :params filename : Issue filename
        """

        trees = {}
        issue = parser.IssueParser(filename)
        sorted_articles = sorted(issue.articles.keys())

        for article in sorted_articles:

            for i, extract in enumerate(issue.get_non_extracts(article)):
                trees[i] = syntax.ActionTreeGenerator.generate_action_tree(
                    extract, issue, article)
                for j, t in enumerate(trees[i]):
                    print(t['root'])
                    print(t['what'])
                    law_id = t['law']['_id']
                    print('Law id is ', law_id)

                    try:

                        if law_id not in self.laws.keys():
                            print('Not in keys')
                            self.laws[law_id] = parser.LawParser(law_id)

                        self.db.query_from_tree(self.laws[law_id], t)

                        print('Pushed to Database')
                    except Exception as e:
                        print(str(e))
                        continue

                    print('\nPress any key to continue')
                    input()
Exemplo n.º 2
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.º 3
0
def _test_law_parsing_from_government_gazette_issue():
    issue = parser.IssueParser('../data/15.txt')
    new_laws = issue.detect_new_laws()
    for k in new_laws.keys():
        assert (
            new_laws[k].corpus['15'] ==
            '1.  Η Επιτροπή Κεφαλαιαγοράς χορηγεί άδεια λειτουργίας Α.Ε.Π.Ε.Υ. μόνον εφόσον η αιτούσα εταιρεία έχει επαρκές  αρχικό κεφάλαιο, σύμφωνα με τις απαιτήσεις του Κανονισμού (ΕΕ) 575/2013, λαμβανομένης υπόψη της φύσης της σχετικής επενδυτικής υπηρεσίας ή δραστηριότητας. '
        )
Exemplo n.º 4
0
def codify_pair(source=None, target=None, outfile=None):
    """Codify a pair of issues. Used at the CLI tool
    params: source : Source file. If None then read from stdin
    params: target : Target file. If None then read from stdin
    params: outfile : Output file. If None then output to stdout
    Errors go to stderr
    """
    # Parse issues
    if not source:
        source = sys.argv[1]
    source_issue = parser.IssueParser(source)
    source_issue.detect_new_laws()

    target_issue = parser.IssueParser(None, stdin=True)

    # Detect laws
    target_issue.detect_new_laws()
    source_law = list(source_issue.new_laws.items())[0][1]
    target_law = list(target_issue.new_laws.items())[0][1]

    initial_text = target_law.export_law('issue')
    source_articles = source_law.get_articles_sorted()

    for article in source_articles:
        for paragraph in source_law.get_paragraphs(article):
            try:
                target_law.apply_amendment(paragraph)
            except BaseException:
                # If failing write to stderr
                # sys.stderr.write(paragraph)
                pass

    # Write initial version to stdout in pretty format
    with open(sys.argv[2], 'w+') as f:
        f.write(initial_text)

    # Write formatted output to stdout
    sys.stdout.write(target_law.export_law('issue'))
Exemplo n.º 5
0
#!/usr/bin/env python3
# Simple Exporter
# usage: exporter.py --markdown < issue.txt > output.md
import sys
sys.path.insert(0, '../')
import pparser as parser

export_type = sys.argv[1].strip('--')
issue = parser.IssueParser(None, stdin=True)
laws = issue.detect_new_laws()
for i, l in issue.new_laws.items():
    try:
        result = l.export_law(export_type)
        sys.stdout.write(result)
    except BaseException:
        sys.stderr.write('Error in exporting')
sys.stdout.flush()