pre_solution2/docdiff.scala
changeset 384 6e1237691307
parent 346 663c2a9108d1
equal deleted inserted replaced
383:c02929f2647c 384:6e1237691307
    32 def prod(lst1: List[String], lst2: List[String]) : Int = {
    32 def prod(lst1: List[String], lst2: List[String]) : Int = {
    33     val words = (lst1 ::: lst2).distinct
    33     val words = (lst1 ::: lst2).distinct
    34     val occs1 = occurrences(lst1)
    34     val occs1 = occurrences(lst1)
    35     val occs2 = occurrences(lst2)
    35     val occs2 = occurrences(lst2)
    36     words.map{ w => occs1.getOrElse(w, 0) * occs2.getOrElse(w, 0) }.sum
    36     words.map{ w => occs1.getOrElse(w, 0) * occs2.getOrElse(w, 0) }.sum
    37 }
    37 }          
    38 
    38 
    39 //(4) Complete the functions overlap and similarity. The overlap of
    39 //(4) Complete the functions overlap and similarity. The overlap of
    40 //    two documents is calculated by the formula given in the assignment
    40 //    two documents is calculated by the formula given in the assignment
    41 //    description. The similarity of two strings is given by the overlap
    41 //    description. The similarity of two strings is given by the overlap
    42 //    of the cleaned (see (1)) strings.  
    42 //    of the cleaned (see (1)) strings.