April 2017
Intermediate to advanced
532 pages
12h 39m
English
The final step is to create a function that converts a set of terms into a sparse vector representation. To do this, we will create an empty sparse matrix with one row and a number of columns equal to the total number of terms in our dictionary. We will then step through each term in the input list of terms and check whether this term is in our term dictionary. If it is, we assign a value of 1 to the vector at the index that corresponds to the term in our dictionary mapping:
extracted terms:
Scala
def create_vector(title_terms:Array[String], all_terms_dic:ListBuffer[String]): CSCMatrix[Int] = { var idx = 0 val x = CSCMatrix.zeros[Int](1, all_terms_dic.length) title_terms.foreach(i => { if (all_terms_dic.contains(i)) ...Read now
Unlock full access