Sa-m commited on
Commit
878b4f2
·
verified ·
1 Parent(s): 08c56ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -189,6 +189,26 @@ def word_cloud_generator(parsed_text_name, text_Party):
189
  print(f"Word cloud error: {e}")
190
  return None
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  # --- Main Analysis Function ---
193
  def analysis(Manifesto, Search):
194
  try:
 
189
  print(f"Word cloud error: {e}")
190
  return None
191
 
192
+ def get_all_phases_containing_tar_wrd(target_word, tar_passage, left_margin=10, right_margin=10, numLins=4):
193
+ """
194
+ Function to get all the phrases that contain the target word in a text/passage.
195
+ """
196
+ if not target_word or target_word.strip() == "":
197
+ return "Please enter a search term"
198
+
199
+ tokens = nltk.word_tokenize(tar_passage)
200
+ text = nltk.Text(tokens)
201
+ c = nltk.ConcordanceIndex(text.tokens, key=lambda s: s.lower())
202
+ offsets = c.offsets(target_word)
203
+
204
+ concordance_txt = [
205
+ text.tokens[max(0, offset - left_margin):offset + right_margin]
206
+ for offset in offsets[:numLins]
207
+ ]
208
+
209
+ result = [' '.join(con_sub) for con_sub in concordance_txt]
210
+ return '\n'.join(result)
211
+
212
  # --- Main Analysis Function ---
213
  def analysis(Manifesto, Search):
214
  try: