Skip to content

Commit 68604de

Browse files
author
Jader Martins
committed
update
1 parent 818eb84 commit 68604de

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ scalaVersion := "2.11.10"
33
name := "kwic"
44
version := "0.0.1"
55

6-
val sparkVersion = "2.3.0"
6+
val sparkVersion = "2.1.0"
77

88

99
resolvers ++= Seq(

src/main/scala/br/unb/cic/kwic/IndexManager.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package br.unb.cic.kwic
22

33
import org.apache.spark.rdd._
44

5+
56
object IndexManager {
7+
type TMatch = (String, List[String])
68

7-
def process(lines: RDD[String]): RDD[(String, List[String])] =
9+
def process(lines: RDD[String]): RDD[TMatch] =
810
lines.flatMap { l =>
911
val words = l.split(' ').toList
1012
val indexes = (1 to words.length).map(p => (words, p-1))
@@ -15,10 +17,9 @@ object IndexManager {
1517
}
1618
}.reduceByKey((x: List[String], y: List[String]) => x++y)
1719

18-
def occurrencesOfWord(word: String,
19-
indexmap: RDD[(String, List[String])]): List[String] =
20+
def occurrencesOfWord(word: String, indexmap: RDD[TMatch]): List[String] =
2021
indexmap.lookup(word).head
2122

22-
def sortedWords(indexmap: RDD[(String, List[String])]): List[String] =
23+
def sortedWords(indexmap: RDD[TMatch]): List[String] =
2324
indexmap.keys.collect.toList.sorted
2425
}

src/main/scala/br/unb/cic/kwic/WordShift.scala

+6-16
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ object WordShift {
1111
*/
1212
def shift(words: List[String], pos: Int, target: Int) : List[String] = {
1313
val (l, r) = words.splitAt(pos)
14-
if(l.mkString(" ").length < (target -5)) {
15-
return shiftRight(l, r, target)
16-
}
17-
return shiftLeft(l, r, target)
14+
if (l.mkString(" ").length < (target -5)) shiftRight(l, r, target)
15+
else shiftLeft(l, r, target)
1816
}
1917

2018
/*
@@ -23,16 +21,12 @@ object WordShift {
2321
*of the first list is "smaller enough" than the target parameter.
2422
*/
2523
private def shiftRight(l : List[String], r : List[String], target : Int) : List[String] = {
26-
if(r.length == 0) {
27-
return l
28-
}
24+
if (r.length == 0) return l
2925

3026
val (r1, r2) = r.splitAt(r.length-1)
3127
val l1 = r2 ++ l
3228

33-
if(l1.mkString(" ").length > (target - 5)) {
34-
return l ++ r
35-
}
29+
if(l1.mkString(" ").length > (target - 5)) return l ++ r
3630

3731
return shiftRight(l1, r1, target)
3832
}
@@ -43,16 +37,12 @@ object WordShift {
4337
*of the first list is "smaller enough" than the target parameter.
4438
*/
4539
private def shiftLeft(l : List[String], r : List[String], target : Int) : List[String]= {
46-
if(l.length == 0) {
47-
return r
48-
}
40+
if(l.length == 0) return r
4941

5042
val (l1, l2) = l.splitAt(1)
5143
val r1 = r ++ l1
5244

53-
if(l2.mkString(" ").length < (target - 5)) {
54-
return l2 ++ r1
55-
}
45+
if(l2.mkString(" ").length < (target - 5)) return l2 ++ r1
5646

5747
return shiftLeft(l2, r1, target)
5848
}

0 commit comments

Comments
 (0)