예제 #1
0
    def say(self, prep, selector, noun, allow_archaic):
        """
        args -> SayResult or None

        See if the args can be expressed using a pro-adverb.
        """
        n2 = selector.decide_grammatical_number(self.cor2res_gno)
        if not n2:
            return None

        conj = N2_TO_CONJ[n2]

        for pro_adverb_col in self.noun2pro_adverb_cols[noun]:
            key = (selector.correlative, pro_adverb_col)
            tokens, is_archaic = self.cor_pac2ss_archaic[key]
            tokens = list(tokens)

            if is_archaic and not allow_archaic:
                continue

            noun = self.pro_adverb_col2noun[pro_adverb_col]
            eat_prep = noun in self.noun2hallucinate_prep

            return SayResult(tokens=tokens,
                             conjugation=conj,
                             eat_prep=eat_prep)

        return None
예제 #2
0
    def say(self, state, idiolect, context):
        tokens = []
        for i, a in self.aa:
            if i == 0:
                left = context.has_left
            else:
                left = True

            if i == len(self.aa) - 1:
                right = True
            else:
                right = context.has_right

            sub_context = SayContext(
                context.prep, has_left=left, has_right=right,
                is_possessive=False)
            r = a.say(state, idiolect, sub_context)
            tokens += r.tokens

            if i < len(self.aa) - 2:
                tokens += [',']
            if i != len(self.aa) - 1:
                tokens += [OP2TEXT[self.op]]

        return SayResult(tokens=tokens, conjugation=Conjugation.P3,
                         eat_prep=False)
예제 #3
0
 def perspro_say(self, p, use_whom):
     """
     PersonalPronoun, who/whom -> tokens
     """
     pc = self.ppcase2pc[p.ppcase]
     ss = self.tables.say(p.declension, pc, use_whom)
     conj = self.perspro_decide_conjugation(p)
     return SayResult(tokens=ss, conjugation=conj, eat_prep=False)
예제 #4
0
파일: direction.py 프로젝트: knighton/babi
    def say(self, state, idiolect, context):
        if self.of:
            sub_context = SayContext(('of', ), True, context.has_right, False)
            r = self.of.say(state, idiolect, sub_context)
            of_tokens = r.tokens
        else:
            of_tokens = []

        tokens = [self.which, 'of'] + of_tokens
        return SayResult(tokens=tokens,
                         conjugation=Conjugation.S3,
                         eat_prep=False)
예제 #5
0
def test_say(m):
    selector = Selector(Correlative.DEF, N5.FEW, N5.FEW, N5.FEW, N5.FEW)
    r = SayResult(tokens=['the'], conjugation=Conjugation.P3, eat_prep=False)
    say(m, selector, False, r)

    selector = Selector(Correlative.DEF, N5.SING, N5.SING, N5.SING, N5.SING)
    r = SayResult(tokens=['the'], conjugation=Conjugation.S3, eat_prep=False)
    say(m, selector, False, r)

    selector = Selector(Correlative.DEF, N5.SING, N5.SING, N5.SING, N5.SING)
    r = None
    say(m, selector, True, r)

    selector = Selector(Correlative.NEG, N5.ZERO, N5.ZERO, N5.DUAL, N5.DUAL)
    r = SayResult(tokens=['neither'],
                  conjugation=Conjugation.P3,
                  eat_prep=False)
    say(m, selector, False, r)

    selector = Selector(Correlative.NEG, N5.ZERO, N5.ZERO, N5.DUAL, N5.DUAL)
    r = SayResult(tokens=['neither'],
                  conjugation=Conjugation.P3,
                  eat_prep=False)
    say(m, selector, True, r)

    selector = Selector(Correlative.NEG, N5.ZERO, N5.ZERO, N5.FEW, N5.MANY)
    r = SayResult(tokens=['no'], conjugation=Conjugation.P3, eat_prep=False)
    say(m, selector, False, r)

    selector = Selector(Correlative.NEG, N5.ZERO, N5.ZERO, N5.FEW, N5.MANY)
    r = SayResult(tokens=['none'], conjugation=Conjugation.P3, eat_prep=False)
    say(m, selector, True, r)
