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

相关文章

Java学习手册之Filter和Listener使用方法

《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen

Java使用ANTLR4对Lua脚本语法校验详解

《Java使用ANTLR4对Lua脚本语法校验详解》ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,下面就跟随小编一起看看Java如何使用ANTLR4对Lua脚本... 目录什么是ANTLR?第一个例子ANTLR4 的工作流程Lua脚本语法校验准备一个Lua Gramm

springboot filter实现请求响应全链路拦截

《springbootfilter实现请求响应全链路拦截》这篇文章主要为大家详细介绍了SpringBoot如何结合Filter同时拦截请求和响应,从而实现​​日志采集自动化,感兴趣的小伙伴可以跟随小... 目录一、为什么你需要这个过滤器?​​​二、核心实现:一个Filter搞定双向数据流​​​​三、完整代码

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

redis+lua实现分布式限流的示例

《redis+lua实现分布式限流的示例》本文主要介绍了redis+lua实现分布式限流的示例,可以实现复杂的限流逻辑,如滑动窗口限流,并且避免了多步操作导致的并发问题,具有一定的参考价值,感兴趣的可... 目录为什么使用Redis+Lua实现分布式限流使用ZSET也可以实现限流,为什么选择lua的方式实现

C语言字符函数和字符串函数示例详解

《C语言字符函数和字符串函数示例详解》本文详细介绍了C语言中字符分类函数、字符转换函数及字符串操作函数的使用方法,并通过示例代码展示了如何实现这些功能,通过这些内容,读者可以深入理解并掌握C语言中的字... 目录一、字符分类函数二、字符转换函数三、strlen的使用和模拟实现3.1strlen函数3.2st

Spring Boot拦截器Interceptor与过滤器Filter详细教程(示例详解)

《SpringBoot拦截器Interceptor与过滤器Filter详细教程(示例详解)》本文详细介绍了SpringBoot中的拦截器(Interceptor)和过滤器(Filter),包括它们的... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)详细教程1. 概述1

dubbo3 filter(过滤器)如何自定义过滤器

《dubbo3filter(过滤器)如何自定义过滤器》dubbo3filter(过滤器)类似于javaweb中的filter和springmvc中的intercaptor,用于在请求发送前或到达前进... 目录dubbo3 filter(过滤器)简介dubbo 过滤器运行时机自定义 filter第一种 @A

C# string转unicode字符的实现

《C#string转unicode字符的实现》本文主要介绍了C#string转unicode字符的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随... 目录1. 获取字符串中每个字符的 Unicode 值示例代码:输出:2. 将 Unicode 值格式化

Java 8 Stream filter流式过滤器详解

《Java8Streamfilter流式过滤器详解》本文介绍了Java8的StreamAPI中的filter方法,展示了如何使用lambda表达式根据条件过滤流式数据,通过实际代码示例,展示了f... 目录引言 一.Java 8 Stream 的过滤器(filter)二.Java 8 的 filter、fi