lunarflu HF staff commited on
Commit
8c2219a
1 Parent(s): 5a7f0a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -125,12 +125,16 @@ async def on_message(message):
125
 
126
 
127
  def extract_adjacent_words(content, trigger, num_words=3):
128
- pattern = r'\b(\w+\s+){0,' + str(num_words) + '}' + r'\b' + r'\b'.join(map(re.escape, trigger)) + r'\b' + r'(\s+\w+){0,' + str(num_words) + '}\b'
129
- match = re.search(pattern, content, re.IGNORECASE)
130
- if match:
131
- f"----------------------------------------------------"
132
- print(f"...{match.group(0)}...")
133
- return f"...{match.group(0)}..."
 
 
 
 
134
  return content
135
 
136
 
 
125
 
126
 
127
  def extract_adjacent_words(content, trigger, num_words=3):
128
+ words = content.split()
129
+ pattern = r'\b' + r'\b\s*\b'.join(map(re.escape, trigger)) + r'\b'
130
+ regex = re.compile(pattern, re.IGNORECASE)
131
+
132
+ for match in regex.finditer(content):
133
+ start, end = match.span()
134
+ before = content[:start].split()[-num_words:]
135
+ after = content[end:].split()[:num_words]
136
+ print('...' + ' '.join(before + [match.group()] + after) + '...')
137
+ return '...' + ' '.join(before + [match.group()] + after) + '...'
138
  return content
139
 
140