smq

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KEY_POS = data.GetKeyPos()
	PUNCTS  = data.GetPuncts()
	COMB    = data.GetComb()
)

Functions

func AddTo

func AddTo(sli *[]int, pos int)

func GetFileName

func GetFileName(fp string) string

func OutputDetail

func OutputDetail(textName string, res *Result)

func ResToJson

func ResToJson(res []*Result) ([]byte, error)

输出 json

func TestDuoduo

func TestDuoduo(t *testing.T)

func TestJidian

func TestJidian(t *testing.T)

func TestJisu

func TestJisu(t *testing.T)

func Tranformer

func Tranformer(f io.Reader) io.Reader

将 io流 转换为 utf-8

Types

type CaR

type CaR struct {
	Count int
	Rate  float64
}

count and rate

type CoC

type CoC struct {
	Code  string
	Order int
	Count int
}

type Dict

type Dict struct {
	Name   string // 码表名
	Single bool   // 单字模式

	Format string /* 码表格式
	default: 默认 本程序赛码表 词\t编码选重\t选重
	jisu:js 极速赛码表 词\t编码选重
	duoduo:dd 多多格式码表 词\t编码
	jidian:jd 极点格式 编码\t词1 词2 词3
	bingling:bl 冰凌格式码表 编码\t词
	*/
	Transformer Transformer // 自定义码表格式转换
	SelectKeys  string      // 普通码表自定义选重键(默认为_;')
	PushStart   int         // 普通码表起顶码长(码长大于等于此数,首选不会追加空格)

	// 初始化 Matcher
	Algorithm string // 匹配算法 trie:前缀树 order:顺序匹配(极速跟打器) longest:最长匹配
	Matcher   Matcher

	PressSpaceBy string // 空格按键方式 left|right|both
	OutputDict   bool   // 输出转换后的码表
	OutputDetail bool   // 输出详细数据
	// contains filtered or unexported fields
}

func (*Dict) Load

func (dict *Dict) Load(rd io.Reader)

从 io 流加载码表

func (*Dict) LoadFromPath

func (dict *Dict) LoadFromPath(path string)

从文件加载码表

func (*Dict) LoadFromString

func (dict *Dict) LoadFromString(s string)

从字符串流加载码表

type Matcher

type Matcher interface {
	// 插入一个词条 word code order
	Insert(string, string, int)
	// 读取完码表后的操作
	Handle()
	// 匹配下一个词
	Match([]rune, int) (int, string, int)
}

type Result

type Result struct {
	Name      string
	Basic     basic
	Words     words     // 打词
	Collision collision // 选重
	CodeLen   codeLen   // 码长

	Keys    keys  // 按键统计
	Combs   combs // 按键组合
	Fingers fingers
	Hands   hands

	Data export
	// contains filtered or unexported fields
}

type Smq

type Smq struct {
	Name   string  // 文本名
	Text   []byte  // 文本
	Inputs []*Dict // 码表选项
}

func New

func New(name string, rd io.Reader) Smq

初始化一个赛码器

func NewFromPath

func NewFromPath(name, path string) Smq

func NewFromString

func NewFromString(name, text string) Smq

func (*Smq) Add

func (smq *Smq) Add(dict *Dict)

添加一个码表

func (*Smq) Run

func (smq *Smq) Run() []*Result

开始计算

func (*Smq) ToJson

func (smq *Smq) ToJson() ([]byte, error)

输出 json

type Transformer

type Transformer interface {
	Read(transformer.Dict) []transformer.Entry
}

Jump to

Keyboard shortcuts

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