rime中州韵小狼毫 inputShow lua Filter 输入字符透传滤镜

2024-01-04 01:28

本文主要是介绍rime中州韵小狼毫 inputShow lua Filter 输入字符透传滤镜,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在 rime中州韵小狼毫 inputShow lua Translator 一文中,我们通过 inputShow.lua 定制了 inputShow_translator,这使得我们的输入方案可以将用户输入的字符透传到候选列表中来。如下👇:
20240102151229
👆上图中我们在候选列表中看到了 inputShow_translator 透传过来的字符 Straa,但是这两个透传过来的字符在候选列表中的位置是比较靠后的。

本文中, 我们通过定义一个 inputShow_Filterfilter,用于调整候选词的顺序,以使 inputShow_translator 透传过来的字符处于合理的位置。

Filter

在 rime中州韵 help lua Translator 一文中有提到 TranslatorFilter 的工作顺序。
20240101191010
以上文所示流程,Filer 工作于 Translator 之后,也就是说 Translator 所抛出的候选词列表,是 Filter 工作的输入项。Filter 是很强大的处理器,其功能包括但不限于:

  • 增删选项
  • 调整次序
  • 修饰选项(comment)

inputShow_Filter.lua

我们在 inputShow_Filter.lua 文档中定义我们的 Filter,脚本如下👇:

-- spaceAppending.lua
-- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com>
--[[这个脚本,作为filter来用,需要结合inputShow的在translator阶段的处理信息进行工作
--]]
local function _inputShow(input, env)local cands = {}local candsSelflg=falselocal candsInput = {}local inputInfo = {str='',len=0,flg=false,candsCntLimitForLen={15,25}}local candsCnt = 0for cand in input:iter() doif cand.comment == 'inputShowStr' then--这个选项表明了前端的输入编码信息inputInfo.str = string.sub(cand.text,4)inputInfo.len = string.len(inputInfo.str)elseif cand.comment == 'inputShow' then--这是一个转换后需要展示的选项inputInfo.flg = truelocal thisCand = {}thisCand.start = cand.startthisCand._end = cand._endthisCand.text = cand.textthisCand.comment = cand.commenttable.insert(candsInput,cand)candsCnt = candsCnt + 1else--这是一个没有转换的选项table.insert(cands,cand)if string.find(cand.comment,'☯') then--标记选项中存在自造词candsSelflg = trueendcandsCnt = candsCnt + 1endif inputInfo.flg and 0~=inputInfo.len then--如果已经捕获取了inputShow选项--根据输入的编码的长度,判断候选项数量是否已经够用if nil~=inputInfo.candsCntLimitForLen[inputInfo.len] thenif candsCnt >= inputInfo.candsCntLimitForLen[inputInfo.len] thenbreakendendendendif 0==inputInfo.len theninputInfo.flg = falseendlocal candsHasBeenYield=0--下面开始抛出候选项--第一步,如果存在自造词,则先抛出自造词local candsFor2nd = {}for idx=1,#cands doif inputInfo.flg thenif string.find(cands[idx].comment,'☯') thenyield(cands[idx])candsHasBeenYield = candsHasBeenYield + 1elsetable.insert(candsFor2nd,cands[idx])endelse--如果不需要处理 inputShow,则不做处理,进行转存table.insert(candsFor2nd,cands[idx])endend--第二步,把编码完全项抛出,即没有comment(此处指的是编码提示的comment内容)的选项,以供优先选用local candsFor4th = {}for idx=1,#candsFor2nd doif inputInfo.flg thenif candsFor2nd[idx].comment == '' thenyield(candsFor2nd[idx])candsHasBeenYield = candsHasBeenYield + 1elsetable.insert(candsFor4th,candsFor2nd[idx])endelse--如果不需要处理 inputShow,则不做处理,进行转存table.insert(candsFor4th,candsFor2nd[idx])endend--第三步,如果有的话,抛出inputShow的选项for idx=1,#candsInput dolocal thisC = candsInput[idx]--此处的comment是 inputShow,为了不为后续造成干扰,此处需要清除comment内容thisC:get_genuine().comment = ''yield(thisC)candsHasBeenYield = candsHasBeenYield + 1end--第四步,如果还有其它选项,则抛出其它选项for idx=1,#candsFor4th doif nil==inputInfo.candsCntLimitForLen[inputInfo.len] thenyield(candsFor4th[idx])elseif candsHasBeenYield<inputInfo.candsCntLimitForLen[inputInfo.len] thenyield(candsFor4th[idx])elsebreakendcandsHasBeenYield = candsHasBeenYield + 1end
endlocal function inputShow(input, env)--获取debug选项开关状态--local debugSwitchSts = env.engine.context:get_option("debug")_inputShow(input,env)
endreturn inputShow

