def METHOD_NAME(self, text: str, rng: Random) -> str:
    spacy_to_wordnet_pos = {
        "VERB": "v",
        "NOUN": "n",
        "ADV": "r",
        "ADJ": "s",
    }
    doc = self.spacy_model(text)
    perturbed_text = ""
    for token in doc:
        word = token.text
        wordnet_pos = spacy_to_wordnet_pos.get(token.pos_)
        synonyms = []
        if wordnet_pos:
            for base in wordnet._morphy(word.lower(), wordnet_pos):  # _morphy returns the base form of a word
                synonyms.extend(self.wordnet_synonyms.get(f"{base}:{wordnet_pos}", []))
        synonyms = [s for s in synonyms if s != word.lower()]
        synonyms = list(dict.fromkeys(synonyms))  # Make the list unique while preserving the order
        if synonyms and rng.uniform(0, 1) < self.prob:
            synonym = rng.choice(synonyms)
            word = match_case(word, synonym)
        perturbed_text += word + token.whitespace_
    return perturbed_text