I am trying to write a word counting program in Scala. I use the line "file":
"file"
file.map( _.split(" ")).flatMap(word => (word, 1)).reduceByKey( _ + _ )
He says that:
Value separationnot a member of Char
not a member of Char
I can’t understand how to solve it!
When you call mapin String, it completes WrappedString, which expands AbstractSeq[Char]. Therefore, when you call map, you kind of do it on Seqfrom Charnot a Seqfrom String.
map
String
WrappedString
AbstractSeq[Char]
Seq
Char
See the link below for the code https://github.com/scala/scala/blob/v2.10.2/src/library/scala/collection/immutable/WrappedString.scala
The code below is broken into spaces and returns the size, word counter.
val file = "Some test data" file.split("\\s+").size
, .
val file = "Some test data test" println(file.split("\\s+").toList.groupBy(w => w).mapValues(_.length))
, ! , Spark, RDD, - . ! :
file.flatMap(line = > line.split( ")). map (w = > (w, 1)). reduceByKey (+). saveAsTextFile (" OUT.txt")
.