Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -42,19 +42,32 @@ class Agent1:
|
|
42 |
text.strip().endswith('?') or
|
43 |
any(word in self.question_words for word in words))
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
def replace_pronoun(self, questions: List[str]) -> List[str]:
|
46 |
if len(questions) < 2:
|
47 |
return questions
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
if not nouns:
|
54 |
return questions
|
55 |
|
56 |
-
# Use the last noun as the antecedent
|
57 |
-
antecedent =
|
58 |
|
59 |
# Replace pronouns in subsequent questions
|
60 |
for i in range(1, len(questions)):
|
|
|
42 |
text.strip().endswith('?') or
|
43 |
any(word in self.question_words for word in words))
|
44 |
|
45 |
+
def find_noun_phrases(self, sentence):
|
46 |
+
tokens = nltk.pos_tag(word_tokenize(sentence))
|
47 |
+
noun_phrases = []
|
48 |
+
current_phrase = []
|
49 |
+
for word, tag in tokens:
|
50 |
+
if tag.startswith('NN'):
|
51 |
+
current_phrase.append(word)
|
52 |
+
elif current_phrase:
|
53 |
+
noun_phrases.append(' '.join(current_phrase))
|
54 |
+
current_phrase = []
|
55 |
+
if current_phrase:
|
56 |
+
noun_phrases.append(' '.join(current_phrase))
|
57 |
+
return noun_phrases
|
58 |
+
|
59 |
def replace_pronoun(self, questions: List[str]) -> List[str]:
|
60 |
if len(questions) < 2:
|
61 |
return questions
|
62 |
|
63 |
+
# Find noun phrases in the first question
|
64 |
+
noun_phrases = self.find_noun_phrases(questions[0])
|
65 |
+
|
66 |
+
if not noun_phrases:
|
|
|
67 |
return questions
|
68 |
|
69 |
+
# Use the last noun phrase as the antecedent
|
70 |
+
antecedent = noun_phrases[-1]
|
71 |
|
72 |
# Replace pronouns in subsequent questions
|
73 |
for i in range(1, len(questions)):
|