👆以上的脚本中,我们首先依次读取候选项,根据既定的规则对所读取的候选项进行取舍处理。然后再根据既定的规则次序抛出候选项,从而达到对候选项的 增删调整修饰

inputShow_Filter 文档应该位于 用户文件夹lua 内,如下👇:
20240102155438

rime.lua

在 rime中州韵 help lua Translator 一文中,我们完成 translator 方法的定义后,我们需要在 rime.lua 内把 translator 方法转换为 Translator 接口,以便 rime中州韵小狼毫输入法引擎可以引用 Translator 接口。

同样的,我们在 inputShow_Filter.lua 中完成 Filter 方法的定义后,也需要在 rime.lua 内进行 Filter 方法向 Filter 接口的转换/映射。👇如下,我们在 rime.lua 中进行如下配置:

help_translator = require("help")
inputShow_translator = require("inputShow")
inputShow_Filter = require("inputShow_Filter")

👆以上的配置中,我们把 inputShow_Filter 映射成了 inputShow_Filter

wubi_pinyin.custom.yaml

类比对 translator 的引用,我们同样需要在输入方案中配置引用 Filter,此处以 五笔・拼音 输入方案为例,我们在 wubi_pinyin.custom.yaml 做👇如下的配置:

# encoding:utf-8
patch:engine/translators/+:                         #增加以下translator- lua_translator@inputShow_translator- table_translator@custom_phrase            # 指定使用 custom_phrase 进行输入字符的翻译- lua_translator@help_translatorengine/filters:								# 设置以下filter- simplifier- lua_filter@inputShow_Filter				# 这个过滤器用于在特定场景下,增加候选项- uniquifier								# 过滤重复候选项,依赖 simplifiercustom_phrase:  # 设置用户字/词典dictionary: ""user_dict: Custom_phrase  # 指向 Custom_phrase.txt 文档db_class: stabledbenable_completion: falseenable_sentence: trueinitial_quality: 1punctuator:  # 设置标点符号集import_preset: symbols# 设置以下 translator 相关的开关translator/enable_sentence: true          #是否整句连打translator/enable_user_dict: true         #开启用户词典translator/enable_encoder: true           #是否自动造词translator/encode_commit_history: false 	#对已上屏的内容整合成词条,看需求translator/max_phrase_length: 4          	#自动造词的最长字数translator/enable_completion: true  		#编码逐渐提示开关;编码提示

👆以上配置中,请注意观察 engine/filters 节点下的内容,我们在这个节点内增加了 inputShow_Filter

效果欣赏

当我们完成以上配置后,重新部署 rime中州韵小狼毫,则我们即可以观察到我们所配置的 inputShow_Filter 的效果,如下👇:
20240102174527
👆上图中,我们可以观察到,透传的字符 abip 都排到了较前的位置,同时这些字符中的 comment 内容(例如 inputShow, inputShowStr)被移除。这些处理结果,为下一步更丰富强大功能提供了基础。

inputShow_Filter.lua/rime.lua/wubi_pinyin.custom.yaml 文档

👆以上所述 inputShow_Filter.luarime.luawubi_pinyin.custom.yaml 文档,你也可以在 inputShow.zip 下载取胜。

小结

以上就是今天分享的在 rime 中州韵小狼毫输入中配置 inputShow_Filter 的方法。并以此为样例演示了如何定义一个基础的 Filter,并在 rime.lua 中完成接口映射,然后在输入方案文档 wubi_pinyin.custom.yaml 中引用该 inputShow_Filter,从而实现对候选词的调序和修饰。

这篇关于rime中州韵小狼毫 inputShow lua Filter 输入字符透传滤镜的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/567730

相关文章

我与Bloom filter

