http://ijece.iaescore.com Smart detection of offensive words in social media using the soundex algorithm and permuterm

Info 2021 Offensive posts in the social media that are inappropriate for a specific age, level of maturity, or impression are quite often destined more to unadult than adult participants. Nowadays, the growth in the number of the masked offensive words in the social media is one of the ethically challenging problems. Thus, there has been growing interest in development of methods that can automatically detect posts with such words. This study aimed at developing a method that can detect the masked offensive words in which partial alteration of the word may trick the conventional monitoring systems when being posted on social media. The proposed method progresses in a series of phases that can be broken down into a pre-processing phase, which includes filtering, tokenization, and stemming; offensive word extraction phase, which relies on using the soundex algorithm and permuterm index; and a post-processing phase that classifies the users’ posts in order to highlight the offensive content. Accordingly, the method detects the masked offensive words in the written text, thus forbidding certain types of offensive words from being published. Results of evaluation of performance of the proposed method indicate a 99% accuracy of detection of offensive


INTRODUCTION
The World Wide Web and the Internet have been making constant changes in people's everyday life [1]. Social networks became the most popular platforms on the Internet. They are currently used in various sectors and their users interact on them to realize several benefits. However, those users usually come from diverse cultures and educational backgrounds [2]. Therefore, offensive, user-generated content that is published on the various social netwroks may make the users' online experiences inconvenient since offensive words may insult and annoy them; they may show aggression against some cultures, societies, races, and/or ideologies [3]. In addition, cyberbullying is a form of offensive language and is one of the major reasons behind suicide [4].
There are cases when legal actions were taken against social media companies such as Twitter and Facebook because they did not prevent users from posting offensive words and/or hate speech [5]. However, many authors of offensive content use different variations of the same word to mask the cursing words in their attempts to avoid the automated tools which are designed to detect such content. Specifically, they replace some alphabetical letters by symbols or numbers with similar shape or sound and insert those  [6]. This makes manual detection of the offensive content and its removal from social networks a boring task. Consequently, there is a need for development of an effective automated tool that can detect such offensive content in social networks.
Several studies have been conducted on offensive language detection in user-generated online content. In general, they aimed at eliminating the posting of offensive language and focused on detecting different types of offenses such as cyberbullying [7]- [9], profanity or curse [10], [11], harassment [12], [13], and offensive language in general [14]- [16]. Most of these studies were based on feature extraction of offensive words from the text. Some of these studies employed the bag-of-words model [17] and some others used lexical features [18]. However, evidence supports that the various approaches followd thus far fail to understand the context of the words and sentences.
Use of lexical features can make success in easy detection of offensive entities without the need for consideration of the syntactical structure of the whole sentence. But, they fail to distinguish the sentences that contain the same offensive words but in a different order or the words which have some of their characters replaced with symbols and numbers of similar shape or sound [19]. Parts-of-speech (POS) features have also been used in offensive speech detection problems as explained in [20].
In other respects, text classifiers have been used to solve the problem of detecting offensive content. So far, the support vector machines [9], [17], [21]- [24] and the naïve bayes classifier [21]- [23] are the most popular classifiers that have been employed for this purpose. A multi-level text classifier for offensive content detection was proposed in [3] as an automated offensive content detection method. This method extracts features at different conceptual levels. Moreover, offensive detection software was designed and run at a high level of accuracy with both normal and offensive text. Furthermore, the researchers in [2] introduced a new approach that automatically classifies tweets on Twitter into three categories: offensive, hateful, and clean tweets. Experiments on this approach were performed using a Twitter dataset, considering n-grams as features and passing their term frequency-inverse document frequency (TFIDF) values to multiple machine learning models. Performance evaluation uncovered that this approach has a detection accuracy of 95.6%.
Recently, several studies highlighted the importance of using sentiment-based methods to detect offensive language. For example, the researchers in [19] applied sentiment analysis to detect bullying in tweets and used latent dirichlet allocation (LDA) topic models to recognize relevant topics in these texts. Moreover, several studies discussed different approaches to harassment detection on Web 2.0 [25], [26]. Additionally, logistic regression [16], [21], [23], random forests [21], decision trees [21], long short-term memory networks [9], and convolutional neural networks [27] were used to solve the offensive text detection problem. However, none of the efforts reported in the literature has been designed specifically to solve the problem of detecting and removing the offensive text that is masked by replacement of some of the alphabetical letters of the offensive terms with symbols and numbers that have similar shape or sound, or by insertion of symbols and special characters between letters. Thus, this study was intended to overcome the problem of automatically detecting the offensive text that has been masked. Our approach to solving this problem is based on development of a new method that integrates the Soundex algorithm with the permuterm index.

