Shreyas094 commited on
Commit
2982f30
·
verified ·
1 Parent(s): bb53ca6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
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
- # Simple NLP to identify potential nouns in the first question
50
- tokens = nltk.pos_tag(word_tokenize(questions[0]))
51
- nouns = [word for word, pos in tokens if pos.startswith('NN')]
52
-
53
- if not nouns:
54
  return questions
55
 
56
- # Use the last noun as the antecedent
57
- antecedent = nouns[-1]
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)):