예제 #6
0
    def say(self, selector, is_pro):
        """
        Selector, whether pronoun or determiner -> SayResult or None

        See if the args can be said using a determiner or (impersonal) pronoun.
        """
        is_plur = True if selector.guess_n(N2) == N2.PLUR else False
        key = (selector.correlative, is_pro, is_plur, selector.guess_of_n(N5))
        s = self.cor_pro_plur_of2s.get(key)
        if not s:
            return None

        n2 = selector.decide_grammatical_number(self.cor2res_gno)
        if not n2:
            return None
        conj = N2_TO_CONJ[n2]

        return SayResult(tokens=[s], conjugation=conj, eat_prep=False)
예제 #7
0
    def say(self, state, idiolect, context):
        if self.than:
            sub_context = SayContext(('than', ), True, context.has_right,
                                     False)
            r = self.than.say(state, idiolect, sub_context)
            than_tokens = r.tokens
        else:
            than_tokens = []

        pre, main = state.comparative_mgr.encode(ComparativeDegree.COMPARATIVE,
                                                 self.polarity, self.adjective)

        tokens = []
        if pre:
            tokens.append(pre)
        assert main
        tokens.append(main)
        tokens.append('than')
        tokens += than_tokens

        return SayResult(tokens=tokens,
                         conjugation=Conjugation.S3,
                         eat_prep=False)
예제 #8
0
    def say(self, state, idiolect, context):
        ss = []

        # Get the complementizer, if any.
        ctzr = COMPLEMENTIZER2WORD[self.complementizer]
        if ctzr:
            ss.append(ctzr)

        # Say the verb.
        #
        # If the verb words go in front, verb_pre_tokens (split-off verb words
        # that go in front of a subject instead of after like the rest) will be
        # empty.
        verb_pre_tokens, verb_main_tokens = state.verb_mgr.say(self.verb)

        fronted_argx = self.get_fronted_argx()
        stranded_argx = self.get_stranded_argx()

        # Say each verb argument.
        ate_stranded_prep = False
        for i, (prep, varg) in enumerate(self.preps_vargs):
            if i == self.vmain_index - 1:
                ss += verb_pre_tokens
            elif i == self.vmain_index:
                ss += verb_main_tokens

            if varg:
                if context.has_left:
                    left = True
                elif ctzr:
                    left = True
                else:
                    left = 0 < i

                if context.has_right:
                    right = True
                elif i < len(self.preps_vargs) - 1:
                    right = True
                elif self.vmain_index == len(self.preps_vargs):
                    right = True
                else:
                    right = False

                used_stranded_prep = False
                if i == fronted_argx and not prep:
                    if stranded_argx:
                        used_stranded_prep = True
                        prep = self.preps_vargs[stranded_argx][0]

                sub_context = SayContext(
                    prep=prep, has_left=left, has_right=right,
                    is_possessive=False)

                r = varg.say(state, idiolect, sub_context)
                if prep and not r.eat_prep:
                    ss += prep
                ss += r.tokens

                if used_stranded_prep and r.eat_prep:
                    ate_stranded_prep = True
            else:
                if i != stranded_argx or not ate_stranded_prep:
                    ss += prep
        if self.vmain_index == len(self.preps_vargs):
            ss += verb_main_tokens

        # Eg, "[you going home] is ...".
        conj = Conjugation.S3

        return SayResult(tokens=ss, conjugation=conj, eat_prep=False)
예제 #9
0
 def say(self, state, idiolect, context):
     ss = list(self.name)
     if context.is_possessive:
         ss.append(POSSESSIVE_MARK)
     conj = self.decide_conjugation(state, idiolect, context)
     return SayResult(tokens=ss, conjugation=conj, eat_prep=False)
예제 #10
0
 def posdet_say(self, dec, use_whom):
     """
     Declension, who/whom -> tokens
     """
     ss = self.tables.say(dec, PersonalColumn.POS_DET, use_whom)
     return SayResult(tokens=ss, conjugation=None, eat_prep=False)
예제 #11
0
 def say(self, state, idiolect, context):
     tokens = state.time_of_day_mgr.encode(self.day_offset, self.section)
     return SayResult(tokens=tokens,
                      conjugation=Conjugation.S3,
                      eat_prep=False)
예제 #12
0
 def say(self, state, idiolect, context):
     return SayResult(tokens=['there'], conjugation=None, eat_prep=False)
예제 #13
0
 def say(self, state, idiolect, context):
     return SayResult(tokens=[self.s], conjugation=S3, eat_prep=False)