cosine_similarity

package module
v0.0.0-...-776b36a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2019 License: MIT Imports: 6 Imported by: 0

README

Project

a test similarity implenmentation by cosine similarity

About text similarity

https://cloud.tencent.com/developer/article/1389446

How to test

$ go test -v -test.run TestCosineSimilar

=== RUN TestCosineSimilar

srcWords: [为什么 我 的 眼里 常含 泪水 , 因为 我 对 这片 土地 爱得 深沉]

dstWords: [我 深沉 的 爱 着 这片 土地 , 所以 我 的 眼里 常含 泪水]

allWordsMap:map[为什么:1 因为:1 土地:2 对:1 常含:2 我:4 所以:1 泪水:2 深沉:2 爱:1 爱得:1 的:3 眼里:2 着:1 这片:2 ,:2]

allWordsSlice:[因为 这片 爱得 所以 的 , 眼里 泪水 对 深沉 爱 我 常含 着 为什么 土地]

srcVector:[1 1 1 0 1 1 1 1 1 1 0 2 1 0 1 1]

dstVector:[0 1 0 1 2 1 1 1 0 1 1 2 1 1 0 1]

--- PASS: TestCosineSimilar (0.62s)

similarity_test.go:20: CosineSimilar score: 0.7660323462854266

PASS

Process finished with exit code 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilar

func CosineSimilar(srcWords, dstWords []string) float64

func RemoveHtml

func RemoveHtml(src string) string

Types

type GoJieba

type GoJieba struct {
	C *gojieba.Jieba
}
var GJB *GoJieba

func NewGoJieba

func NewGoJieba() *GoJieba

func (*GoJieba) AddWords

func (this *GoJieba) AddWords(words []string)

func (*GoJieba) Close

func (this *GoJieba) Close()

func (*GoJieba) JiebaCut

func (this *GoJieba) JiebaCut(rawStr string, useHmm bool, cutAll bool) (words []string)

func (*GoJieba) JiebaCutForSearch

func (this *GoJieba) JiebaCutForSearch(rawStr string, useHmm bool)

func (*GoJieba) JiebaCutWithFrequency

func (this *GoJieba) JiebaCutWithFrequency(rawStr string, useHmm bool, cutAll bool) (wordsFreqs map[string]int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL