Compare commits
10 Commits
e4d66e501d
...
4a1e2b9c5e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a1e2b9c5e | ||
|
|
14e54f2393 | ||
|
|
2d1c6f161a | ||
|
|
64a2507631 | ||
|
|
de47a7fab3 | ||
|
|
3dcd171227 | ||
|
|
1de46569e8 | ||
|
|
57c153a6c3 | ||
|
|
55ad14e790 | ||
|
|
2b1e514431 |
@@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
.DEFAULT: all
|
.DEFAULT: all
|
||||||
.PHONY: all clean
|
.PHONY: all clean test
|
||||||
|
|
||||||
#
|
#
|
||||||
DIST?= dist/
|
DIST?= dist/
|
||||||
@@ -18,3 +18,6 @@ dist/ir-tfidf:: cmd/ir-tfidf/* internal/**
|
|||||||
|
|
||||||
clean::
|
clean::
|
||||||
rm -rf "${DIST}"
|
rm -rf "${DIST}"
|
||||||
|
|
||||||
|
test::
|
||||||
|
go test ./...
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
fmt.Printf("You need to specify a keyword to search.\n")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
articles := artifact.Read("data/articles.json")
|
articles := artifact.Read("data/articles.json")
|
||||||
|
|
||||||
tokens := make(map[string][]string)
|
tokens := make(map[string][]string)
|
||||||
@@ -49,7 +54,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if score > 0 {
|
if score > 0 {
|
||||||
fmt.Printf("Article %v: %v\n", article.Id, score)
|
fmt.Printf("Article %v (https://blog.gslin.org/?p=%v): %v\n", article.Id, article.Id, score)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37897
data/articles.json
37897
data/articles.json
File diff suppressed because one or more lines are too long
@@ -7,6 +7,21 @@ import (
|
|||||||
"github.com/gslin/go-ir-playground/internal/ngram"
|
"github.com/gslin/go-ir-playground/internal/ngram"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestBigram(t *testing.T) {
|
||||||
|
a := ngram.Bigram("test")
|
||||||
|
assert.Equal(t, len(a), 0)
|
||||||
|
|
||||||
|
a = ngram.Bigram("測試")
|
||||||
|
assert.Equal(t, len(a), 1)
|
||||||
|
assert.Equal(t, a[0], "測試")
|
||||||
|
|
||||||
|
a = ngram.Bigram("中文測試")
|
||||||
|
assert.Equal(t, len(a), 3)
|
||||||
|
assert.Equal(t, a[0], "中文")
|
||||||
|
assert.Equal(t, a[1], "文測")
|
||||||
|
assert.Equal(t, a[2], "測試")
|
||||||
|
}
|
||||||
|
|
||||||
func TestUnigram(t *testing.T) {
|
func TestUnigram(t *testing.T) {
|
||||||
a := ngram.Unigram("test")
|
a := ngram.Unigram("test")
|
||||||
assert.Equal(t, len(a), 1)
|
assert.Equal(t, len(a), 1)
|
||||||
|
|||||||
14
internal/tokenizer/tokenizer_test.go
Normal file
14
internal/tokenizer/tokenizer_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package tokenizer_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/gslin/go-ir-playground/internal/tokenizer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTokenize(t *testing.T) {
|
||||||
|
a := tokenizer.Tokenize("test")
|
||||||
|
assert.Equal(t, len(a), 1)
|
||||||
|
assert.Equal(t, a[0], "test")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user