325 changed files with 1843 additions and 1792 deletions
@ -0,0 +1,57 @@ |
|||||
|
package textcomparison |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"strings" |
||||
|
|
||||
|
"github.com/Chain-Zhang/pinyin" |
||||
|
) |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-09-30 16:00:42 |
||||
|
@ 功能: 中文转拼音 |
||||
|
@ 参数 |
||||
|
|
||||
|
#text 中文 |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
#pinYinStr 拼音 |
||||
|
#err 错误信息 |
||||
|
*/ |
||||
|
func ChinaToPinYinFirstBig(text string) (pinYinStr string, err error) { |
||||
|
pinYinStr, err = pinyin.New(text).Split("").Mode(pinyin.InitialsInCapitals).Convert() |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-09-30 16:08:40 |
||||
|
@ 功能: 获取首字母 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func ChinaToPinYinFirstWord(text string) (pinYinStr string, err error) { |
||||
|
pinYinStrAll, err := pinyin.New(text).Convert() |
||||
|
pinYinAry := strings.Split(pinYinStrAll, " ") |
||||
|
if len(pinYinAry) < 1 { |
||||
|
err = fmt.Errorf("转译错误!") |
||||
|
return |
||||
|
} |
||||
|
for i := 0; i < len(pinYinAry); i++ { |
||||
|
if len(pinYinAry[i]) > 0 { |
||||
|
ziMuStr := pinYinAry[i][0] |
||||
|
firstWord := strings.ToUpper(string(ziMuStr)) |
||||
|
pinYinStr = fmt.Sprintf("%v%v", pinYinStr, firstWord) |
||||
|
} |
||||
|
} |
||||
|
return |
||||
|
} |
||||
@ -1,83 +0,0 @@ |
|||||
package textcomparison |
|
||||
|
|
||||
import ( |
|
||||
"sync" |
|
||||
|
|
||||
"github.com/yanyiwu/gojieba" |
|
||||
) |
|
||||
|
|
||||
type GoJieba struct { |
|
||||
C *gojieba.Jieba |
|
||||
} |
|
||||
|
|
||||
var GJB *GoJieba |
|
||||
var one sync.Once |
|
||||
|
|
||||
func NewGoJieba() *GoJieba { |
|
||||
one.Do(func() { |
|
||||
GJB = &GoJieba{ |
|
||||
C: gojieba.NewJieba(), |
|
||||
//equals with x := NewJieba(DICT_PATH, HMM_PATH, USER_DICT_PATH)
|
|
||||
} |
|
||||
}) |
|
||||
return GJB |
|
||||
} |
|
||||
|
|
||||
func (this *GoJieba) Close() { |
|
||||
this.C.Free() |
|
||||
} |
|
||||
|
|
||||
func (this *GoJieba) AddWords(words []string) { |
|
||||
for _, word := range words { |
|
||||
this.C.AddWord(word) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (this *GoJieba) JiebaCut(rawStr string, useHmm bool, cutAll bool) (words []string) { |
|
||||
if cutAll { |
|
||||
words = jiebaCutAll(this.C, &rawStr) |
|
||||
} else { |
|
||||
words = jiebaCut(this.C, &rawStr, useHmm) |
|
||||
} |
|
||||
|
|
||||
return |
|
||||
} |
|
||||
|
|
||||
func (this *GoJieba) JiebaCutWithFrequency(rawStr string, useHmm bool, cutAll bool) (wordsFreqs map[string]int) { |
|
||||
wordsFreqs = make(map[string]int) |
|
||||
if cutAll { |
|
||||
words := jiebaCutAll(this.C, &rawStr) |
|
||||
for _, word := range words { |
|
||||
freq := wordsFreqs[word] |
|
||||
wordsFreqs[word] = freq + 1 |
|
||||
} |
|
||||
} else { |
|
||||
words := jiebaCut(this.C, &rawStr, useHmm) |
|
||||
for _, word := range words { |
|
||||
freq := wordsFreqs[word] |
|
||||
wordsFreqs[word] = freq + 1 |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return |
|
||||
} |
|
||||
|
|
||||
func (this *GoJieba) JiebaCutForSearch(rawStr string, useHmm bool) { |
|
||||
jiebaCut4Search(this.C, &rawStr, useHmm) |
|
||||
|
|
||||
} |
|
||||
|
|
||||
func jiebaCutAll(x *gojieba.Jieba, rawStr *string) (words []string) { |
|
||||
words = x.CutAll(*rawStr) |
|
||||
return |
|
||||
} |
|
||||
|
|
||||
func jiebaCut(x *gojieba.Jieba, rawStr *string, useHmm bool) (words []string) { |
|
||||
words = x.Cut(*rawStr, useHmm) |
|
||||
return |
|
||||
} |
|
||||
|
|
||||
func jiebaCut4Search(x *gojieba.Jieba, rawStr *string, useHmm bool) (words []string) { |
|
||||
words = x.CutForSearch(*rawStr, useHmm) |
|
||||
return |
|
||||
} |
|
||||
@ -1,7 +1,7 @@ |
|||||
package autocode |
package autocode |
||||
|
|
||||
type ApiGroup struct { |
type ApiGroup struct { |
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
|
// Code generated by gin_server_admin Begin; DO NOT EDIT.
|
||||
AutoCodeExampleApi |
AutoCodeExampleApi |
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
|
// Code generated by gin_server_admin End; DO NOT EDIT.
|
||||
} |
} |
||||
|
|||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue