Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
adjusting regex for num_words
Browse files
app.py
CHANGED
@@ -95,16 +95,14 @@ async def on_message(message):
|
|
95 |
|
96 |
|
97 |
def extract_adjacent_words(content, trigger, num_words=5):
|
98 |
-
words = content.split()
|
99 |
pattern = r'\b' + r'\b\s*\b'.join(map(re.escape, trigger)) + r'\b'
|
100 |
regex = re.compile(pattern, re.IGNORECASE)
|
101 |
|
102 |
for match in regex.finditer(content):
|
103 |
start, end = match.span()
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
return '...' + ' '.join(before + [match.group()] + after) + '...'
|
108 |
return content
|
109 |
|
110 |
|
|
|
95 |
|
96 |
|
97 |
def extract_adjacent_words(content, trigger, num_words=5):
|
|
|
98 |
pattern = r'\b' + r'\b\s*\b'.join(map(re.escape, trigger)) + r'\b'
|
99 |
regex = re.compile(pattern, re.IGNORECASE)
|
100 |
|
101 |
for match in regex.finditer(content):
|
102 |
start, end = match.span()
|
103 |
+
before_words = re.findall(r'\b\w+\b', content[:start])[-num_words:]
|
104 |
+
after_words = re.findall(r'\b\w+\b', content[end:end + 100])[:num_words]
|
105 |
+
return '...' + ' '.join(before_words + [match.group()] + after_words) + '...'
|
|
|
106 |
return content
|
107 |
|
108 |
|