Ejemplo n.º 1
0
    def handle_DRS(self, tok, context):
        drs = drt.DrtParser.handle_DRS(self, tok, context)
        location_time = None

        for cond in drs.conds:
            if isinstance(cond, DrtFindEventualityExpression):
                # PERF(.) gives rise to a DrtFindEventualityExpression;
                # in case it is among the DRS-conditions, the eventuality carried by
                # this DRS does not give rise to a REFER(.) condition
                return DRS(drs.refs, drs.conds)

            if not location_time and isinstance(cond, DrtLocationTimeApplicationExpression):
                location_time = cond.argument

        for ref in drs.refs:
            # Change DRS: introduce REFER(s/e) condition, add INCLUDE/OVERLAP
            # conditions to verbs (triggered by LOCPRO) and given some trigger
            # from DrtTokens.TENSE put UTTER(.) condition and,for PAST and FUT,
            # earlier(.,.) condition w.r.t. to some new discourse
            # referent bound to utterance time.

            if is_statevar(ref.name):
                # Adds REFER(s) condition.
                if location_time:
                    # Relates location time and eventuality
                    drs.conds.append(
                        DrtTimeApplicationExpression(
                            DrtTimeApplicationExpression(
                                self.make_ConstantExpression(DrtTokens.OVERLAP), location_time
                            ),
                            DrtStateVariableExpression(ref),
                        )
                    )
                drs.conds.append(
                    DrtFindEventualityExpression(
                        self.make_ConstantExpression(DrtTokens.REFER), DrtVariableExpression(ref)
                    )
                )

            if is_eventvar(ref.name):
                # Adds REFER(e) condition.
                if location_time:
                    # Relates location time and eventuality
                    drs.conds.append(
                        DrtTimeApplicationExpression(
                            DrtTimeApplicationExpression(
                                self.make_ConstantExpression(DrtTokens.INCLUDE), location_time
                            ),
                            DrtStateVariableExpression(ref),
                        )
                    )
                drs.conds.append(
                    DrtFindEventualityExpression(
                        self.make_ConstantExpression(DrtTokens.REFER), DrtVariableExpression(ref)
                    )
                )

            if is_timevar(ref.name) and not is_uttervar(ref.name):
                # Relates location time with utterance time

                tense_cond = [
                    c
                    for c in drs.conds
                    if isinstance(c, DrtApplicationExpression)
                    and isinstance(c.function, DrtConstantExpression)
                    and c.function.variable.name in DrtTokens.TENSE
                    and DrtVariableExpression(ref) == c.argument
                ]
                if not tense_cond == []:
                    if tense_cond[0].function.variable.name == DrtTokens.PRES:
                        # Put UTTER(t) instead
                        # drs.conds.remove(drs.conds.index(tense_cond[0]))
                        drs.conds[drs.conds.index(tense_cond[0])] = DrtFindUtterTimeExpression(
                            self.make_ConstantExpression(DrtTokens.UTTER), DrtTimeVariableExpression(ref)
                        )

                    else:
                        # Put new discourse referent and bind it to utterance time
                        # by UTTER(.) and also add earlier(.,.) condition
                        utter_time = unique_variable(ref)
                        drs.refs.insert(0, utter_time)
                        drs.conds[drs.conds.index(tense_cond[0])] = DrtFindUtterTimeExpression(
                            self.make_ConstantExpression(DrtTokens.UTTER), DrtTimeVariableExpression(utter_time)
                        )

                        if tense_cond[0].function.variable.name == DrtTokens.PAST:
                            drs.conds.append(
                                DrtTimeApplicationExpression(
                                    DrtTimeApplicationExpression(
                                        self.make_ConstantExpression(DrtTokens.EARLIER), DrtTimeVariableExpression(ref)
                                    ),
                                    DrtTimeVariableExpression(utter_time),
                                )
                            )

                        else:
                            drs.conds.append(
                                DrtTimeApplicationExpression(
                                    DrtTimeApplicationExpression(
                                        self.make_ConstantExpression(DrtTokens.EARLIER),
                                        DrtTimeVariableExpression(utter_time),
                                    ),
                                    DrtTimeVariableExpression(ref),
                                )
                            )

        return DRS(drs.refs, drs.conds)
