Skip to content

Commit 2267141

Browse files
JustCallMeRayJadePrideauxKatieLGIlamaranMagesh
authored
Group1 commit
Co-authored-by: Jade Prideaux <JadePrideaux@users.noreply.github.com> Co-authored-by: Katie Gardner <KatieLG@users.noreply.github.com> Co-authored-by: Maran <ilamaran.magesh@gmail.com>
1 parent c21a49f commit 2267141

3 files changed

Lines changed: 152 additions & 0 deletions

File tree

2026-01-07/Group-1/katie.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
MARKDOWN = """
2+
# Hello world!
3+
4+
Time to:
5+
- get poisoned
6+
- have fun
7+
- tokens
8+
9+
## Plan
10+
11+
We want regex to look for certain words and replace them with less common words
12+
"""
13+
14+
import re
15+
import random
16+
import nltk
17+
18+
#nltk.download('wordnet')
19+
20+
from nltk.corpus import wordnet as wn
21+
22+
def get_similar_words(input_word: str) -> list[str]:
23+
"""Use nltk to get simliar words"""
24+
return [word for group in wn.synonyms(input_word) for word in group]
25+
26+
27+
def example_replacement(match: re.Match) -> str:
28+
"""
29+
usage re.sub(pattern, repl, string, count=0, flags=0)
30+
We are implementing the "repl" bit here
31+
"""
32+
return match.group().upper()
33+
34+
35+
def replace_char(match: re.Match) -> str:
36+
match match.group():
37+
case "ae": return "æ"
38+
case "a": return random.choice("аâāąáäãà")
39+
case "A": return random.choice("А")
40+
case "B": return random.choice("Bʙ")("В")
41+
case "c": return random.choice("с")
42+
case "C": return random.choice("С")
43+
case "e": return random.choice("eё")
44+
case "i": return random.choice("iiiįɨ")
45+
case "I": return random.choice("IÍíÌìÏïĨĩİĬĭĮɫÎîĪīıɪ")
46+
case "g": return random.choice("ġĝğģɡ")
47+
case "M": return random.choice("М")
48+
case "o": return random.choice("о")
49+
case "O": return random.choice
50+
case "|": return random.choice("ӏ")
51+
case "H": return random.choice("Н")
52+
case "T": return random.choice("Т")
53+
54+
def do_replacements(string: str) -> str:
55+
words = string.split()
56+
modified: list[str] = []
57+
for word in words:
58+
if similar := get_similar_words(word):
59+
modified.append(random.choice(similar))
60+
else:
61+
modified.append(word)
62+
resulting_markdown = "".join(modified)
63+
return re.sub(r"ae|a|A|B|c|C|e|i|I|g|M|o|\||H|T", replace_char, resulting_markdown)
64+
65+
if __name__ == "__main__":
66+
print(re.sub(r"cats", example_replacement, "cats have tails"))
67+
print(get_similar_words("small"))
68+
print(do_replacements(MARKDOWN))
69+
70+
71+

2026-01-07/Group-1/main.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
MARKDOWN = """
2+
# Happy new year!
3+
4+
Time to:
5+
- get poisoned
6+
- have fun
7+
- tokens
8+
9+
## Plan
10+
11+
We want regex to look for certain words and replace them with less common words
12+
"""
13+
14+
import re
15+
import random
16+
import nltk
17+
18+
#nltk.download('wordnet')
19+
20+
from nltk.corpus import wordnet as wn
21+
22+
def get_similar_words(input_word: str) -> list[str]:
23+
"""Use nltk to get simliar words"""
24+
return [word for group in wn.synonyms(input_word) for word in group]
25+
26+
27+
def example_replacement(match: re.Match) -> str:
28+
"""
29+
usage re.sub(pattern, repl, string, count=0, flags=0)
30+
We are implementing the "repl" bit here
31+
"""
32+
return match.group().upper()
33+
34+
35+
def replace_char(match: re.Match) -> str:
36+
match match.group():
37+
case "ae": return "æ"
38+
case "a": return random.choice("аâāąáäãà")
39+
case "A": return random.choice("А")
40+
case "B": return random.choice("Bʙ")("В")
41+
case "c": return random.choice("с")
42+
case "C": return random.choice("С")
43+
case "e": return random.choice("eё")
44+
case "i": return random.choice("iiiįɨ")
45+
case "I": return random.choice("IÍíÌìÏïĨĩİĬĭĮɫÎîĪīıɪ")
46+
case "g": return random.choice("ġĝğģɡ")
47+
case "M": return random.choice("М")
48+
case "o": return random.choice("о")
49+
case "O": return random.choice
50+
case "|": return random.choice("ӏ")
51+
case "H": return random.choice("Н")
52+
case "T": return random.choice("Т")
53+
54+
def do_replacements(string: str) -> str:
55+
lines = string.split("\n")
56+
modified: list[str] = []
57+
for line in lines:
58+
new_line: list[str] = []
59+
for word in line.split(" "):
60+
if similar := get_similar_words(word):
61+
new_line.append(similar[0])
62+
else:
63+
new_line.append(word)
64+
modified.append(" ".join(new_line))
65+
resulting_markdown = "\n".join(modified)
66+
return re.sub(r"ae|a|A|B|c|C|e|i|I|g|M|o|\||H|T", replace_char, resulting_markdown)
67+
68+
if __name__ == "__main__":
69+
print(re.sub(r"cats", example_replacement, "cats have tails"))
70+
print(get_similar_words("small"))
71+
print(do_replacements(MARKDOWN))
72+
print(do_replacements(MARKDOWN))

2026-01-07/Group-1/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
import KatiePlsHelp
3+
4+
# tokenise an input string
5+
# run a funtion from "main.py"
6+
# tokenise the output
7+
# compare results
8+
9+

0 commit comments

Comments
 (0)