April 2019
Beginner to intermediate
386 pages
11h 20m
English
An instance of the CosineSimilarity class was created, followed by the declaration of two sample strings. Next, a lambda expression was used to create the Map instance that represents the string vectors. The sample strings were split into individual characters. These characters were summed and added to the Map instance using the character as the key. These map instances represent the two sentences as numeric vectors:
Map<CharSequence, Integer> vectorA = Arrays .stream(firstSample.split("")) .collect(Collectors.toMap( character -> character, character -> 1, Integer::sum));Map<CharSequence, Integer> vectorB = Arrays .stream(secondSample.split("")) .collect(Collectors.toMap( character -> character, character -> 1, Integer::sum)); ...Read now
Unlock full access