Ejemplo n.º 2
0
    def handle_DRS(self, tok, context):
        drs = drt.DrtParser.handle_DRS(self, tok, context)
        location_time = None

        for cond in drs.conds:
            if isinstance(cond, DrtFindEventualityExpression):
                #PERF(.) gives rise to a DrtFindEventualityExpression;
                #in case it is among the DRS-conditions, the eventuality carried by
                #this DRS does not give rise to a REFER(.) condition
                return DRS(drs.refs, drs.conds)

            if not location_time and isinstance(
                    cond, DrtLocationTimeApplicationExpression):
                location_time = cond.argument

        for ref in drs.refs:
            #Change DRS: introduce REFER(s/e) condition, add INCLUDE/OVERLAP
            #conditions to verbs (triggered by LOCPRO) and given some trigger
            #from DrtTokens.TENSE put UTTER(.) condition and,for PAST and FUT,
            #earlier(.,.) condition w.r.t. to some new discourse
            #referent bound to utterance time.

            if is_statevar(ref.name):
                #Adds REFER(s) condition.
                if location_time:
                    #Relates location time and eventuality
                    drs.conds.append(
                        DrtTimeApplicationExpression(
                            DrtTimeApplicationExpression(
                                self.make_ConstantExpression(
                                    DrtTokens.OVERLAP), location_time),
                            DrtStateVariableExpression(ref)))
                drs.conds.append(
                    DrtFindEventualityExpression(
                        self.make_ConstantExpression(DrtTokens.REFER),
                        DrtVariableExpression(ref)))

            if is_eventvar(ref.name):
                #Adds REFER(e) condition.
                if location_time:
                    #Relates location time and eventuality
                    drs.conds.append(
                        DrtTimeApplicationExpression(
                            DrtTimeApplicationExpression(
                                self.make_ConstantExpression(
                                    DrtTokens.INCLUDE), location_time),
                            DrtStateVariableExpression(ref)))
                drs.conds.append(
                    DrtFindEventualityExpression(
                        self.make_ConstantExpression(DrtTokens.REFER),
                        DrtVariableExpression(ref)))

            if is_timevar(ref.name) and not is_uttervar(ref.name):
                #Relates location time with utterance time

                tense_cond = [c for c in drs.conds if isinstance(c, DrtApplicationExpression) and \
                               isinstance(c.function, DrtConstantExpression) and \
                               c.function.variable.name in DrtTokens.TENSE and DrtVariableExpression(ref) == c.argument]
                if not tense_cond == []:
                    if tense_cond[0].function.variable.name == DrtTokens.PRES:
                        #Put UTTER(t) instead
                        #drs.conds.remove(drs.conds.index(tense_cond[0]))
                        drs.conds[drs.conds.index(
                            tense_cond[0])] = DrtFindUtterTimeExpression(
                                self.make_ConstantExpression(DrtTokens.UTTER),
                                DrtTimeVariableExpression(ref))

                    else:
                        #Put new discourse referent and bind it to utterance time
                        #by UTTER(.) and also add earlier(.,.) condition
                        utter_time = unique_variable(ref)
                        drs.refs.insert(0, utter_time)
                        drs.conds[drs.conds.index(
                            tense_cond[0])] = DrtFindUtterTimeExpression(
                                self.make_ConstantExpression(DrtTokens.UTTER),
                                DrtTimeVariableExpression(utter_time))

                        if tense_cond[
                                0].function.variable.name == DrtTokens.PAST:
                            drs.conds.append(
                                DrtTimeApplicationExpression(
                                    DrtTimeApplicationExpression(
                                        self.make_ConstantExpression(
                                            DrtTokens.EARLIER),
                                        DrtTimeVariableExpression(ref)),
                                    DrtTimeVariableExpression(utter_time)))

                        else:
                            drs.conds.append(
                                DrtTimeApplicationExpression(
                                    DrtTimeApplicationExpression(
                                        self.make_ConstantExpression(
                                            DrtTokens.EARLIER),
                                        DrtTimeVariableExpression(utter_time)),
                                    DrtTimeVariableExpression(ref)))

        return DRS(drs.refs, drs.conds)
