1
2
3
4
5
6
7
8 """
9 This module performs the anaphora resolution functionality for DRT.py. It may be
10 modified or swapped out to test different resolution techniques.
11 """
12
13 from nltk.sem import logic
14
26
30
34
38
43
46
49 trail_addition = [self, self.first]
50 return self.__class__(self.first.resolve_anaphora(trail + trail_addition),
51 self.second.resolve_anaphora(trail + trail_addition))
52
55
60
63
66 if self.is_pronoun_function():
67 possible_antecedents = PossibleAntecedents()
68 for ancestor in trail:
69 try:
70 refexs = [self.make_VariableExpression(ref)
71 for ref in ancestor.get_refs()]
72 possible_antecedents.extend(refexs)
73 except AttributeError:
74 pass
75
76
77
78
79
80 possible_antecedents.remove(self.argument)
81 equalityExpression = self.get_EqualityExpression()
82 if len(possible_antecedents) == 1:
83 equalityExp = equalityExpression(self.argument,
84 possible_antecedents[0])
85 else:
86 equalityExp = equalityExpression(self.argument,
87 possible_antecedents)
88 return equalityExp
89 else:
90 r_function = self.function.resolve_anaphora(trail + [self])
91 r_argument = self.argument.resolve_anaphora(trail + [self])
92 return self.__class__(r_function, r_argument)
93
95 - def free(self, indvar_only=True):
96 """Set of free variables."""
97 return set(self)
98
99 - def replace(self, variable, expression, replace_bound=False):
100 """Replace all instances of variable v with expression E in self,
101 where v is free in self."""
102 result = PossibleAntecedents()
103 for item in self:
104 if item == variable:
105 self.append(expression)
106 else:
107 self.append(item)
108 return result
109
112
114 return '[' + ','.join([str(item) for item in self]) + ']'
115