cilin

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

同义词词林扩展版

Go Reference Go goreleaser GitHub go.mod Go version of a Go module GoReportCard GitHub license GitHub release

Word similarity computation based on Tongyici Cilin. 这是一个基于哈工大同义词词林扩展版的单词相似度计算方法的golang实现,参考论文如下: 2010 田久乐等,吉林大学学报(信息科学版),基于同义词词林的词语相似度计算方法。

Install

go get -u github.com/bububa/cilin

Usage

import "github.com/bububa/cilin"

cs := cilin.NewSimilarity()
w1 := "抄袭"
w2 := "克隆"
sim := cs.Calculate(w1, w2)
fmt.Printf("%s %s 相似度为 %f\n", w1, w2, sim)
// 抄袭 克隆 相似度为 0.585642777645155

w1 = "人民"
lst := []string{"国民", "群众", "党群", "良民", "同志", "成年人", "市民", "亲属", "志愿者", "先锋"}
for _, w2 := range lst {
    sim := s.Calculate(w1, w2)
    fmt.Printf("%s %s, 相似度:%f\n", w1, w2, sim)
}

// 人民 国民, 相似度:1.000000
// 人民 群众, 相似度:0.957661
// 人民 党群, 相似度:0.897808
// 人民 良民, 相似度:0.718246
// 人民 同志, 相似度:0.663015
// 人民 成年人, 相似度:0.630692
// 人民 市民, 相似度:0.540593
// 人民 亲属, 相似度:0.360396
// 人民 志愿者, 相似度:0.225247
// 人民 先锋, 相似度:0.180198

同类项目

致谢

本代码的实现要感谢下面几位作者:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultLayerTable = map[int]int{
		1: 1,
		2: 2,
		4: 3,
		5: 4,
		7: 5,
	}
	DEGREE float64 = 180
)

Functions

This section is empty.

Types

type Layer

type Layer [6]string

Layer 编码按层次结构化

func NewLayer

func NewLayer(c string) Layer

NewLayer 将编码按层次结构化 Aa01A01= 第三层和第五层是两个数字表示; 第一、二、四层分别是一个字母; 最后一个字符用来区分所有字符相同的情况。

type Param

type Param struct {
	// contains filtered or unexported fields
}

Param 为Similarity相似性计算参数

func NewDefaultParam

func NewDefaultParam() *Param

NewDefaultParam 默认计算参数

type Similarity

type Similarity struct {
	// contains filtered or unexported fields
}

Similarity 结构体

func NewSimilarity

func NewSimilarity() *Similarity

NewSimilarity 新建Simility

func (*Similarity) Calculate

func (s *Similarity) Calculate(w1 string, w2 string) float64

Calculate 计算相似度 根据以下论文提出的改进方法计算: 《基于知网与词林的词语语义相似度计算》,朱新华,马润聪, 孙柳,陈宏朝( 广西师范大学 计算机科学与信息工程学院,广西 桂林541004)

func (*Similarity) GetCodes

func (s *Similarity) GetCodes(w string) []string

GetCode 获取字符串编码

func (*Similarity) Load

func (s *Similarity) Load(filename string) error

Load 读入同义词词林,编码为key,词群为value,保存在codeWord 单词为key,编码为value,保存在wordCode

func (*Similarity) ParseCilin

func (s *Similarity) ParseCilin()

Jump to

Keyboard shortcuts

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