Example #1
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)
Example #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)
Example #3
0
    def determine_verbs(self, sentence, dependencies, active):
        actions = []

        main_predicate_index = None

        # Determine main predicate

        if active:
            nsubj = Search.find_dependencies(dependencies, NSUBJ)
            nsubj = self.exclude_relative_clauses(sentence, nsubj)
            if len(nsubj) == 0:
                dobj = Search.find_dependencies(dependencies, DOBJ)
                dobj = self.exclude_relative_clauses(sentence, dobj)
                if len(dobj) >= 1:
                    main_predicate_index = dobj[0]['governor']
            elif len(nsubj) == 1:
                main_predicate_index = nsubj[0]['governor']
                cop = Search.find_dependencies(dependencies, COP)
                cop = self.exclude_relative_clauses(sentence, cop)
                for dep in cop:
                    if dep['governor'] == main_predicate_index:
                        main_predicate_index = dep['dependent']
                        break
            else:
                self.logger.info("Sentence has more than one active predicate")
                self.logger.debug(nsubj)

        else:
            nsubjpass = Search.find_dependencies(dependencies, NSUBJPASS)
            nsubjpass = self.exclude_relative_clauses(sentence, nsubjpass)
            if len(nsubjpass) == 1:
                main_predicate_index = nsubjpass[0]['governor']
            elif len(nsubjpass) > 1:
                self.logger.info("Sentence has more than one passive predicate")
                self.logger.debug(nsubjpass)

        # Find all actions

        if main_predicate_index:
            main_predicate = Search.find_dep_in_tree(self.f_full_sentence,
                                                     main_predicate_index)
            vp_head = Search.get_full_phrase_tree(main_predicate, VP)
            action = Builder.create_action(self.f_stanford_sentence, self.f_full_sentence,
                                           main_predicate_index, dependencies, active)
            self.check_sub_sentences(vp_head, dependencies, action, False)
            actions.append(action)
        else:
            verbs = Search.find_in_tree(sentence, VP, (SBAR, S))
            if len(verbs) == 0:
                self.logger.info("Sentence contains no action")
            elif len(verbs) > 1:
                self.logger.info("Sentence has more than one verb phrase")
            else:
                vp = verbs[0]
                action = Builder.create_action_syntax(self.f_stanford_sentence, self.f_full_sentence, vp)
                self.check_sub_sentences(vp, dependencies, action, False)
                actions.append(action)

        if len(actions) > 0:
            for new_action in self.check_conjunctions(dependencies, actions[0],
                                                      False, False, active):
                actions.append(new_action)

        return actions