Ejemplo n.º 3
0
    def readings(self, trail=[]):

        state_reference_point = None
        index = trail[-1].conds.index(self)
        # state reference point in case there are no previous events
        for drs in (ancestor for ancestor in ReverseIterator(trail) if isinstance(ancestor, DRS)):

            search_list = drs.refs

            if drs is trail[-1]:

                # Described eventuality in the object's referents?
                # Take refs' list up to described eventuality

                search_list = drs.refs[: drs.refs.index(self.argument.variable)]

            for ref in ReverseIterator(search_list):
                # search for the most recent reference
                refex = DrtVariableExpression(ref)

                if (
                    isinstance(refex, DrtEventVariableExpression)
                    and not (refex == self.argument)
                    and not self.function.variable.name == DrtTokens.PERF
                ):

                    if isinstance(self.argument, DrtEventVariableExpression):
                        # In case given eventuality is an event, return earlier
                        return (
                            [
                                Binding(
                                    [
                                        (
                                            trail[-1],
                                            ConditionReplacer(
                                                index, [self._combine(DrtTokens.EARLIER, refex, self.argument)]
                                            ),
                                        )
                                    ]
                                )
                            ],
                            False,
                        )

                    elif isinstance(self.argument, DrtStateVariableExpression):
                        # In case given eventuality is a state, return include
                        return (
                            [
                                Binding(
                                    [
                                        (
                                            trail[-1],
                                            ConditionReplacer(
                                                index, [self._combine(DrtTokens.INCLUDE, self.argument, refex)]
                                            ),
                                        )
                                    ]
                                )
                            ],
                            False,
                        )

                elif (
                    not state_reference_point
                    and isinstance(refex, DrtStateVariableExpression)
                    and not (refex == self.argument)
                ):
                    # In case no event is found, locate the most recent state
                    state_reference_point = refex

        if state_reference_point:

            if self.function.variable.name == DrtTokens.PERF:
                # in case we are dealing with PERF
                if isinstance(self.argument, DrtEventVariableExpression):

                    # Reference point is a state and described eventuality an event,
                    # return event abuts on state

                    return (
                        [
                            Binding(
                                [
                                    (
                                        trail[-1],
                                        ConditionReplacer(
                                            index, [self._combine(DrtTokens.ABUT, self.argument, state_reference_point)]
                                        ),
                                    )
                                ]
                            )
                        ],
                        False,
                    )

                elif isinstance(self.argument, DrtStateVariableExpression):
                    # Reference point is a state and described eventuality a state,
                    # then add an event referent to the ancestor's refs list and two conditions
                    # that that event is the end of eventuality and
                    # that event abuts on ref.state. Function object needed.
                    termination_point = unique_variable(Variable("e"))
                    conds = [
                        DrtEqualityExpression(
                            DrtEventVariableExpression(termination_point),
                            DrtApplicationExpression(self.make_ConstantExpression(DrtTokens.END), self.argument),
                        ),
                        self._combine(
                            DrtTokens.ABUT, DrtEventVariableExpression(termination_point), state_reference_point
                        ),
                    ]
                    return (
                        [
                            Binding(
                                [
                                    (
                                        trail[-1],
                                        DrtFindEventualityExpression.ConditionReplacer(index, conds, termination_point),
                                    )
                                ]
                            )
                        ],
                        False,
                    )

            elif isinstance(self.argument, DrtStateVariableExpression):
                # Reference point is a state and given eventuality is also a state,
                # return overlap

                return (
                    [
                        Binding(
                            [
                                (
                                    trail[-1],
                                    ConditionReplacer(
                                        index, [self._combine(DrtTokens.OVERLAP, state_reference_point, self.argument)]
                                    ),
                                )
                            ]
                        )
                    ],
                    False,
                )

            elif isinstance(self.argument, DrtEventVariableExpression):
                # Reference point is a state and given eventuality is an event,
                # return include
                return (
                    [
                        Binding(
                            [
                                (
                                    trail[-1],
                                    ConditionReplacer(
                                        index, [self._combine(DrtTokens.INCLUDE, state_reference_point, self.argument)]
                                    ),
                                )
                            ]
                        )
                    ],
                    False,
                )

        else:
            # no suitable reference found
            return [Binding([(trail[-1], ConditionRemover(index))])], False
