Now, I am trying to create a Map[String, String] from the csv file where the word is the Key*, and the pronunciation is the Value. I have managed to do it myself using the code below.
def mapFile(filename: String): Map[String, String] = {
var content: String = ""
val file: BufferedSource = Source.fromFile(filename)
for (line <- file.getLines()) {
if (!line.contains("//")) {
content = content + line + "//"
}
}
content.split("//").map(_.split(" ")).map(arr => arr(0) -> arr(1)).toMap
}
So file reads the text file, and for every line in the the text file that is not //, it creates a string and then splits the string into key-value, key being split by " " and value being split by `"//"``.
However, it is too slow.
Is there a more efficient way i can create the map without it taking 5 minutes?
if (ok == false)is the same thing asif (!line.contains(";;;")). Choose the 2nd one, it makes more sense.