forked from mfonda/simhash
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexampleB_test.go
35 lines (28 loc) · 1.17 KB
/
exampleB_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//package main
package simhash_test
import (
"fmt"
"github.com/go-dedup/simhash"
)
// for standalone test, change package to `main` and the next func def to,
// func main() {
func ExampleBuildSimhash() {
hashes := make([]uint64, len(docs))
sh := simhash.NewSimhash()
for i, d := range docs {
hashes[i] = sh.BuildSimhash(string(d), simhash.Doc2words)
fmt.Printf("Simhash of '%s': %x\n", d, hashes[i])
}
fmt.Printf("Comparison of `%s` and `%s`: %d\n", docs[0], docs[1], simhash.Compare(hashes[0], hashes[1]))
fmt.Printf("Comparison of `%s` and `%s`: %d\n", docs[0], docs[2], simhash.Compare(hashes[0], hashes[2]))
fmt.Printf("Comparison of `%s` and `%s`: %d\n", docs[0], docs[3], simhash.Compare(hashes[0], hashes[3]))
// Output:
// Simhash of 'this is a test phrase': 8c3a5f7e9ecb3f35
// Simhash of 'this is a test phrass': 8c3a5f7e9ecb3f21
// Simhash of 'these are test phrases': ddfdbf7fbfaffb1d
// Simhash of 'foo bar': d8dbe7186bad3db3
// Comparison of `this is a test phrase` and `this is a test phrass`: 2
// Comparison of `this is a test phrase` and `these are test phrases`: 22
// Comparison of `this is a test phrase` and `foo bar`: 29
}
var exampleB_dummy bool