1 海量网页判断用Bloom Filter 面试的时候,一个面试官问我说:“有一个网络爬虫,爬虫程序会不停地爬取页面上的每一个网页,并把爬取后的网页给存储起来,那么爬虫如何判定现在在爬的网页有没有被爬过。” 我当时卡住了半天回答不上来。 面试官给我说用Bloom Filter。 Bloom Filter把爬取过的网页映射到Bloom Filter内,如果再爬取到该网页,Bloom Filt

剑指offer(C++)--第一个只出现一次的字符

题目 在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写). class Solution {public:int FirstNotRepeatingChar(string str) {map<char, int> mp;for(int i = 0; i < str.size(); ++i)m

Redis-在springboot环境下执行lua脚本

文章目录 1、什么lua2、创建SpringBoot工程3、引入相关依赖4、创建LUA脚本5、创建配置类6、创建启动类7、创建测试类 1、什么lua “Lua”的英文全称是“Lightweight Userdata Abstraction Layer”,意思是“轻量级用户数据抽象层”。 2、创建SpringBoot工程 3、引入相关依赖 <?xml version

【Python如何输入升高和体重判断你是偏胖还是偏瘦】

1、求体质指数得Python代码如下: # BMI(Body Mass Index)指数:简称体质指数,# 是国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。# 常用指标:BMI<18.5 偏瘦 18.5<=MBI<=24 正常 MBI>24 偏胖# 计算公式:BMI=体重kg/身高的平方ma = eval(input("请输入你的体重(kg):")) # 输入体重b = e

网页脚本输入这么简单

如何在网页中进行脚本操作呢? 研究了一下,很简单,用google浏览器的Console直接操作javaScript。思路: Created with Raphaël 2.1.0 开始 输入(如何输入) 点击(如何点击) 结束 下面是,通过脚本刷直播屏的实现,直接在Console输入即可 var words=new Arra

linux匹配Nginx日志,某个字符开头和结尾的字符串

匹配 os=1 开头, &ip结尾的字符串 cat 2018-06-07.log | egrep -o ‘os=1.*.&ip’ 存入日志。然后使用submit 前面和后面的值去掉,剩下就是需要的字符串。 cat 2018-06-07.log | egrep -o ‘os=1.*.&ip’ >log.log

国产数据库 - 内核特性 - CloudberryDB中的Runtime Filter

国产数据库 - 内核特性 - CloudberryDB中的Runtime Filter 今年5月份GreenPlum官方将GitHub仓库代码全部删除,各个分支的issues和bugs讨论等信息全部清除,仅将master分支代码进行归档。对于国内应用GPDB的用户来说,这是一个挑战性事件,对与后期维护、升级等都变得非常困难。有幸HashData开源了基于GP衍生版本CloudberryDB版本,

输入url发生了什么

1.浏览器查询缓存,如果有缓存,则直接跳到第9步 2.浏览器询问操作系统服务器ip 3.操作系统做dns查询,返回ip地址给浏览器 4.浏览器打开对服务器的tcp连接(如果是https的话则更复杂) 5.浏览器通过tcp发送http请求 6.浏览器接收响应并且可能关掉Tcp连接,或者是重新使用连接处理新请求 7.浏览器检查响应是否为一个重定向(3xx结果状态码),或者是重新

C语言中的字符输入/输出和验证输入

在C语言中,字符输入/输出功能允许程序与用户进行交互,读取用户的输入信息并展示输出结果。同时,验证输入的作用在于确保用户输入的数据符合预期,以提高程序的稳定性和可靠性,防止无效输入引发的错误或异常行为,从而提供更好的用户体验。 基础概念 输入(Input):指的是向程序填充数据的过程,通常来源于用户输入、文件读取或其他外部数据源。 输出(Output):指的是将数据显示在屏幕上、打印机上或

Python高阶函数map、reduce、filter应用

定义 map映射函数 map()通过接收一个函数F和一个可迭代序列,作用是F依次作用序列的每个元素,并返回一个新的list。reduce递归映射函数 reduce()把一个函数作用在一个序列上,这个函数必须接收两个参数,reduce把结果继续和序列的下一个元素做函数运算。filter过滤函数 filter()与map()类似,接收一个函数F和一个可迭代序列,只不过这里的函数F是条件判断函数。