FredZhang7
commited on
Commit
•
0eef561
1
Parent(s):
81017b5
Reveal prompt preprocessing
Browse files- preprocess.py +30 -0
preprocess.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
|
3 |
+
def clean_sentence(sentence):
|
4 |
+
# Remove "!", "?", ".", "(", ")" from the sentence
|
5 |
+
sentence = re.sub(r"[!.?()]", "", sentence)
|
6 |
+
|
7 |
+
# Replace " , " with an empty space
|
8 |
+
sentence = re.sub(r" , ", " ", sentence)
|
9 |
+
|
10 |
+
# Remove any trailing commas
|
11 |
+
sentence = re.sub(r"^,|,$", "", sentence)
|
12 |
+
|
13 |
+
# Strip spaces
|
14 |
+
sentence = sentence.strip()
|
15 |
+
|
16 |
+
# Remove any usernames
|
17 |
+
words = sentence.split(", ")
|
18 |
+
result = []
|
19 |
+
for word in words:
|
20 |
+
word = word.strip()
|
21 |
+
if word == 'v':
|
22 |
+
result.append(word)
|
23 |
+
continue
|
24 |
+
if len(word) < 2:
|
25 |
+
continue
|
26 |
+
if any(char.isdigit() for char in word) and word not in ["1girl", "1boy", "1koma", "1other"]:
|
27 |
+
continue
|
28 |
+
result.append(word)
|
29 |
+
|
30 |
+
return ", ".join(result)
|