Ejemplo n.º 4
0
    def readings(self, trail=[]):

        state_reference_point = None
        index = trail[-1].conds.index(self)
        #state reference point in case there are no previous events
        for drs in (ancestor for ancestor in ReverseIterator(trail)
                    if isinstance(ancestor, DRS)):

            search_list = drs.refs

            if drs is trail[-1]:

                #Described eventuality in the object's referents?
                #Take refs' list up to described eventuality

                search_list = drs.refs[:drs.refs.index(self.argument.variable)]

            for ref in ReverseIterator(search_list):
                #search for the most recent reference
                refex = DrtVariableExpression(ref)

                if isinstance(refex, DrtEventVariableExpression) and \
                not (refex == self.argument) and not self.function.variable.name == DrtTokens.PERF:

                    if isinstance(self.argument, DrtEventVariableExpression):
                        #In case given eventuality is an event, return earlier
                        return [
                            Binding([
                                (trail[-1],
                                 ConditionReplacer(index, [
                                     self._combine(DrtTokens.EARLIER, refex,
                                                   self.argument)
                                 ]))
                            ])
                        ], False

                    elif isinstance(self.argument, DrtStateVariableExpression):
                        #In case given eventuality is a state, return include
                        return [
                            Binding([
                                (trail[-1],
                                 ConditionReplacer(index, [
                                     self._combine(DrtTokens.INCLUDE,
                                                   self.argument, refex)
                                 ]))
                            ])
                        ], False


                elif not state_reference_point and \
                    isinstance(refex, DrtStateVariableExpression) and \
                    not (refex == self.argument):
                    #In case no event is found, locate the most recent state
                    state_reference_point = refex

        if state_reference_point:

            if self.function.variable.name == DrtTokens.PERF:
                #in case we are dealing with PERF
                if isinstance(self.argument, DrtEventVariableExpression):

                    #Reference point is a state and described eventuality an event,
                    #return event abuts on state

                    return [
                        Binding([
                            (trail[-1],
                             ConditionReplacer(index, [
                                 self._combine(DrtTokens.ABUT, self.argument,
                                               state_reference_point)
                             ]))
                        ])
                    ], False

                elif isinstance(self.argument, DrtStateVariableExpression):
                    #Reference point is a state and described eventuality a state,
                    #then add an event referent to the ancestor's refs list and two conditions
                    #that that event is the end of eventuality and
                    #that event abuts on ref.state. Function object needed.
                    termination_point = unique_variable(Variable("e"))
                    conds = [
                        DrtEqualityExpression(
                            DrtEventVariableExpression(termination_point),
                            DrtApplicationExpression(
                                self.make_ConstantExpression(DrtTokens.END),
                                self.argument)),
                        self._combine(
                            DrtTokens.ABUT,
                            DrtEventVariableExpression(termination_point),
                            state_reference_point)
                    ]
                    return [
                        Binding([
                            (trail[-1],
                             DrtFindEventualityExpression.ConditionReplacer(
                                 index, conds, termination_point))
                        ])
                    ], False

            elif isinstance(self.argument, DrtStateVariableExpression):
                #Reference point is a state and given eventuality is also a state,
                #return overlap

                return [
                    Binding([(trail[-1],
                              ConditionReplacer(index, [
                                  self._combine(DrtTokens.OVERLAP,
                                                state_reference_point,
                                                self.argument)
                              ]))])
                ], False

            elif isinstance(self.argument, DrtEventVariableExpression):
                #Reference point is a state and given eventuality is an event,
                #return include
                return [
                    Binding([(trail[-1],
                              ConditionReplacer(index, [
                                  self._combine(DrtTokens.INCLUDE,
                                                state_reference_point,
                                                self.argument)
                              ]))])
                ], False

        else:
            #no suitable reference found
            return [Binding([(trail[-1], ConditionRemover(index))])], False