RESEARCH METHOD AND THE PROPOSED APPROACH
Detection of masked offensive content in short time and with low effort is an essential requirement and there is bad need for provision of robust solutions to meet it. Therefore, the method we propose in this study aims at improving the capability to automatically detect the masked offensive words. This method incorporates the Soundex algorithm and permuterm index for the purpose of extracting the offensive terms in an elegant, logical, and accurate way.
Soundex is one of the phonetic algorithms widely used for English language text detection. The main goal of this algorithm is to match homophone names, regardless of minor differences in spelling or pronunciation, by encoding them with the same representation [28]. The permuterm index, on the other hand, is a smart and time-efficient approach to solving the string-matching problem in which pattern queries may include one wildcard symbol [29].
As shown in Figure 1, our proposed method begins with importing the user's post as a tweet. Then, it starts the pre-processing phase wherein it performs the following processes: filtering, tokenization, and stemming. Subsequently, it begins the extractions phase, in which it applies the Soundex algorithm and the permuterm index together for data training and extraction of the offensive words. Thereafter, the postprocessing phase is started. In this phase, the method shows the detected offensive terms, if any. This method was implemented using the Python programming language and its graphical user interface; Tkinter.

Pre-processing
In the pre-processing phase (Algorithm 1), our proposed method imports the user's posts which are due to be processed. Basically, this phase consists of three processes: filtering, tokenization, and stemming. A briefing on each follow.

Filtering
The filtering process improves the efficiency of the Soundex algorithm and the permuterm index by rationally reducing the size of the imported text file. It removes the repetitive words that do not change the meaning of the sentence and do not have any value (e.g., prepositions and stop words). Furthermore, it removes all hyperlinks, images, audio records, and videos.

Tokenization
Tokenization splits the input text into tokens and generates a series of them. It also eliminates the spaces so that each word can be separated by only one white space. This step is necessary to transform the input text that has unstructured form into a suitable form for processing. To perform these tasks and ensure the splitting of the input text into tokens, the tokenization process uses the String.Split() method [30].

Stemming
Stemming is designed to obtain the token root using a data set that contains the roots of offensive words. This data set is used to classify the user's posts. It is trained using the Soundex algorithm and Permutrm Index. In order to obtain the root of every token, our approach uses the Porter stemming algorithm, which returns the English words to their roots [31]. IF P ∈ Filter list 4 : P ←remove the items that are found in the filter list from the post 5 : else 6 : P← P 7 : End if 8 : For each in P do 9 : token ← tokenizing( ) ∴ Split the post 10 : (term ) ← stemming( ) ∴ Stemming the token 11 : ← add term to list 12 : End for 13 : Return T 14 : End procedure

Extraction of offensive terms
In the extraction phase, we employ the Soundex algorithm and permuterm index in order to detect the offensive content that matches the offensive data existing in the training data sub-sets.

The soundex algorithm
The Soundex algorithm assigns values to terms in such a manner that similar-sounding terms get the same value [32]. These values are known as Soundex encodings. If Soundex encoding of any word in the post matches any Soundex encoding in the data set, then it is concluded that this post contains offensive content [33]. Table 1 presents the Soundex phonetic code for each English language letter.
In this study, the Soundex algorithm (Algorithm 2) begins with replacement of the first two letters as shown in Table 2. Then, the remaining letters of the term are replaced with phonetic code. Afterwards, any adjacent repetitions of codes and all occurrences of the 0 code are removed. Thereafter, the procedure returns the first four characters right-padding with zeroes if there are fewer than four letters. Table 3 illustrates how the Soundex algorithm works with one of the most popular offensive words, namely, fuck. This word is written in a variety of different ways but with a similar phoneme.  : t ← replace first with "T" 9 : else ( ) ='DH' 10 : ← replace first with "D" 11 : else (t ) ='SH' 12 : ← replace first with "S" 13 : else (t ) ='CK' 14 : t ← replace first with "C" 15 : else (t ) ='GH' 16 : ← replace first with "G" 17 : else ( ) ='KH' 18 : ← replace with "K" 19 : else (t ) ='CH' 20 : ← replace with "C" 21 : End if 22 : S ← soundex( ) 23 : End for 24 : Return S 25 : End procedure Table 3. Examples on functioning of the Soundex algorithm step-by-step Example Step 1 Step 2 Step 3 Step

