本文介绍: 本文分享了一中在rime中州韵小狼毫须鼠管输入法中配置pīn yīn输入方案的方法,从而实现了汉语拼音的快速录入,并且根据需要,可以在录入词组后自动加上空格。

教程目录:rime中州韵小狼毫须鼠管安装配置教程 保姆级教程 100+增强功能配置教程

word中,我们可以轻易的给汉字加上拼音,如下👇:
在word中汉字加拼音.gif
但是,如何单独的输入拼音呢?例如输入 pīn yīn, 再如 zhōng guō。今天我们分享一个使用rime中州韵小狼毫须鼠管输入法配置的输入汉语拼音的输入方案。功能简单,但十分好用。

先睹为快

pīnyīn输入方案可以快捷的输入带有声调的汉语拼音,输出直观,选词快捷,录入体验优良。
20240113013722
20240113013902_rec_

pinyin.schema.yaml

pinyin.schema.yaml 是我们的输入方案的方案文档,我们在 用户文件夹 下创建一个 txt 文档,然后改名为 pinyin.schema.yaml,pinyin.schema.yaml文档内容如下👇:

__build_info:
  rime_version: 1.5.3
  timestamps:
    default: 1626914460
    default.custom: 1651399897
    easy_en.custom: 0
    easy_en.schema: 1491118644
    key_bindings: 1561218646
    key_bindings.custom: 0
    punctuation: 1561218646
    punctuation.custom: 0
switches:
  - name: ascii_mode  # 默认为中文输出模式
    reset: 0
    states: [ 中文, 西文 ]
  - name: full_shape  # 字符默认半角输出
    reset: 0
    states: [ 半角, 全角 ]
  - name: ascii_punct  # 默认使用中文标点
    reset: 0
    states: [ 。,, ., ]
  - name: debug  # 默认debug开关为关闭状态
    reset: 0
    states: [Off, 🐞]
engine:
  processors:
    - ascii_composer
    - key_binder
    - speller
    - recognizer
    - punctuator
    - selector
    - navigator
    - express_editor
  segmentors:
    - matcher
    - ascii_segmentor
    - abc_segmentor
    - punct_segmentor
    - fallback_segmentor
key_binder:
  import_preset: default
recognizer:
  import_preset: default
speller:
  alphabet: "zyxwvutsrqponmlkjihgfedcba"
  delimiter: " "
schema:
  author:
    - "dyy <douyaoyuan@126.com>"
  description: "pīn yīn 输入"
  name: "pīn yīn"
  schema_id: pinyin
  version: 0.0

在上述脚本配置中,我们的schema节点中配置了以下内容:

  • schema_idpinyin;这个schema_id将会在下文的default.custom.yaml中用到
  • namepīn yīn;这个name的值pīn yīn将会出现在方案选单

pinyin.custom.yaml

一如既往,方案名.custom.yaml是对应方案文档的补丁文档,这个pinyin.custom.yaml文档中配置了用户的个性化的配置项目,此处pinyin.custom.yaml文档的配置如下👇:

patch:
  translator/enable_user_dict: false				# false:自动造词及动态词频功能失效;true:启用自动造词和动态词频
  style/inline_preedit: false						# 是否在输入行内进行预测生成,true 表示不单独显示输入字符
  engine/translators:
    - lua_translator@pinyin_translator				# 添加 pinyin_translator lua 翻译器
  engine/filters:									# 设置以下filter
    - simplifier
    - lua_filter@pinyin_Filter						# 这个过滤器用于给拼音候选词组增加一个尾部空格
    - uniquifier									# 过滤重复候选项,依赖 simplifier
  switches/+: #增加以下开关
    - name: space					# 一个标志开头,用来控制是否在拼音选项组词后自动加一个空格
      reset: 0
      states: [,空格]

在以上配置中,我们为pinyin输入方案指定了以下关键配置:

  • 翻译器lua_translator@pinyin_translator:这个pinyin_translator的脚本文档将在下文中介绍。
  • 滤镜lua_filter@pinyin_Filter:这个pinyin_Filter的脚本文档将在下文中介绍
  • 开关space:这个开关的作用是用来控制是否在拼音词组中加入一个空格,以提高输入效率

default.custom.yaml

上文中我们定义了新的输入方案 pinyin,我们需要在 default.custom.yaml 中的方案选单中配置该输入方案,以便我们可以选择使用pinyin输入方案。default.custom.yaml中的配置如下👇:

