Пример #1
0
    def exclude_relative_clauses(self, sentence, dependencies):

        relative_clauses = []

        for dep in dependencies:
            if dep['dep'] != RCMOD:
                sentence_index = Search.find_sentence_index(self.f_full_sentence,
                                                            sentence)
                dep_in_tree = Search.find_dep_in_tree(self.f_full_sentence,
                                                      dep['dependent'])

                while dep_in_tree.label() != ROOT:

                    if sentence.label() == dep_in_tree.label():
                        part_index = Search.find_sentence_index(self.f_full_sentence,
                                                                dep_in_tree)
                        if sentence_index >= part_index:
                            break

                    if dep_in_tree.label() in (SBAR, S, PRN) and dep_in_tree.parent().label() != SBAR:
                        relative_clauses.append(dep)
                        break

                    dep_in_tree = dep_in_tree.parent()

        return [dep for dep in dependencies if dep not in relative_clauses]
Пример #2
0
    def extract_SBAR_spec(cls, origin, full_sentence, element, phrase_head):
        if phrase_head:
            sbar_list = Search.find_in_tree(phrase_head, SBAR, [])
            phrase_index = Search.find_sentence_index(full_sentence, phrase_head)

            for sbar in sbar_list:
                sbar_index = Search.find_sentence_index(full_sentence, sbar)

                if sbar_index > phrase_index:
                    spec = Specifier(origin, sbar_index, " ".join(sbar.leaves()))
                    spec.f_type = SBAR
                    element.f_specifiers.append(spec)
Пример #3
0
    def extract_PP_spec_syntax(cls, origin, full_sentence, element, vphead):
        pp_list = Search.find_in_tree(vphead, PP, (SBAR, S, NP, PRN))

        for pp in pp_list:
            pp_index = Search.find_sentence_index(full_sentence, pp)
            spec = Specifier(origin, pp_index, " ".join(pp.leaves()))
            spec.f_type = PP
            element.f_specifiers.append(spec)
Пример #4
0
    def create_action_syntax(cls, origin, full_sentence, vphead):
        verb_parts = cls.extract_verb_parts(vphead)
        index = Search.find_sentence_index(full_sentence, vphead)

        action = Action(origin, index, " ".join(verb_parts))
        cls.extract_SBAR_spec(origin, full_sentence, action, vphead)
        cls.extract_PP_spec_syntax(origin, full_sentence, action, vphead)

        cls.logger.debug("Identified action {}".format(action))
        return action
Пример #5
0
    def filter_dependencies(self, sentence, dependencies):
        filtered_deps = []
        start_index = Search.find_sentence_index(self.f_full_sentence, sentence)
        end_index = start_index + len(sentence.leaves())

        for dep in dependencies:
            if dep['dep'] == RCMOD or \
                    (start_index <= dep['governor'] < end_index
                     and start_index <= dep['dependent'] < end_index):
                filtered_deps.append(dep)

        return filtered_deps
Пример #6
0
    def check_sub_sentences(self, head, dependencies, obj, is_np):

        if head and not isinstance(head, str):
            if head.label() == SBAR:
                leaves = head.leaves()
                start_index = Search.find_sentence_index(self.f_full_sentence, head)
                end_index = start_index + len(leaves)
                ccomps = Search.find_dependencies(dependencies, CCOMP)

                for ccomp in ccomps:
                    if start_index < ccomp['dependent'] < end_index:
                        complms = Search.find_dependencies(dependencies, COMPLM)
                        for complm in complms:
                            if complm['governor'] == ccomp['dependent'] and complm['dependentGloss'] == THAT:
                                return

                action = obj if isinstance(obj, Action) else None
                if not action or not action.f_xcomp or start_index > action.f_xcomp.f_word_index or end_index < action.f_xcomp.f_word_index:
                    self.analyze_recursive(head, self.filter_dependencies(head, dependencies))
                    return
            else:
                if head.label() in (PP, VP, NP, S):
                    for child in head:
                        self.check_sub_sentences(child, dependencies, obj, is_np)