Пример #1
0
    def decode_personal_pronoun(self, deep_ref, from_xx, to_xx):
        d = deep_ref.arg.declension

        if d == Declension.WHO1:
            who = Noun.make_who()
            x = self.add_idea(who)
            return [[x]]
        elif d == Declension.WHO2:
            who = Noun.make_who()
            x = self.add_idea(who)
            return [[x]]
        elif d == Declension.YOU:
            return [to_xx]
        elif d == Declension.HE:
            features = NounFeatures(gender=Gender.MALE, kind='person')
        elif d == Declension.SHE:
            features = NounFeatures(gender=Gender.FEMALE, kind='person')
        elif d == Declension.THEY2:
            features = NounFeatures(kind='person')
            xx = self.resolve_plural_noun(features)
            return [xx]
        else:
            print 'Unhandled declension, bailing on this dsen:', \
                Declension.to_str[d]
            return None

        xx = self.resolve_one_noun(features)
        return [xx]
Пример #2
0
    def decode_personal_pronoun(self, deep_ref, from_xx, to_xx):
        d = deep_ref.arg.declension

        if d == Declension.WHO1:
            who = Noun.make_who()
            x = self.add_idea(who)
            return [[x]]
        elif d == Declension.WHO2:
            who = Noun.make_who()
            x = self.add_idea(who)
            return [[x]]
        elif d == Declension.YOU:
            return [to_xx]
        elif d == Declension.HE:
            features = NounFeatures(gender=Gender.MALE, kind='person')
        elif d == Declension.SHE:
            features = NounFeatures(gender=Gender.FEMALE, kind='person')
        elif d == Declension.THEY2:
            features = NounFeatures(kind='person')
            xx = self.resolve_plural_noun(features)
            return [xx]
        else:
            print 'Unhandled declension, bailing on this dsen:', \
                Declension.to_str[d]
            return None

        xx = self.resolve_one_noun(features)
        return [xx]
Пример #3
0
    def resolve_one_noun(self, features):
        for i in xrange(len(self.ideas) - 1, -1, -1):
            idea = self.ideas[i]
            if not idea:
                continue
            if idea.matches_noun_features(
                    features, self.ideas, self.place_kinds):
                idea = Reverb(i)
                x = self.add_idea(idea)
                x = self.go_to_the_source(x)
                return [x]

        idea = Noun.from_features(features)
        x = self.add_idea(idea)
        return [x]
Пример #4
0
    def resolve_one_noun(self, features):
        for i in xrange(len(self.ideas) - 1, -1, -1):
            idea = self.ideas[i]
            if not idea:
                continue
            if idea.matches_noun_features(features, self.ideas,
                                          self.place_kinds):
                idea = Reverb(i)
                x = self.add_idea(idea)
                x = self.go_to_the_source(x)
                return [x]

        idea = Noun.from_features(features)
        x = self.add_idea(idea)
        return [x]
Пример #5
0
    def resolve_plural_noun(self, features):
        rr = []
        for i in xrange(len(self.ideas) - 1, -1, -1):
            idea = self.ideas[i]
            if not idea:
                continue
            if idea.matches_noun_features(
                    features, self.ideas, self.place_kinds):
                idea = Reverb(i)
                x = self.add_idea(idea)
                x = self.go_to_the_source(x)
                rr.append(x)
                if 1 < len(rr):
                    return rr

        idea = Noun.from_feature(features)
        x = self.add_idea(idea)
        return [x]
Пример #6
0
    def resolve_plural_noun(self, features):
        rr = []
        for i in xrange(len(self.ideas) - 1, -1, -1):
            idea = self.ideas[i]
            if not idea:
                continue
            if idea.matches_noun_features(features, self.ideas,
                                          self.place_kinds):
                idea = Reverb(i)
                x = self.add_idea(idea)
                x = self.go_to_the_source(x)
                rr.append(x)
                if 1 < len(rr):
                    return rr

        idea = Noun.from_feature(features)
        x = self.add_idea(idea)
        return [x]
Пример #7
0
    def decode_common_noun(self, deep_ref, from_xx, to_xx):
        n = deep_ref.arg

        assert not n.possessor

        if n.number and n.number.is_interrogative() and not n.rels_nargs:
            assert n.selector.correlative == Correlative.INDEF
            idea = Noun(query=Query.CARDINALITY,
                        attributes=n.attributes,
                        kind=n.noun)
            x = self.add_idea(idea)
            return [[x]]

        if n.selector.correlative == Correlative.INDEF and not n.rels_nargs:
            if n.selector.n_min == N5.SING and n.selector.n_max == N5.SING:
                # Create a new one.
                idea = Noun(attributes=n.attributes, kind=n.noun)
                x = self.add_idea(idea)
                return [[x]]
            elif N5.DUAL <= n.selector.n_min:
                # It's referring to all of instances with those fields.
                features = NounFeatures(query=Query.GENERIC,
                                        attributes=n.attributes,
                                        kind=n.noun)
                xx = self.resolve_one_noun(features)
                return [xx]
            else:
                assert False

        assert n.selector.correlative in [
            Correlative.DEF,
            Correlative.DIST,
            Correlative.INTR,
        ]

        if n.selector.correlative == Correlative.INTR:
            idea = Noun(query=Query.IDENTITY,
                        attributes=n.attributes,
                        kind=n.noun)
            x = self.add_idea(idea)
            return [[x]]

        d = n.selector.dump()
        del d['correlative']
        if d != {
                'n_min': 'SING',
                'n_max': 'SING',
                'of_n_min': 'SING',
                'of_n_max': 'SING',
        }:
            pass  # TODO: actually handle this correctly.

        rel2xxx = {}
        for rel, narg in n.rels_nargs:
            sub_ref = DeepReference(owning_clause_id=deep_ref.owning_clause_id,
                                    is_subj=False,
                                    arg=narg)
            xxx = self.decode(sub_ref, from_xx, to_xx)
            rel2xxx[rel] = xxx

        if n.noun == 'person':
            gender = None
        else:
            gender = Gender.NEUTER
        features = NounFeatures(attributes=n.attributes,
                                kind=n.noun,
                                gender=gender,
                                rel2xxx=rel2xxx)
        xx = self.resolve_one_noun(features)
        return [xx]
Пример #8
0
 def decode_adjective(self, deep_ref, from_xx, to_xx):
     adj = deep_ref.arg.s
     noun = Noun(attributes=[adj])
     x = self.add_idea(noun)
     return [[x]]
Пример #9
0
 def new(self):
     uid = randint(0, 0x7FFFFFFFFFFFFFFF)
     assert uid not in self.uid2x
     x = self.memory.add_idea(Noun(kind='person'))
     self.uid2x[uid] = x
     return uid