patch:
  ascii_composer/switch_key:
    Caps_Lock: commit_code  # 候选状态下,按 Caps_Lock 后编码上屏
    Control_L: noop  # 左 ctrl 键无使用效果
    Control_R: noop  # 右 ctrl 键无使用效果
    Eisu_toggle: clear  # 按 Esc 键,清除候选编码,退出候选框
    Shift_L: commit_code  # 候选状态下,按 左 Shift 后,编码上屏
    Shift_R: commit_code  # 候选状态下,按 右 Shift 后,编码上屏
  ascii_composer:
    good_old_caps_lock: true  # true 通过 caps lock 键切换入英文模式后,保持大写输入状态
  engine/filters:
    - simplifier  # 引入简体拼音输入法过滤器
    - uniquifier  # 过滤重复候选项,依赖 simplifier
  key_binder/bindings:
    - {accept: semicolon, send: 2, when: has_menu}  # 使用 ; 键选择第 2 候选词
    - {accept: apostrophe, send: 3, when: has_menu}  # 使用 . 键选择第 3 候选词
    - {accept: bracketleft, send: Page_Up, when: paging}  # 使用 PageUp 键向上翻页
    - {accept: bracketright, send: Page_Down, when: has_menu}  # 使用 PageDown 键向下翻页
  menu/page_size: 10  # 存在候选词选项时,每一页显示的候选词数量,最大是 10
  recognizer/patterns/punct: "^/([0-9]0?|[A-Za-z]+)$"  # 标点符号识别模式
  schema_list:
    - {schema: wubi_pinyin}			# 五笔・拼音 输入方案
    - {schema: easy_en}				# 英文输入方案
    - {schema: pinyin}				# 拼音输入
  switcher:
    abbreviate_options: true  # 功能选项显示为简写模式
    caption: "〔方案选单〕"  # 选项菜单的名字
    fold_options: true  # 功能选项折叠显示
    hotkeys: [F8]  # 使用 F8 键调出 方案选单

👆以上配置中,请注音观察schema_list节点下最后一个schema的内容。

rime.lua

pinyin 输入方案中我们使用到了lua_translatorlua_filter,我们在rime.lua中增加一个translator翻译器和一个filter滤镜,rime.lua中的配置如下👇:

help_translator = require("help")
inputShow_translator = require("inputShow")
inputShow_Filter = require("inputShow_Filter")
Upper_Filter = require("Upper_Filter")
dic_4w_Filter = require("dic_4w_Filter")
phraseReplace_Filter = require("phraseReplace_Filter")
pinyinAdding_Filter = require("pinyinAdding_Filter")
dateTime_Filter = require("dateTime_filter")
dynamicPhrase_Filter = require("dynamicPhrase_Filter")
phraseExt_Filter = require("phraseExt_Filter")
phraseComment_Filter = require("phraseComment_Filter")
pinyin_translator = require("pinyin_translator")
pinyin_Filter = require("pinyin_Filter")

👆以上lua脚本中,注意观察最后两行内容。

💣注意:
以上所述default.custom.yamlpinyin.custom.yamlpinyin.schema.yamlrime.lua 四个文档,应该位于 用户文件夹 下,如下👇:
Snipaste_2024-01-13_00-02-55

pinyin_translator.lua

pinyin_translator.lua 是一个lua脚本,脚本实现了rime引擎的lua_translator翻译器接口;pinyin_translator.lua脚本实现了用户输入编码向拼音词组翻译的功能。pinyin_translator.lua脚本内容如下👇:

--lua语言中的注释用“--”
--[[
pinyin_translator.lua
-- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com>
这是一个lua translator 翻译器,负责将用户输入的拼音生成带有声调的拼音,例如 pīn yīn
]]

local logEnable, log = pcall(require, "runLog")
if logEnable then
	log.writeLog('')
	log.writeLog('log from pinyin_translator.lua')
end

local a = {'ā','á','ǎ','à','a'}
local o = {'ō','ó','ǒ','ò','o'}
local e = {'ē','é','ě','è','e'}
local i = {'ī','í','ǐ','ì','i'}
local u = {'ū','ú','ǔ','ù','u'}
local v = {'ǖ','ǘ','ǚ','ǜ','ü'}
local jv = {'jū','jú','jǔ','jù','ju'}
local qv = {'qū','qú','qǔ','qù','qu'}
local xv = {'xū','xú','xǔ','xù','xu'}
local iu = {'iū','iú','iǔ','iù','iu'}
local ui = {'uī','uí','uǐ','uì','ui'}

