Affinity Answers
Assumptions:
- The input file is a text file containing one tweet per line.
- The set of racial slurs is provided in a text file, with one slur per line.
- We consider a tweet to be profane if it contains at least one racial slur.
- We measure the degree of profanity as the percentage of racial slurs in the tweet.
Explanation:
We first read in the file of racial slurs and store them in a vector called slurs. We then read in the file of tweets and store them in a vector called tweets. We then loop through each tweet in the tweets vector and perform the following steps:
- We split the tweet into individual words using the strsplit function.
- We count the number of racial slurs in the tweet by checking which words in the tweet are in the slurs vector and summing up the results.
- We calculate the degree of profanity by dividing the number of racial slurs by the total number of words in the tweet and multiplying by 100 to get a percentage.
- We print out the tweet and the degree of profanity using the cat function, with appropriate formatting.