Example #1
0
    def reference_resolution(self):
        to_check = []
        to_check.extend(self.f_world.f_actors)
        to_check.extend(self.f_world.f_resources)

        for obj in to_check:
            if obj.f_needsResolve:
                self.logger.debug("Resolving {}".format(obj))
                sentence_word_id = (obj.f_sentence.f_id, obj.f_word_index)
                if sentence_word_id in self.f_reference_map:
                    target = self.f_reference_map[sentence_word_id]
                    element = self.to_element(target)
                    obj.f_reference = element
                    self.logger.debug(
                        "Manual resolution of {}".format(element))
                else:
                    sentence_id = obj.f_sentence.f_id
                    if Processing.is_action_resolution_determiner(obj.f_name):
                        action = self.find_action(sentence_id, obj)
                        obj.f_reference = action
                        self.logger.debug(
                            "Resolution result: {}".format(action))
                    else:
                        animate = self.determine_animate_type(obj)
                        containing_action = Search.get_action(
                            self.f_world.get_actions_of_sentence(
                                obj.f_sentence), obj)
                        invert_role_match = containing_action.f_cop or Processing.is_RC_pronoun(
                            obj.f_name)
                        reference = self.find_reference(
                            sentence_id, obj, animate, invert_role_match)
                        obj.f_reference = reference
                        self.logger.debug(
                            "Resolution result: {}".format(reference))
Example #2
0
    def combine_actions(self):
        for action in self.f_world.f_actions:
            reference_action = None
            if action.f_actorFrom and isinstance(
                    action.f_actorFrom.f_reference, Action):
                reference_action = action.f_actorFrom.f_reference
            elif action.f_object and action.f_object.f_reference:
                if isinstance(action.f_object.f_reference, Action):
                    reference_action = action.f_object.f_reference
                else:
                    reference_action = Search.get_action(
                        self.f_world.f_actions, action.f_object.f_reference)

            if reference_action:
                if self.can_be_merged(reference_action, action, False):
                    self.logger.debug("Merging {} and {}".format(
                        reference_action, action))
                    self.merge(reference_action, action, False)
                elif self.can_be_merged(reference_action, action, True):
                    self.logger.debug(
                        "Copying attributes from {} to {}".format(
                            reference_action, action))
                    action.f_actorFrom = reference_action.f_actorFrom
                    action.f_object = reference_action.f_object
                    action.f_cop = reference_action.f_cop
                    action.f_copIndex = reference_action.f_copIndex
Example #3
0
    def determine_conjunct_elements(self, conjunctions, action, conjoined,
                                    actions):
        conj_type = None
        conj_status = NOT_CONTAINED
        conjoined.append(action)
        conjs_used = []

        for conj in conjunctions:
            if not conj_type or conj_type == conj.f_type:
                status = self.is_part_of(conj.f_from, conjoined)
                target = conj.f_to
                if status == NOT_CONTAINED:
                    status = self.is_part_of(conj.f_to, conjoined)
                    target = conj.f_from
                if status != NOT_CONTAINED and conj_status in (NOT_CONTAINED,
                                                               status):
                    link = Search.get_action(actions, target)
                    if link:
                        if link not in conjoined:
                            conjoined.append(link)
                            conjs_used.append(conj)
                            if not conj_type:
                                conj_status = status
                                conj_type = conj.f_type
                    else:
                        self.logger.error(
                            "Unable to determine action from link {}".format(
                                conj.f_to))
            # elif conj_type:
            #     if conj_type == AND and conj_status == ACTOR_SUBJECT and conj.f_type != AND:
            #         conj_type = MIXED

        for conj in conjs_used:
            conjunctions.remove(conj)

        return conj_type, conj_status