local aoeListDict = {['a']=a,
					['o']=o,
					['e']=e,
					['i']=i,
					['u']=u,
					['v']=v,
					['jv']=jv,
					['qv']=qv,
					['xv']=xv,
					['iu']=iu,
					['ui']=ui}

local aoeList = {'a','o','e','ui','iu','i','u','jv','qv','xv','v'}

function translator(input, seg)
	-- 遍历检查韵母, 找到对应的 aoeKey 值
	local aoeKey = ''
	for j,aoeK in ipairs(aoeList) do
		if nil ~= string.match(input,'.*'..aoeK..'.*') then
			aoeKey = aoeK
			break
		end
	end
	
	local inputStr = input
	-- 如果没有 aoeKey,则在input后面加入一个 a,以提供有效的拼音选项
	if '' == aoeKey then
		aoeKey = 'a'
		inputStr = input ..'a'
	end
	
	--这个 aoeK 存在于 input 中,则将 input 中第一个 aoeK 替换成对应的注音字符,然后抛出作为选项
	local aoeL = aoeListDict[aoeKey]
	for j,aoe in ipairs(aoeL) do
		yield(Candidate("pinyin", seg.start, seg._end,string.gsub(inputStr,aoeKey,aoe,1),''))
		if 4 == j and false then
		-- 如果这是第四个选项(四声),则填充5个None选项,目的是为了使轻声出现在序号为 0 的位置, 如果你希望这样,请将判定中的 false 改为true
			for kk=5,9 do
				yield(Candidate("pinyin", seg.start, seg._end,'None'..tostring(kk),''))
			end
		end
		
		if 4 == j and true then
		--是否输出轻声选项,如果不想输出轻声选项(如果拼音中不包含 v,轻声可以通过 Enter 键直接将字母上屏即可),请保持判断条件为true
			if string.find(inputStr,'v') < 1 then
			--如果确实没有 v 的存在,则可以跳过轻声选项
				break
			end
		end
	end
end

return translator

pinyin_Filter.lua

pinyin_Filter.lua是一个lua脚本定义的lua_filter滤镜。pinyin_Filter.lua所定义的滤镜的功能是根据space开关的状态,决策是否向候选词组中加入空格。pinyin_Filter.lua脚本的内容如下👇:

-- pinyin_Filter.lua
-- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com>
--[[
这个过滤器的主要作用是,在拼音候选词组的尾部,增加一个空格
]]

local logEnable, log = pcall(require, "runLog")
if logEnable then
	log.writeLog('')
	log.writeLog('log from pinyin_Filter.lua')
end

local function pinyin_Filter(input, env)
	--获取选项space(空格)开关状态
	local spaceSwitchFlg = env.engine.context:get_option("space") or false
	
	for cand in input:iter() do
		if spaceSwitchFlg then
			yield(Candidate("word", cand.start, cand._end, cand.text..' ', cand.comment))
		else
			yield(cand)
		end
	end
end

return pinyin_Filter

💣注意:
👆上述pinyin_translator.luapinyin_Filter.lua两个脚本文档,均应该位于 用户文件夹下的lua文件夹内,如下👇:
20240113012751

配置文档

👆以上所述配置文档,你可以在 rime中州韵小狼毫须鼠管输入法 汉语拼音输入方案配置包.zip 下载取用。

如果你可以访问gitHub,你也可以在 dyyRime 中找到完全版本的配置包。

效果欣赏

当你完成了以上的所有设置时,你需要重新部署你的rime,然后通过F4/F8调出方案选单,你应该可以看到pīnyīn输入方案,如下👇:
20240113013129
选择pīnyīn输入方案后,就可以愉快的开始体验拼音输入了。

如果希望输入的拼音后面自动加上一个空格,可以将space开关打开,如下👇:
20240113014327

小结

本文分享了一中在rime中州韵小狼毫须鼠管输入法中配置pīn yīn输入方案的方法,从而实现了汉语拼音的快速录入,并且根据需要,可以在录入词组后自动加上空格。

原文地址:https://blog.csdn.net/weixin_42148809/article/details/135565378

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_57479.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注