import scala.io.Source object MostCommonWord { def main(args: Array[String]): Unit = { // Replace 'your_text_file.txt' with the path to your text file val filePath = "your_text_file.txt" // Read the text from the file val text = Source.fromFile(filePath).mkString // Tokenize the text into words and clean them val words = text.split("\\s+").map(_.replaceAll("[^a-zA-Z]", "").toLowerCase) // Create a map to store word frequencies val wordCountMap = words.groupBy(identity).mapValues(_.length) // Find the most common word val mostCommonWord = wordCountMap.maxBy(_._2) // Print the result println(s"The most common word is '${mostCommonWord._1}' with ${mostCommonWord._2}