| Title: | Political Linguistics Toolkit - Gaffes, Phonetics, and Text Transformation |
|---|---|
| Description: | A comprehensive toolkit for political linguistics featuring a museum of famous digital gaffes, phonetic transformation algorithms (Soundex, consonant shifts), QWERTY keyboard geometry for typo simulation, syllable parsing, word blending (portmanteau creation), and text corruption analysis. Originally inspired by the infamous "covfefe" tweet of 2017. |
| Authors: | Michael Kirchner [aut, cre] |
| Maintainer: | Michael Kirchner <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-05-26 07:49:42 UTC |
| Source: | https://github.com/mkirch/covfefe |
Replaces one or more characters with adjacent keys.
adjacent_key_typo(word, n_typos = 1L)adjacent_key_typo(word, n_typos = 1L)
word |
Character. Word to typo-fy |
n_typos |
Integer. Number of typos to introduce (default 1) |
Character. Word with typos
set.seed(123) adjacent_key_typo("hello")set.seed(123) adjacent_key_typo("hello")
Analyze a gaffe comprehensively
analyze_gaffe(gaffe, intended)analyze_gaffe(gaffe, intended)
gaffe |
Character. The typo/gaffe |
intended |
Character. The intended word |
List with comprehensive analysis
analyze_gaffe("covfefe", "coverage")analyze_gaffe("covfefe", "coverage")
Score how well a word is a blend of two others
blend_score(blend, word1, word2)blend_score(blend, word1, word2)
blend |
Character. Potential blend |
word1 |
Character. First source word |
word2 |
Character. Second source word |
Numeric. Score from 0 (poor blend) to 1 (perfect blend)
blend_score("brunch", "breakfast", "lunch")blend_score("brunch", "breakfast", "lunch")
Combines the beginning of word1 with the end of word2.
blend_words(word1, word2, overlap = NULL)blend_words(word1, word2, overlap = NULL)
word1 |
Character. First word (contributes beginning) |
word2 |
Character. Second word (contributes ending) |
overlap |
Integer. Desired overlap characters (auto-detected if NULL) |
Character. Blended word
blend_words("breakfast", "lunch") # "brunch" or similar blend_words("refute", "repudiate") # "refudiate" or similarblend_words("breakfast", "lunch") # "brunch" or similar blend_words("refute", "repudiate") # "refudiate" or similar
Pairs of consonants that are phonetically similar and commonly confused.
consonant_pairsconsonant_pairs
A named list mapping consonants to their phonetically similar pairs.
Corrupt text with specified error type
corrupt_text(text, type = "random", position = NULL)corrupt_text(text, type = "random", position = NULL)
text |
Character. Text to corrupt |
type |
Character. Type of corruption: "keyboard", "phonetic", "double", "truncate", "swap", "omit", "random" |
position |
Integer. Position for positional corruptions (NULL = random) |
Character. Corrupted text
set.seed(42) corrupt_text("hello", type = "keyboard") corrupt_text("coverage", type = "truncate", position = 3)set.seed(42) corrupt_text("hello", type = "keyboard") corrupt_text("coverage", type = "truncate", position = 3)
Attempt to produce your own historic typos. This function takes a word and performs the following algorithm thanks to this codegolf thread:
1. Include all characters up through the first vowel in the word. (co)
2. Identifies the next consonant after the first vowel in the word. (v)
3. Changes that consonant to a phonetically similar consonant. (f)
4. Finds the next vowel after that consonant. (e)
5. Combines the two, and repeats. (fefe)
6. Puts it all together: covfefe
covfefy(str = "coverage")covfefy(str = "coverage")
str |
Character string of word to covfefy. Defaults to "coverage". |
covfefy("coverage") covfefy("programming") covfefy("president") covfefy("tropical")covfefy("coverage") covfefy("programming") covfefy("president") covfefy("tropical")
Calls covfefy() and uses rules to decide which, if any, word is
covfefefied.
covfefySentence( sent = paste0("Despite the constant negative", " press coverage we are going ", "to Make America Great Again"), endSentence = TRUE )covfefySentence( sent = paste0("Despite the constant negative", " press coverage we are going ", "to Make America Great Again"), endSentence = TRUE )
sent |
Character string of sentence to covfefy. Defaults to the famous tweet. |
endSentence |
Boolean where TRUE forces use of punctuation. |
covfefySentence(paste0("Despite the constant negative press coverage,", "we are going to Make America Great Again"))covfefySentence(paste0("Despite the constant negative press coverage,", "we are going to Make America Great Again"))
Calls covfefySentences() and uses rules to decide which,
if any, sentences are covfefefied.
covfefySpeech( text = system.file("extdata", "inauguration.txt", package = "covfefe"), out = file.path(tempdir(), "covfefe_inauguration.txt") )covfefySpeech( text = system.file("extdata", "inauguration.txt", package = "covfefe"), out = file.path(tempdir(), "covfefe_inauguration.txt") )
text |
Location of input .txt file. |
out |
Location of output .txt file. |
covfefySpeech()covfefySpeech()
Detect possible source words for a blend
detect_blend(blend, candidates)detect_blend(blend, candidates)
blend |
Character. The blended word |
candidates |
Character vector. Possible source words |
Character vector. Most likely source words
detect_blend("brunch", c("breakfast", "lunch", "dinner"))detect_blend("brunch", c("breakfast", "lunch", "dinner"))
Detect likely typo type
detect_typo_type(typo, intended = NULL)detect_typo_type(typo, intended = NULL)
typo |
Character. The typo'd word |
intended |
Character. The intended word (if known) |
List with possible_types and confidence scores
detect_typo_type("tesy", "test")detect_typo_type("tesy", "test")
A data frame containing 13 famous digital gaffes and typos from political figures.
gaffesgaffes
A data frame with 13 rows and 8 variables:
Unique identifier for the gaffe
The intended word or phrase
The actual typo or gaffe
The person who made the gaffe
Year the gaffe occurred
Platform where the gaffe appeared (Twitter, Truth Social, etc.)
Classification of the typo type
Brief description of the context
Various news sources and social media archives
Garble a sentence with random corruptions
garble_sentence(sentence, corruption_rate = 0.3)garble_sentence(sentence, corruption_rate = 0.3)
sentence |
Character. Sentence to garble |
corruption_rate |
Numeric. Fraction of words to corrupt (0-1) |
Character. Garbled sentence
set.seed(42) garble_sentence("This is a test", corruption_rate = 0.5)set.seed(42) garble_sentence("This is a test", corruption_rate = 0.5)
Get phonetic group for a consonant
get_phonetic_group(consonant)get_phonetic_group(consonant)
consonant |
Character. Single consonant |
Character. Group name (labial, dental, velar, etc.)
get_phonetic_group("b") # "labial"get_phonetic_group("b") # "labial"
Check if two keys are adjacent
is_keyboard_adjacent(key1, key2)is_keyboard_adjacent(key1, key2)
key1 |
Character. First key |
key2 |
Character. Second key |
Logical
is_keyboard_adjacent("a", "s") # TRUE is_keyboard_adjacent("a", "p") # FALSEis_keyboard_adjacent("a", "s") # TRUE is_keyboard_adjacent("a", "p") # FALSE
Adds random adjacent characters to simulate accidental key presses.
keyboard_mash(word, n_extra = 3L)keyboard_mash(word, n_extra = 3L)
word |
Character. Base word |
n_extra |
Integer. Number of extra characters to add |
Character. Word with extra characters
set.seed(456) keyboard_mash("powerful") # Might produce "powerfulnnz"set.seed(456) keyboard_mash("powerful") # Might produce "powerfulnnz"
Filter gaffes by person
museum_by_person(pattern)museum_by_person(pattern)
pattern |
Character. Regex pattern to match person name |
Data frame of matching gaffes
museum_by_person("Trump")museum_by_person("Trump")
Filter gaffes by typo type
museum_by_type(type)museum_by_type(type)
type |
Character. Type of typo (e.g., "blend", "keyboard_mash") |
Data frame of matching gaffes
museum_by_type("blend")museum_by_type("blend")
Filter gaffes by year
museum_by_year(year)museum_by_year(year)
year |
Integer. Year to filter by |
Data frame of matching gaffes
museum_by_year(2017)museum_by_year(2017)
List all gaffes in the museum
museum_list()museum_list()
Character vector of gaffe IDs
museum_list()museum_list()
Look up a specific gaffe
museum_lookup(id)museum_lookup(id)
id |
Character. The gaffe ID (e.g., "covfefe", "potatoe") |
List with gaffe details
museum_lookup("covfefe")museum_lookup("covfefe")
Get a random gaffe from the museum
museum_random()museum_random()
List with gaffe details
set.seed(42) museum_random()set.seed(42) museum_random()
Parse syllable into onset, nucleus, coda
onset_nucleus_coda(syllable)onset_nucleus_coda(syllable)
syllable |
Character. Single syllable |
List with onset, nucleus, coda components
onset_nucleus_coda("cat") # list(onset="c", nucleus="a", coda="t")onset_nucleus_coda("cat") # list(onset="c", nucleus="a", coda="t")
Uses Soundex codes to measure phonetic similarity.
phonetic_distance(word1, word2)phonetic_distance(word1, word2)
word1 |
Character. First word |
word2 |
Character. Second word |
Numeric. Distance (0 = identical, higher = more different)
phonetic_distance("coverage", "covfefe")phonetic_distance("coverage", "covfefe")
Consonants grouped by place of articulation.
phonetic_groupsphonetic_groups
A named list with groups: labial, dental, velar, sibilant, liquid, glide.
Shift consonant to phonetically similar consonant
phonetic_shift(word, target)phonetic_shift(word, target)
word |
Character. Word to transform |
target |
Character. Consonant to shift (if found) |
Character. Transformed word
phonetic_shift("coverage", "v") # "coferage"phonetic_shift("coverage", "v") # "coferage"
A list containing adjacent keys for each letter on a QWERTY keyboard.
qwerty_adjacencyqwerty_adjacency
A named list with 26 elements (a-z), each containing a character vector of adjacent key letters.
Get adjacent keys on QWERTY keyboard
qwerty_adjacent(key)qwerty_adjacent(key)
key |
Character. Single lowercase letter |
Character vector of adjacent keys
qwerty_adjacent("f")qwerty_adjacent("f")
Uses Euclidean distance based on key positions.
qwerty_distance(key1, key2)qwerty_distance(key1, key2)
key1 |
Character. First key (single lowercase letter) |
key2 |
Character. Second key (single lowercase letter) |
Numeric distance
qwerty_distance("a", "s") # Adjacent = 1 qwerty_distance("a", "p") # Far apartqwerty_distance("a", "s") # Adjacent = 1 qwerty_distance("a", "p") # Far apart
A list containing row and column positions for each letter on a QWERTY keyboard.
qwerty_layoutqwerty_layout
A named list with 26 elements (a-z), each containing a named numeric vector with 'row' and 'col' positions.
American Soundex algorithm for phonetic encoding.
soundex(word)soundex(word)
word |
Character. Word to encode |
Character. 4-character Soundex code
soundex("Robert") # "R163" soundex("Rupert") # "R163" (same as Robert) soundex("Washington") # "W252"soundex("Robert") # "R163" soundex("Rupert") # "R163" (same as Robert) soundex("Washington") # "W252"
Mapping of consonants to their Soundex digit codes.
soundex_mapsoundex_map
A named character vector mapping consonants to digits 1-6.
Suggest corrections for a typo
suggest_corrections(typo, dictionary = NULL)suggest_corrections(typo, dictionary = NULL)
typo |
Character. The typo'd word |
dictionary |
Character vector. Optional custom dictionary |
Character vector of suggested corrections
suggest_corrections("tesy")suggest_corrections("tesy")
Uses a simplified vowel-based algorithm.
syllabify(word)syllabify(word)
word |
Character. Word to syllabify |
Character vector of syllables
syllabify("hello") # c("hel", "lo") syllabify("coverage") # c("cov", "er", "age")syllabify("hello") # c("hel", "lo") syllabify("coverage") # c("cov", "er", "age")
Count syllables in a word
syllable_count(word)syllable_count(word)
word |
Character. Word to count |
Integer. Number of syllables
syllable_count("hello") # 2syllable_count("hello") # 2
Swap syllables between two words
syllable_swap(word1, word2, position = 1L)syllable_swap(word1, word2, position = 1L)
word1 |
Character. First word |
word2 |
Character. Second word |
position |
Integer. Which syllable to swap (1-indexed) |
Character vector of length 2 with swapped words
syllable_swap("coverage", "president", 1)syllable_swap("coverage", "president", 1)
Shift vowels in a word
vowel_shift(word, from, to)vowel_shift(word, from, to)
word |
Character. Word to transform |
from |
Character. Vowel to replace |
to |
Character. Replacement vowel |
Character. Transformed word
vowel_shift("test", "e", "i") # "tist"vowel_shift("test", "e", "i") # "tist"
Possible vowel shifts inspired by historical sound changes.
vowel_shiftsvowel_shifts
A named list mapping vowels to possible shift targets.