Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Natural language processing is a subfield of computer science focusing on how co

ID: 3882756 • Letter: N

Question

Natural language processing is a subfield of computer science focusing on how computers can "make sense" of human languages like English. Before it can be used in NLP, text data must often be "cleaned." Write a method that cleans a string by removing the punctuation and common words listed below. You can assume the words in the input string are separated by single spaces, the input string does not begin or end with a space, and the input string does not contain any non-letter characters besides spaces and the punctuation below. The method should return a lower-case, space-delimited version of the input string, with the punctuation and common words removed. Punctuation marks to be removed:;: ! ? () Words to be removed: a an the is am are and or Required method header: public static String cleanText (string s) Example inputs and outputs: Input: "Omg, so like, the fox, like, totally jumped over the lazy dog!" Output: "omg so like fox like totally jumped over lazy dog" Input: "I provide this example: a, b, or c..." Output: "i provide this example b c"

Explanation / Answer

Source Code :

import java.util.Scanner;
public class Test
{
    public static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        String inp=scan.nextLine();
        System.out.println("Input: "+inp+" ");
        System.out.println("Output: "+cleanText(inp));
    }
    public static String cleanText(String s)
    {
        String str;
        int i=0;
        String[] rword={"the","a","an","of","am","or","are","and"};
        // similar to Matcher.replaceAll
        s = s.replaceAll("\p{Punct}","");
        while(i<8)
        {
        s=s.replaceAll(rword[i],"");
        i++;
        }
        return s.toLowerCase();
      
      
    }
   
}

OUTPUT

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote