IN SCALA COMPLETE THE FUNCTIONS (prod, overlap and similarity) //(1) Complete the clean function below. It should find // all words in a string using the regular expression // \w+ and the library function // // some_regex.findAllIn(some_string) // // The words should be Returned as a list of strings. def clean(s: String) : List[String] = { valreg = """\w+""".r reg.findAllIn(s).toList
IN SCALA COMPLETE THE FUNCTIONS (prod, overlap and similarity) //(1) Complete the clean function below. It should find // all words in a string using the regular expression // \w+ and the library function // // some_regex.findAllIn(some_string) // // The words should be Returned as a list of strings. def clean(s: String) : List[String] = { valreg = """\w+""".r reg.findAllIn(s).toList
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
IN SCALA
COMPLETE THE FUNCTIONS (prod, overlap and similarity)
//(1) Complete the clean function below. It should find
// all words in a string using the regular expression
// \w+ and the library function
//
// some_regex.findAllIn(some_string)
//
// The words should be Returned as a list of strings.
def clean(s: String) : List[String] = {
valreg = """\w+""".r
reg.findAllIn(s).toList
}
//clean("list of strings")
//(2) The function occurrences calculates the number of times
// strings occur in a list of strings. These occurrences should
// be calculated as a Map from strings to integers.
def occurrences(xs: List[String]): Map[String, Int] = {
valcleaned = xs.distinct
cleaned.map(x => (x , xs.count(_==x))).toMap
}
//occurrences(List("a","a","b"))
//(3) This functions calculates the dot-product of two documents
// (list of strings). For this it calculates the occurrence
// maps from (2) and then multiplies the corresponding occurrences.
// If a string does not occur in a document, the product is zero.
// The function finally sums up all products.
def prod(lst1: List[String], lst2: List[String]) : Int = ???
//(4) Complete the functions overlap and similarity. The overlap of
// two documents is calculated by the formula given in the assignment
// description. The similarity of two strings is given by the overlap
// of the cleaned strings (see (1)).
def overlap(lst1: List[String], lst2: List[String]) : Double = ???
def similarity(s1: String, s2: String) : Double = ???
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education