Beispiel #1
0
    def build_level_helper(tmp,
                           subtree,
                           max_depth,
                           stem,
                           list_iter=False,
                           recursive=True):
        """Builds a level of the tree using the stems lookup"""
        lookup = ActionTreeGenerator.trans_lookup[stem]

        for i, w in enumerate(tmp):
            if re.search(stem, w):
                is_plural = helpers.is_plural(w)
                if not list_iter:
                    subtree[lookup]['_id'] = next(
                        helpers.ssconj_doc_iterator(tmp, i))
                else:
                    try:
                        subtree[lookup]['_id'] = list(
                            helpers.ssconj_doc_iterator(tmp,
                                                        i,
                                                        is_plural=is_plural,
                                                        recursive=recursive))
                    except:
                        continue
                subtree[lookup][
                    'children'] = ActionTreeGenerator.children_loopkup[lookup]

        return subtree
Beispiel #2
0
    def get_nsubj(doc, i, tree):
        """Get nsubj dependency, in order to find what is
        amended, using spaCy Greek Language model
        :params doc : A spaCy doc object
        :params i: The action position
        :params tree : The JSON tree"""
        found_what = False
        root_token = doc[i]
        for child in root_token.children:

            if child.dep_ in ['nsubj', 'obl']:
                for what in entities.whats:
                    if child.text == what:
                        found_what = True
                        tree['root']['children'].append('law')
                        tree['what'] = {
                            'index': child.i,
                            'context': what,
                        }
                        logging.info('nlp ok')

                        is_plural = helpers.is_plural(what)

                        return found_what, tree, is_plural

        return found_what, tree, False
Beispiel #3
0
    def get_renumbering(tree, doc):
        """Get renumbering content"""
        start = tree['root']['_id']
        is_plural = helpers.is_plural(tree['what']['context'])

        for i in range(start, len(doc)):
            if doc[i].text == 'σε':
                tree['what']['to'] = list(
                    helpers.ssconj_doc_iterator(doc, i, is_plural))
                break

        return tree
Beispiel #4
0
    def get_nsubj_fallback(tmp, tree, i, max_what_window=20):
        found_what = False
        logging.info('Fallback mode')
        logging.info(tmp)
        for j in range(1, max_what_window + 1):
            for what in entities.whats:
                if i + j <= len(tmp) - 1 and what == tmp[i + j]:
                    tree['root']['children'].append('law')
                    tree['what'] = {
                        'index': i + j,
                        'context': what,
                    }

                    if i + j + 1 <= len(tmp):
                        tree['what']['number'] = list(
                            helpers.ssconj_doc_iterator(tmp, i + j))
                    else:
                        tree['what']['number'] = None

                    is_plural = helpers.is_plural(what)
                    return found_what, tree, is_plural

                if i - j >= 0 and what == tmp[i - j]:
                    tree['root']['children'].append('law')
                    tree['what'] = {
                        'index': i - j,
                        'context': what,
                    }
                    if i - j >= 0:
                        tree['what']['number'] = list(
                            helpers.ssconj_doc_iterator(tmp, i - j))
                    else:
                        tree['what']['number'] = None

                    is_plural = helpers.is_plural(what)
                    return found_what, tree, is_plural

        return found_what, tree, False