Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class Expression(rotule: String, word: String)
- object Texts {
- def processSentence(str: String) : Map[String, Int] = {
- def loop(strLst: List[String], counter: Map[String, Int]): Map[String, Int] = {
- if (strLst.isEmpty || strLst.tail.isEmpty) {
- counter
- } else {
- val n = Expression(strLst.head, strLst.head) match {
- case Expression("#art", _) => "#art"
- case Expression("#sub", _) => "#sub"
- case Expression("#verbo", _) => "#verbo"
- case Expression("#pron", _) => "#pron"
- }
- if (counter.contains(n))
- loop(strLst.tail.tail, counter - n + (n -> (counter(n) + 1)))
- else
- loop(strLst.tail.tail, counter + (n -> 1))
- }
- }
- val splittedStr = str.split(" ").toList
- loop(splittedStr, Map())
- }
- def main(args: Array[String]) {
- println(processSentence("#art O #sub rato #verbo roeu #art a #sub roupa #pron do #sub rei #pron de #sub roma"))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement