Skip to content

Commit c97a4a1

Browse files
committed
Fix issue #43
1 parent 256a4cc commit c97a4a1

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -388,34 +388,32 @@ public class MyApp {
388388
}
389389
```
390390

391-
Or, for large datasets, pre-compute the profile or set representation of all strings. The similarity can then be computed between profiles or sets:
391+
Or, for large datasets, pre-compute the profile of all strings. The similarity can then be computed between profiles:
392392

393393
```java
394394
import info.debatty.java.stringsimilarity.KShingling;
395395
import info.debatty.java.stringsimilarity.StringProfile;
396396

397397

398+
/**
399+
* Example of computing cosine similarity with pre-computed profiles.
400+
*/
398401
public class PrecomputedCosine {
399402

400-
/**
401-
* @param args the command line arguments
402-
*/
403403
public static void main(String[] args) throws Exception {
404404
String s1 = "My first string";
405405
String s2 = "My other string...";
406-
406+
407407
// Let's work with sequences of 2 characters...
408-
KShingling ks = new KShingling(2);
409-
410-
// For cosine similarity I need the profile of strings
411-
StringProfile profile1 = ks.getProfile(s1);
412-
StringProfile profile2 = ks.getProfile(s2);
413-
408+
Cosine cosine = new Cosine(2);
409+
410+
// Pre-compute the profile of strings
411+
Map<String, Integer> profile1 = cosine.getProfile(s1);
412+
Map<String, Integer> profile2 = cosine.getProfile(s2);
413+
414414
// Prints 0.516185
415-
System.out.println(profile1.cosineSimilarity(profile2));
416-
415+
System.out.println(cosine.similarity(profile1, profile2));
417416
}
418-
419417
}
420418
```
421419

0 commit comments

Comments
 (0)