The permuterm index
The permuterm index (Algorithm 3) is used to support wildcard querying over normal language text [34]. It adds a special character "$" to words. As an example, the word fuck was represented in the training sub-set as fuck$, uck$f, ck$fu, or k$fuc. Let us assume that the user posts 'fu*k' or 'fu2k'. This index will look for fu and k, ending up with k$fu. It simply rotates the wildcard so that it will appear at the end only. For each in T do 4 : ← permuterm( ) 5 : End for 6 : Return PT 7 : End procedure

Post-processing
In this phase (Algorithm 4), our approach classifies the user's post into offensive or non-offensive text based on the results of matching between the value returned by the soundex algorithm or the permuterm index and the content of the training sub-sets. F ← true 7 : Print "Found Offensive:" + si 8 : else 9 : For each PT do 10 : IF ∈ training sub-set of Permuterm 11 : F ← true 12 : Print "Found Offensive:" + 13 : End if 14 : End for 15 : End if 16 : End for 17 : End procedure

PERFORMANCE EVALUATION
The data used in this study were collected during the period 1 October 2019 to 28 February 2020. As we are focusing on English tweets, this study picked the most popular 20 offensive English words according to [6]. Subsequently, five-hundred English tweets were manually selected as a sample for this study. Half of the instances in this sample were identified as offensive tweets while the other half were non-offensive tweets.
To fully evaluate performance of our proposed approach, precision (P), recall (R), the F-measure (F), and accuracy (A) were adopted as the performance evaluation measures, computed, and presented in a confusion matrix as shown in Table 4. In the confusion matrix, the acronyms TP, FP, TN, and FN stand for the numbers of correctly-classified offensive words, incorrectly-classified offensive words, correctly classified non-offensive words, and incorrectly classified non-offensive words, respectively. Outcomes of simulation experiments of the proposed approach are given by Table 4. The test values in the confusion matrix see in Table 4 confirm validity of the proposed method as portrayed in Figure 2.
Values of the parameters of the confusion matrix see in Table 4 were used to calculate the values of the aforementioned four performance evaluation metrics, i.e., P, R, A, and the F-measure. Precision (P) is a measure of completeness. It is calculated using as (1): Recall (R) is a measure of exactness. It is computed according to (2): The F-measure (F) is a weighted harmonic mean of precision and recall values. It is computed (4): The values of these four metrics that are associated with the proposed method are listed in Table 5 and depicted in Figure 3. These performance assessment outcomes point out that the proposed method has an offensive word detection accuracy of 99% and precision of 98%. Further, it has a recall of 100% and an F-measure value of 99%. These values confirm that this method is highly efficient in detection of the masked offensive text that is posted on social media.

CONCLUSION
This study handled the problem of detection of the masked offensive content of English posts on social media. The main contribution of this study is that it developed a new method that integrates the Soundex algorithm with the Permuterm Index for detecting the prohibited words that are being posted on social media. Theoretically, our proposed method combines phonetic codes with indexed special tokens extracted from the textual input in order to efficiently detect the English terms that are commonly used for cursing and cussing. Practically, the proposed method can be used as a parental control tool that helps the parents in censoring the content being viewed by their children when surfing the Internet. The experimental results show that the proposed method has the ability to automatically detect restricted offensive content on social media with a very high accuracy (99%). In future work, we will attempt to develop a detection method that can identify offensive texts posted in images by converting the image to text and applying the herein proposed method on it.