-
Notifications
You must be signed in to change notification settings - Fork 25
/
simhash_test.go
59 lines (48 loc) · 3.43 KB
/
simhash_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2015 Benjamin BALET. All rights reserved.
// Use of this source code is governed by the BSD license
// license that can be found in the LICENSE file.
package stopwords
import (
"testing"
)
//French language
func TestSimhashFrench(t *testing.T) {
res1 := Simhash([]byte("la fin d'un bel après-midi d'été"), "fr", false)
res2 := Simhash([]byte("cet été, nous avons eu un bel après-midi"), "fr", false)
res3 := Simhash([]byte("l'hiver, la chaleur n'était pas là à midi"), "fr", false)
if CompareSimhash(res2, res3) < CompareSimhash(res2, res1) {
t.Errorf("Comparison failed")
}
//Hamming distance should be the same
if CompareSimhash(res1, res2) != CompareSimhash(res2, res1) {
t.Errorf("Hamming distance should be the same between 1/2 and 2/1")
}
}
//English language
func TestSimhashEnglish(t *testing.T) {
res1 := Simhash([]byte("the war is coming, send more troop. This soldier was courageous."), "en", false)
res2 := Simhash([]byte("the troop was composed of veteran soldiers of the last war."), "en", false)
res3 := Simhash([]byte("the is an article of the english language it was created long before the last reform."), "en", false)
if CompareSimhash(res2, res3) < CompareSimhash(res2, res1) {
t.Errorf("Comparison failed")
}
//Hamming distance should be the same
if CompareSimhash(res1, res2) != CompareSimhash(res2, res1) {
t.Errorf("Hamming distance should be the same between 1/2 and 2/1")
}
}
//Khmer language
func TestSimhashKhmer(t *testing.T) {
//Articles about election
res1 := Simhash([]byte("គណៈកម្មាធិការជាតិរៀបចំការបោះឆ្នោត(គ.ជ.ប) ប្រកាសទទួលពាក្យស្នើសុំសង្កេតការណ៍បោះឆ្នោតពីអ្នកសង្កេតការណ៍ជាតិ អន្តរជាតិ និងគណបក្សនយោបាយ ខណៈការបោះឆ្នោតក្រុមប្រឹក្សាឃុំសង្កាត់អាណត្តិទី ៤ កាន់តែជិតមកដល់។"), "km", false)
res2 := Simhash([]byte("អ្នកដាក់ពាក្យស្នើសុំសង្កេតការណ៍ជាតិ និងអន្តរជាតិអាចយកពាក្យស្នើសុំនៅការិយាល័យ គ.ជ.ប ឬទាញយកពាក្យតាមគេហទំព័ររបស់គ.ជ.ប និងដាក់ពាក្យវិញនៅការិយាល័យគ.ជ.បដដែល។"), "km", false)
//Description of Cambodia
res3 := Simhash([]byte("កម្ពុជាឬឈ្មោះផ្លូវការព្រះរាជាណាចក្រកម្ពុជាជាប្រទេសមួយស្ថិតនៅផ្នែកខាងត្បូងនៃទៀបកោះឥណ្ឌូចិននៅអាស៊ីអាគ្នេយ៍។"), "km", false)
if CompareSimhash(res2, res3) < CompareSimhash(res2, res1) {
t.Errorf("Comparison failed")
}
//Hamming distance should be the same
if CompareSimhash(res1, res2) != CompareSimhash(res2, res1) {
t.Errorf("Hamming distance should be the same between 1/2 and 2/1")
}
}