导图社区 Rime输入法
Rime输入法(也称为RIME输入法或鼠须管、小狼毫等)是一款开源的输入法引擎,旨在为用户提供高度可定制和灵活的输入法解决方案。涵盖了Rime输入法安装、目录结构、文件结构以及相关代码。
编辑于2024-09-16 01:50:00Rime
效果一览
1. 中文(五笔)输入,
2. 英文输入:首字母大写
3. 中英互译:中译英
4. 中英互译:英译中
5. 汉语拼音输入
6. 正常文本中临时输入 latex 基本字符
7. 表情输入
8. 自定义输入框
9. 自定义符号效果
10. 状态机选项,推荐指数,进度条,对错勾叉符号
11. 上标数字/文字,下标数字/文字
12. 罗马数字,大写罗马数字,带点的数字,带括号的数字,苏州码字
13. 带圈数字,中文数字,带圈中文数字,括号中文数字,分数符号
14. 干支编码,星座与符号,节气
15. 希腊字母,汉字注音
16. 按钮图标,汉字部首
17. 日期/时间效果
当前时间, 时辰,钟表符号
日期输入效果,今天,明天,昨天,后天,前天
上下标格式日期
18. 周序 与 星期
本周,下周,上周
周一 至 周日
19. 月份 与 年
本月,上月,下月
今年,去年,明年
20. 农历 与 节气
农历/节气
春分 至 大寒
21. 动态信息显示/生成效果
生成uuid,显示 ip,随机密码
系统信息显示效果
22. 自定义短语效果
emoji输入效果
微信定制emoji输入
钉钉定制emoji输入
unicode emoji符号输入
单位换算效果
常用git命令输入
常用python关键字输入
23. 词条备注效果
化学元素提示
五笔编码提示
车牌提示
24. 敏感词过滤效果
25. 生词注音效果
26. help效果
27. latex输入效果
help效果
彩色文本效果
彩色文本效果1
彩色文本效果2
上标下标输入效果
上标下标输入效果
希腊字母输入效果
希腊字母输入效果
箭头输入效果
箭头输入效果
三角函数, 反三角函数
三角函数, 反三角函数1
三角函数, 反三角函数2
双曲函数,反双曲函数
双曲函数,反双曲函数1
双曲函数,反双曲函数2
分数输入
分数输入
微商输入
微商输入
积分输入
积分输入1
积分输入2
对数输入
对数输入
极限输入效果
极限输入效果
点输入效果
点输入效果
abs 绝对值输入,bar 上划线输入
abs 绝对值输入,bar 上划线输入1
abs 绝对值输入,bar 上划线输入2
开方输入效果
开方输入效果
临域符号输入效果
临域符号输入效果
函数样式
函数样式
其它输入效果
其它输入效果1
其它输入效果2
其它输入效果3
其它输入效果4
程序(安装)
Windows
小狼毫(Weasel)
macOS
鼠须管(Squirrel)
Linux
ibus-rime
Ubuntu
sudo apt-get install ibus-rime
fcitx-rime
Android
小企鹅
同文
在线版
My Rime
输入方案
Ubuntu搜索wubi相关的schema.yaml文档:find / -type f -name wubi* 2>null
现代标准汉语
明月拼音(luna-pinyin)
sudo apt-get install librime-data-luna-pinyin
地球拼音(terra-pinyin)
注音(bopomofo)
sudo apt-get install librime-data-terra-pinyin librime-data-bopomofo
可以一次安装2个或多个输入法
袖珍简化字拼音(pinyin-simp)
sudo apt-get install librime-data-pinyin-simp
拼音的双拼
双拼
sudo apt-get install librime-data-double-pinyin
宫保拼音
sudo apt-get install librime-data-combo-pinyin
打字速记法
汉语方言
粤拼
sudo apt-get install librime-data-jyutping
吴语(上海话、苏州话)
sudo apt-get install librime-data-wugniu
历史音频
中古汉语拼音
sudo apt-get install librime-data-zyenpheng
字形输入法
五笔画(stroke)
sudo apt-get install librime-data-stroke-simp
五笔(wubi)
sudo apt-get install librime-data-wubi
86版
仓颉(cangjie)
sudo apt-get install librime-data-cangjie5
速成(quick)
sudo apt-get install librime-data-quicks
行列输入法(array)
快速仓颉(scj)
符号输入
会文字
国际音标
程序文件夹
安装目录
Ubuntu安装目录:~/.config/ibus/rime
data文件夹
主要存放Rime各项配置及输入方案的原始配置yaml文档
用户文件夹
程序结构
所有的default.yaml的补丁文档是default.custom.yaml
所有的XXX.schema.yaml的补丁文档是XXX.custom.yaml
在补丁文档中,所有定义的配置节点、配置项、配置值/内容,都应该存在补丁节点patch内,反之,不在patch节点内的配置项/内容不会生效。一个custom.yaml文档只需要一个patch节点,多个patch节点会引起Rime异常
yaml语法
缩进表示层级关系
要么使用空格,要么使用制表符,不可混用
内容大小写敏感
# 表示注释
default.custom.yaml
patch:
ascii_composer/switch_key:
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 后,编码上屏
用来定义输入法状态开关相关的按键
Caps_Lock:
commit_code
候选状态下,按下Caps_Lock后,编码上屏
clear
候选状态下,按下Caps_Lock后,编码清除
Control_L:
commit_code
左ctrl有效
noop
左ctrl无效
Control_R:
commit_code
右ctrl有效
noop
右ctrl无效
Eisu_toggle:
commit_code
候选状态下,按下Esc后,编码上屏
clear
候选状态下,按下Esc后,编码清除
Shift_L:
commit_code
左Shift有效
noop
左Shift无效
Shift_R:
commit_code
右Shift有效
noop
右Shift无效
ascii_composer:
good_old_caps_lock:
patch: ascii_composer: good_old_caps_lock: true # true 通过 caps lock 键切换入英文模式后,保持大写输入状态
用来控制在输入的过程中,使用CapsLock键后输入法的行为
true
通过CapsLock键切换英文模式后,保持大写输入状态
false
通过CapsLock键切换英文模式后,不保持大写输入状态
engine/filters:
patch: "engine/filters": - simplifier # 引入简体拼音输入法过滤器 - uniquifier # 过滤重复候选项,依赖 simplifier
用来定义候选词过滤器的配置
- simplifier
引入简体拼音输入法过滤器
- uniquifier
过滤重复候选项,依赖simplifier
key_binder/bindings:
patch: "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 键向下翻页 - { when: has_menu, accept: minus, send: Page_Up } # -翻页 - { when: has_menu, accept: equal, send: Page_Down } # =翻页
用来定义一些按键的相关作用
- {accept: xxx, send: xxx, when: xxx}
menu/page_size:
patch: "menu/page_size": 10 # 存在候选词选项时,每一页显示的候选词数量,最大是 10
用来定义在输入法候选词存在时,候选框内可以容纳的候选词的数量,最大是 10
recognizer/patterns/punct:
patch: "recognizer/patterns/punct": "^/([0-9]0?|[A-Za-z]+)$" # 标点符号识别模式
用来定义标点符号输入的捕捉模式
正则表达式
schema_list
patch: schema_list: - {schema: wubi_pinyin} # 五笔・拼音 输入方案 - {schema: easy_en} # 英文输入方案 - {schema: pinyin} # 拼音输入 - {schema: latex} # latex输入方案
用于管理输入方案列表,这里所谓的输入方案,指的是 程序文件夹 内的 schema.yaml 文档名
使用快捷键F4/F8或Ctrl+`调出输入方案,方案名称为输入方案的name值而不是default.custom.yaml中配置的xxx(输入方案的 schema.yaml 文档名)
- {schema: xxx}
switcher:
patch: switcher: abbreviate_options: true # 功能选项显示为简写模式 caption: "〔方案选单〕" # 选项菜单的名字 fold_options: true # 功能选项折叠显示 hotkeys: [F8] # 使用 F8 键调出 方案选单
用来管理和控制输入方案及输入选项的开关状态
abbreviate_options:
true
功能选项显示未简写模式
false
caption:
"〔方案选单〕"
fold_option:
true
功能选项折叠显示
false
hotkeys:
[F4]
方案选单快捷键
按键名称一览表
weasel.custom.yaml
输入配色
patch:
定制配色方案
preset_color_schemes/+:
patch: preset_color_schemes/+: ink: name: 墨池/Ink author: 佛振 <chen.sst@gmail.com> text_color: 0x000000 back_color: 0xffffff border_color: 0x000000 hilited_text_color: 0x000000 hilited_back_color: 0xdddddd hilited_candidate_text_color: 0xffffff hilited_candidate_back_color: 0x000000
ink:(主题名)

name:
主题名
author:
作者
text_color:
默认文字颜色
back_color:
候选窗背景色
shadow_color:
候选窗阴影色,默认全透明(无阴影)
border_color:
候选窗边框颜色
hilited_back_color:
编码背景颜色
hilited_text_color:
编码文字颜色
hilited_candidate_text_color:
高亮候选文字颜色
hilited_candidate_back_color:
高亮候选背景颜色
hilited_shadow_color:
编码背景块阴影颜色
hilited_candidate_shadow_color:
高亮候选背景块阴影颜色
candidate_text_color:
非高亮候选文字颜色
candidate_back_color:
非高亮候选背景颜色
candidate_shadow_color:
非高亮候选背景块阴影颜色
使用配色方案
style/color_scheme:xxx
patch: "style/color_scheme": ink
输入环境识别
patch:
app_options/xxx.exe:
patch: "app_options/code.exe": # 配置一个 vscodeFlg 的 flg 以表示当前是否是在 vsCode 环境中进行输入 vscodeFlg: true "app_options/conhost.exe": # cmd cmdFlg: true "app_options/dingtalk.exe": # 钉钉 dingdingFlg: true "app_options/feishu.exe": # 飞书 feishuFlg: true "app_options/mintty.exe": # mintty minttyFlg: true "app_options/pycharm64.exe": # pyCharm pycharmFlg: true "app_options/wechat.exe": # 微信 wechatFlg: true
xxx.custom.yaml
patch:
patch: switches/+: #增加以下开关 - name: encnDic # 中英字典开关 reset: 1 states: [Off, 中英对照] speller/alphabet: "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA/" #定义输入字符的识别格式 engine/filters/+: # 下面的滤镜会对候选项进行格式化处理 - lua_filter@Upper_Filter #英文后加空格滤镜 # 上面的滤镜会增加候选词选项 - uniquifier # 上面的滤镜会增加候选词选项 - lua_filter@dic_4w_Filter # 英中对照滤镜 engine/translators/+: #增加以下translator - table_translator@custom_phrase # 指定使用 custom_phrase 进行输入字符的翻译 custom_phrase: # 设置用户字/词典 dictionary: "" user_dict: Custom_phrase # 指向 Custom_phrase.txt 文档 db_class: stabledb enable_completion: false enable_sentence: true initial_quality: 1 punctuator: # 设置标点符号集 import_preset: symbols translator: enable_user_dict: true #开启用户词典 enable_encoder: true #是否自动造词 encode_commit_history: false #对已上屏的内容整合成词条,看需求
custom_phrase:
dictionary:
user_dict:
user_dict:
指向Custom_phrase.txt文档
db_class:
stabledb
enable_completion:
true
false
enable_sentence:
true
false
initial_quality:
engine/translators/+:
- table_translator@custom_phrase
指定使用 custom_phrase 进行输入字符的翻译
- lua_translator@help_translator
引用help_translator接口
- lua_translator@inputShow_translator
- lua_translator@pinyin_translator
添加 pinyin_translator lua 翻译器
punctuator:
import_preset:
symbols
switches/+:
- name: encnDic
- name: encnDic # 中英字典开关
reset: 1
states: [Off, 中英对照]
- name:pinyin
patch: switches/+: #增加以下开关 - name: pinyin # 这个开关用于标记是否打开拼音滤镜 reset: 0 states: [Off, pīnyīn] engine/filters: # 设置以下filter - simplifier # 下面的滤镜是comment滤镜,不会改变候选项列表 - lua_filter@pinyinAdding_Filter # pinyin滤镜,用于对候选项中的字添加拼音
reset: 0
states: [Off, pīnyīn]
- name: phraseExt
reset: 1
states: [Off, phraseExt]
speller/alphabet:
"zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA/"
定义输入字符的识别格式
engine/filters/+:
- lua_filter@Upper_Filter
英文后加空格滤镜
- uniquifier
- lua_filter@dic_4w_Filter
- lua_filter@inputShow_Filter
用于在特定场景下,增加候选项
- lua_filter@phraseReplace_Filter
词语替换滤镜,针对一些指定的关键字
- lua_filter@dic_4w_Filter
英中对照滤镜
- lua_filter@pinyinAdding_Filter
pinyin滤镜,用于对候选项中的字添加拼音
- lua_filter@dateTime_Filter
时间信息,对于特定的时间或者事件关键字,添加时间信息
- lua_filter@dynamicPhrase_Filter
动态候选项,用于动态获取与运行环境有关的信息
- lua_filter@phraseExt_Filter
自定义短语滤镜,针对响应的关键字,添加新的选项进来
translator:
# encoding:utf-8 patch: engine/translators/+: #增加以下translator - lua_translator@inputShow_translator - table_translator@custom_phrase # 指定使用 custom_phrase 进行输入字符的翻译 - lua_translator@help_translator engine/filters: # 设置以下filter - simplifier - lua_filter@inputShow_Filter # 这个过滤器用于在特定场景下,增加候选项 - uniquifier # 过滤重复候选项,依赖 simplifier
enable_user_dict:
true
开启用户词典
false
enable_encoder:
true
开启自动造词
false
max_phrase_length:
4
自动造词的最长字数
encode_commit_history:
true
对已上屏的内容整合成词条
false
enable_sentence:
true
开启整句连打
false
enable_completion:
true
开启编码逐渐提示
false
symbols.custom.yaml
基础扩展符号的配置
patch:
punctuator:
# encoding:utf-8 patch: punctuator: # 设置标点符号集 import_preset: symbols
import_preset:xxx
自定义符号选项
patch:
punctuator/symbols/+:
patch: punctuator/symbols/+: "/zt": ["", "", "", ""]
"/zt": ["", "", "", ""]
Custom_phrase.txt
自定义词典
# Rime table # coding: utf-8 #@/db_name custom_phrase.txt #@/db_type tabledb # # 【小狼毫】0.9.21 以上 # # 请将该文件以 UTF-8 编码保存 # # 码表各字段以制表符(tab)分隔,制表符不可以用四个空格代替,但允许在文字词句中使用空格 # 顺序为:文字、编码、权重(权重决定重码的次序,是可选项,数字越大,排序越靠前) # # 虽然文本码表编辑较为方便,但不适合导入大量条目 @ at #latex 相关词汇 $$ doll $$\textcolor{blue}{A}$$ doll #latex end lua version: Lua 5.4 help 特殊符号-->/help help latexLetters-->uzalph help
词条 编码 权重(数字,可省略,最大排序越靠前)
easyEnglish输入法
easy_en.dict.yaml
--- name: easy_en version: "0.2" sort: by_weight use_preset_vocabulary: false ... a a A A á a Á A à a À A â a  A ä a Ä A
easy_en.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 # 默认为 ASCII 输出模式 states: [ ASCII, Off ] - name: full_shape reset: 0 # 字符默认半角输出 states: [ 半角, 全角 ] - name: ascii_punct # 默认使用英文标点 reset: 1 states: [ 。,, ., ] engine: filters: - uniquifier processors: - ascii_composer - key_binder - speller - recognizer - punctuator - selector - navigator - express_editor segmentors: - matcher - ascii_segmentor - abc_segmentor - punct_segmentor - fallback_segmentor translators: - table_translator - punct_translator key_binder: import_preset: default speller: auto_select: true delimiter: " ;'" auto_select_unique_candidate: true # 无重码自动上屏 punctuator: import_preset: default recognizer: import_preset: default patterns: email: "^[A-Za-z][-_.0-9A-Za-z]*@.*$" uppercase: "[A-Z][-_+.'0-9A-Za-z]*$" url: "^(www[.]|https?:|ftp[.:]|mailto:|file:).*$|^[a-z]+[.].+$" schema: author: - "Patrick <ipatrickmac@gmail.com>" description: "Easy English" name: "Easy English" schema_id: easy_en version: 0.2 speller: alphabet: "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA-_" delimiter: " '" translator: dictionary: easy_en spelling_hints: 9
不是 一个补丁文档,所以这些参数 不在 ,也 不应该在patch节点下
switches:
- name: ascii_mode
reset: 0
默认为ASCII输出模式
states: [ASCII, Off]
- name: full_shape
reset: 0
字符默认半角输出
states: [半角, 全角]
- name: ascii_punct
reset: 1
默认使用中文标点
states: [。, , . ,]
- name: debug
reset: 0
states: [Off, ]
engine:
filters:
- uniquifier
processors:
- ascii_composer
- key_binder
- speller
- recognizer
- punctuator
- selector
- navigator
- express_editor
segmentors:
- matcher
- ascii_segmentor
- abc_segmentor
- punct_segmentor
- fallback_segmentor
translators:
- table_translator
- punct_translator
key_binder:
import_preset:
default
speller:
auto_select:
true
delimiter:
" ;'"
auto_select_unique_candidate:
true
punctuator:
import_preset:
default
recognizer:
import_preset:
default
patterns:
email:
"^[A-Za-z][-_.0-9A-Za-z]*@.*$"
uppercase:
"[A-Z][-_+.'0-9A-Za-z]*$"
url:
"^(www[.]|https?:|ftp[.:]|mailto:|file:).*$|^[a-z]+[.].+$"
schema:
author:
description:
name:
pīn yīn
这个name的值pīn yīn将会出现在方案选单中
schema_id:
pinyin
schema_id会在下文的default.custom.yaml中用到
version:
speller:
alphabet:
"zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA-_"
delimiter:
" '"
translator:
dictionary:
spelling_hints:
两个文档,需要放在同一路径下,而且需要加入default.custom.yaml才能生效
easy_en.custom.yaml
patch: switches/+: #增加以下开关 - name: encnDic # 中英字典开关 reset: 1 states: [Off, 中英对照] speller/alphabet: "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA/" #定义输入字符的识别格式 engine/filters/+: # 下面的滤镜会对候选项进行格式化处理 - lua_filter@Upper_Filter #英文后加空格滤镜 # 上面的滤镜会增加候选词选项 - uniquifier # 上面的滤镜会增加候选词选项 - lua_filter@dic_4w_Filter # 英中对照滤镜 punctuator: import_preset: symbols translator: enable_user_dict: true #开启用户词典 enable_encoder: true #是否自动造词 encode_commit_history: false #对已上屏的内容整合成词条,看需求
patch:
engine/filters/+:
- lua_filter@Upper_Filter
英文后加空格滤镜
- uniquifier
- lua_filter@dic_4w_Filter
英中对照滤镜
switches/+:
- name: encnDic
- name: encnDic # 中英字典开关
reset:
1
states:
[Off, 中英对照]
help lua Translator 帮助消息翻译器
Translator
lua文件夹
help.lua
主体
--lua语言中的注释用“--” function translator(input, seg) --这里定义 translator 逻辑,例如如果看到 input == ddfb, 则给出候选项 大地 end return translator
案例
--lua语言中的注释用“--” function translator(input, seg) if (input == "/help") then yield(Candidate("help", seg.start, seg._end, "带圈汉字/数字/字母-->/hzq/szq/zmq", " ")) yield(Candidate("help", seg.start, seg._end, "符号/记号/箭头/雪花/表情-->/fh/jh/jt/xh/bq", " ")) yield(Candidate("help", seg.start, seg._end, "数学/数字名/音乐/分数/电脑-->/sx/szm/yy/fs/dn", " ")) yield(Candidate("help", seg.start, seg._end, "方块/麻将/象棋/色子/扑克-->/fk/mj/xq/sz/pk", " ")) yield(Candidate("help", seg.start, seg._end, "单位/货币/偏旁-->/dw/hb/pp", " ")) yield(Candidate("help", seg.start, seg._end, "标点/下标/竖标点-->/bd/xb/bdz", " ")) yield(Candidate("help", seg.start, seg._end, "希腊字符/大写-->/xl/xld", " ")) yield(Candidate("help", seg.start, seg._end, "罗马数字/大写-->/lm/lmd", " ")) yield(Candidate("help", seg.start, seg._end, "天干/地支/干支-->/tg/dz/gz", " ")) yield(Candidate("help", seg.start, seg._end, "八卦-->/bg/bgm/txj", " ")) yield(Candidate("help", seg.start, seg._end, "星座/名-->/xz/xzm/seg", " ")) yield(Candidate("help", seg.start, seg._end, "节气/天气-->/jq/tq", " ")) yield(Candidate("help", seg.start, seg._end, "数字/字母-->/123/abc...", " ")) yield(Candidate("help", seg.start, seg._end, "状态/推荐/进度/对错-->/zt/tj/jd/dc", " ")) elseif (input == "help") then yield(Candidate("help", seg.start, seg._end, "lua version: ".._VERSION, " ")) yield(Candidate("help", seg.start, seg._end, "特殊符号-->/help", " ")) yield(Candidate("help", seg.start, seg._end, "latexLetters-->uzalph", " ")) --yield(Candidate("help", seg.start, seg._end, "", " ")) --yield(Candidate("help", seg.start, seg._end, "", " ")) --yield(Candidate("help", seg.start, seg._end, "", " ")) end end return translator
rime.lua
help_translator = require("help")
help.lua脚本中的translator映射成rime可以引用的方法接口
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")
pinyin_translator = require("pinyin_translator")
pinyin_Filter = require("pinyin_Filter")
latexHelp_translator = require("latexHelp_translator")
latex_translator = require("latex_translator")
inputShow lua Translator 输入字符透传翻译器
lua文件夹
inputShow.lua
--对于指定的输入符号,需要直接提供对应转换值的输入选项,供后处理使用 local cands={} --以下单字母需要输出 cands['a']='a' cands['b']='b' cands['c']='c' cands['d']='d' cands['e']='e' cands['f']='f' cands['g']='g' cands['h']='h' cands['i']='i' cands['j']='j' cands['k']='k' cands['l']='l' cands['m']='m' cands['n']='n' cands['o']='o' cands['p']='p' cands['q']='q' cands['r']='r' cands['s']='s' cands['t']='t' cands['u']='u' cands['v']='v' cands['w']='w' cands['x']='x' cands['y']='y' cands['z']='z' --以下是常用简写的输出 cands['id']='id' cands['ip']='ip' --以下是化学元素简写,需要输出 cands['he']='He' cands['li']='Li' cands['be']='Be' cands['ne']='Ne' cands['na']='Na' cands['mg']='Mg' cands['al']='Al' cands['si']='Si' cands['cl']='Cl' cands['ar']='Ar' cands['ca']='Ca' cands['sc']='Sc' cands['ti']='Ti' cands['cr']='Cr' cands['mn']='Mn' cands['fe']='Fe' cands['co']='Co' cands['ni']='Ni' cands['cu']='Cu' cands['zn']='Zn' cands['ga']='Ga' cands['ge']='Ge' cands['as']='As' cands['se']='Se' cands['br']='Br' cands['kr']='Kr' cands['rb']='Rb' cands['sr']='Sr' cands['zr']='Zr' cands['nb']='Nb' cands['mo']='Mo' cands['tc']='Tc' cands['ru']='Ru' cands['rh']='Rh' cands['pd']='Pd' cands['ag']='Ag' cands['cd']='Cd' cands['in']='In' cands['sn']='Sn' cands['sb']='Sb' cands['te']='Te' cands['xe']='Xe' cands['cs']='Cs' cands['ba']='Ba' cands['la']='La' cands['ce']='Ce' cands['pr']='Pr' cands['nd']='Nd' cands['pm']='Pm' cands['sm']='Sm' cands['eu']='Eu' cands['gd']='Gd' cands['tb']='Tb' cands['dy']='Dy' cands['ho']='Ho' cands['er']='Er' cands['tm']='Tm' cands['yb']='Yb' cands['lu']='Lu' cands['hf']='Hf' cands['ta']='Ta' cands['re']='Re' cands['os']='Os' cands['ir']='Ir' cands['pt']='Pt' cands['au']='Au' cands['hg']='Hg' cands['tl']='Tl' cands['pb']='Pb' cands['bi']='Bi' cands['po']='Po' cands['at']='At' cands['rn']='Rn' cands['fr']='Fr' cands['ra']='Ra' cands['ac']='Ac' cands['th']='Th' cands['pa']='Pa' cands['np']='Np' cands['pu']='Pu' cands['am']='Am' cands['cm']='Cm' cands['bk']='Bk' cands['cf']='Cf' cands['es']='Es' cands['fm']='Fm' cands['md']='Md' cands['no']='No' cands['lr']='Lr' cands['rf']='Rf' cands['db']='Db' cands['sg']='Sg' cands['bh']='Bh' cands['hs']='Hs' cands['mt']='Mt' cands['ds']='Ds' cands['rg']='Rg' cands['cn']='Cn' cands['nh']='Nh' cands['fl']='Fl' cands['mc']='Mc' cands['lv']='Lv' cands['ts']='Ts' cands['og']='Og' function translator(input, seg) --抛出一个选项,用于告诉下游输入的内容是什么,为了避免和正式输入内容混淆,加入一个 Str的前缀 yield(Candidate("inputShow", seg.start, seg._end, 'Str'..input, "inputShowStr")) if nil~=cands[input] then if ''==cands[input] then yield(Candidate("inputShow", seg.start, seg._end, input, "inputShow")) else yield(Candidate("inputShow", seg.start, seg._end, cands[input], "inputShow")) end end end return translator
inputShow lua Filter 输入字符透传滤镜
Filter
增删选项
调整次序
修饰选项(comment)
lua文件夹
inputShow_Filter.lua
案例
-- spaceAppending.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> --[[ 这个脚本,作为filter来用,需要结合inputShow的在translator阶段的处理信息进行工作 --]] local function _inputShow(input, env) local cands = {} local candsSelflg=false local candsInput = {} local inputInfo = {str='',len=0,flg=false,candsCntLimitForLen={15,25}} local candsCnt = 0 for cand in input:iter() do if cand.comment == 'inputShowStr' then --这个选项表明了前端的输入编码信息 inputInfo.str = string.sub(cand.text,4) inputInfo.len = string.len(inputInfo.str) elseif cand.comment == 'inputShow' then --这是一个转换后需要展示的选项 inputInfo.flg = true local thisCand = {} thisCand.start = cand.start thisCand._end = cand._end thisCand.text = cand.text thisCand.comment = cand.comment table.insert(candsInput,cand) candsCnt = candsCnt + 1 else --这是一个没有转换的选项 table.insert(cands,cand) if string.find(cand.comment,'') then --标记选项中存在自造词 candsSelflg = true end candsCnt = candsCnt + 1 end if inputInfo.flg and 0~=inputInfo.len then --如果已经捕获取了inputShow选项 --根据输入的编码的长度,判断候选项数量是否已经够用 if nil~=inputInfo.candsCntLimitForLen[inputInfo.len] then if candsCnt >= inputInfo.candsCntLimitForLen[inputInfo.len] then break end end end end if 0==inputInfo.len then inputInfo.flg = false end local candsHasBeenYield=0 --下面开始抛出候选项 --第一步,如果存在自造词,则先抛出自造词 local candsFor2nd = {} for idx=1,#cands do if inputInfo.flg then if string.find(cands[idx].comment,'') then yield(cands[idx]) candsHasBeenYield = candsHasBeenYield + 1 else table.insert(candsFor2nd,cands[idx]) end else --如果不需要处理 inputShow,则不做处理,进行转存 table.insert(candsFor2nd,cands[idx]) end end --第二步,把编码完全项抛出,即没有comment(此处指的是编码提示的comment内容)的选项,以供优先选用 local candsFor4th = {} for idx=1,#candsFor2nd do if inputInfo.flg then if candsFor2nd[idx].comment == '' then yield(candsFor2nd[idx]) candsHasBeenYield = candsHasBeenYield + 1 else table.insert(candsFor4th,candsFor2nd[idx]) end else --如果不需要处理 inputShow,则不做处理,进行转存 table.insert(candsFor4th,candsFor2nd[idx]) end end --第三步,如果有的话,抛出inputShow的选项 for idx=1,#candsInput do local thisC = candsInput[idx] --此处的comment是 inputShow,为了不为后续造成干扰,此处需要清除comment内容 thisC:get_genuine().comment = '' yield(thisC) candsHasBeenYield = candsHasBeenYield + 1 end --第四步,如果还有其它选项,则抛出其它选项 for idx=1,#candsFor4th do if nil==inputInfo.candsCntLimitForLen[inputInfo.len] then yield(candsFor4th[idx]) elseif candsHasBeenYield<inputInfo.candsCntLimitForLen[inputInfo.len] then yield(candsFor4th[idx]) else break end candsHasBeenYield = candsHasBeenYield + 1 end end local function inputShow(input, env) --获取debug选项开关状态 --local debugSwitchSts = env.engine.context:get_option("debug") _inputShow(input,env) end return inputShow
Upper lua Filter 首字母大写滤镜
Filter
增删选项
调整次序
修饰选项(comment)
lua文件夹
Upper_Filter.lua
案例
-- Upper_Filter.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> -- 这个脚本,用于为英文单词提供一个首字母大写的候选项 -- 如果需要debug,可以在这里进行函数功能调试 local function _specialFunc(input, env) for cand in input:iter() do yield(cand) end end local function _upperFilter(input, env) local cands = {} local idx, idxSelf local selfFlg local candTxtLen idx = 0 idxSelf = 0 for cand in input:iter() do idx = idx + 1 --索引位置 selfFlg = cand.comment:find('') if selfFlg then --自动造词数量 idxSelf = idxSelf + 1 end --匹配英文字母 local s,e = string.find(cand.text,"^[a-z]+$") if nil == s then --匹配失败,说明不是英文单词 if selfFlg then --对于自动造词选项,使用如下逻辑 if idxSelf == 1 and idx == idxSelf then --对于第一条自动造词选项,不加干涉 yield(cand) else --对于非第一条自动造词选项,限制其长度 --candTxtLen = utf8.len(cand.text) yield(cand) end else --对于非自动造的词,则正常输出 yield(cand) end else --匹配成功,说明是英文单词 yield(cand) if idx == 1 then --如果这是第一个候选词,提供一个首字母大写的选项 local thisTxt=cand.text:gsub("^%l",string.upper) yield(Candidate("word", cand.start, cand._end, thisTxt, '')) --idx额外加1 idx = idx + 1 end end end end local function upperFilter(input, env) --获取debug选项开关状态 local debugSwitchSts = env.engine.context:get_option("debug") if debugSwitchSts then _specialFunc(input,env) else _upperFilter(input, env) end end return _upperFilter
中英互绎 滤镜
dic_4w_en.txt
aar 【Aar】n.阿尔河 aardvark 【aardvark】n.土豚;土猪 aardwolf 【aardwolf】n.土狼 aaron 【Aaron】n.艾伦 aaronic 【Aaronic】adj.亚伦的
dic_4w_cn.txt
阿尔河 aar(n.); 土豚 aardvark(n.); 土猪 aardvark(n.); 土狼 aardwolf(n.); 艾伦 aaron(n.); 亚伦 aaronic(adj.);
lua文件夹
dic_4w.lua
-- dic_4w_en.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> local ok, res = pcall(require, 'sysInfo') local currentDir = res.currentDir local function files_to_lines(...) print("--->files_to_lines called here") local tab=setmetatable({},{__index=table}) local index=1 for i,filename in next,{...} do local fn = io.open(filename) if fn then for line in fn:lines() do if not line or #line > 0 then tab:insert(line) end end fn:close() end end print("--->files_to_lines completed here") return tab end local function dictload(...) -- filename) print("-->dictload called here") local lines=files_to_lines(...) local dict={} for i,line in next ,lines do if not line:match("^%s*#") then -- 第一字 # 为注释行 local key,val = string.match(line,"(.+)\t(.+)") if nil ~= key then --此处,相同的key,后加载的内容将覆盖前面加载的内容 dict[key] = val end end end print("-->dictload completed here") return dict end -- Module local M={} local dict={} local function getVal(s) return dict[s] end function M.init(...) print("-> M.init called here") local files={...} --以下files文件的顺序,后面的内容优先级高于前面的, --即后面文件中同一key的value将覆盖前面文件内同一key的value --文件名不支持中文 table.insert(files,"dic_4w_cn.txt") table.insert(files,"dic_4w_en.txt") for i,v in next, files do files[i] = currentDir().."/".. v end dict= dictload(table.unpack(files)) M.getVal=getVal print("->M.init completed here") end M.init() return M
dic_4w_Filter.lua
-- spaceAppending.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> local ok, res = pcall(require, 'dic_4w') local getVal = res.getVal local ok, utf8String = pcall(require, 'utf8String') --最长的comment长度限制 local maxLenOfComment = 100 local function dic_4w_Filter(input, env) --获取中英对照开关状态 local on = env.engine.context:get_option("encnDic") for cand in input:iter() do if on then local candTxt = cand.text:gsub("%s","") or "" local thisComment = cand.comment if candTxt ~= "" then --获取字典释义 thisComment = getVal(candTxt) if nil == thisComment then thisComment = cand.comment else --成功获取了释义,下面进行一些格式化处理 --替换 <br> 为换行符 thisComment = thisComment:gsub("<br>","\r") --替换   为空格 thisComment = thisComment:gsub(" "," ") --需要限制释义长度为 maxLenOfComment thisComment = string.sub(thisComment, 1, maxLenOfComment) --去除首尾空格 和 符号 thisComment = utf8String.utf8PunctuationsTrim(thisComment) end if cand.comment ~= "" then if thisComment ~= cand.comment then if utf8.len(cand.comment) < 5 then if ''==cand.comment then thisComment = cand.comment..thisComment else thisComment = cand.comment..''..thisComment end else thisComment = cand.comment..'\r'..thisComment end end end end cand:get_genuine().comment = thisComment end yield(cand) end end return dic_4w_Filter
sysInfo.lua
local M={} local dbgFlg = false --设置 dbg 开关 M.setDbg = function(flg) dbgFlg = flg print('sysInfo dbgFlg is '..tostring(dbgFlg)) end M.homePath = function() return os.getenv("HOMEPATH") end M.computerName = function() return os.getenv("COMPUTERNAME") end M.userName = function() return os.getenv("USERNAME") end M.osName = function() return os.getenv("OS") end M.NUMBER_OF_PROCESSORS = function() return os.getenv("NUMBER_OF_PROCESSORS") end M.PROCESSOR_IDENTIFIER = function() return os.getenv("PROCESSOR_IDENTIFIER") end M.PROGRAMDATA = function() return os.getenv("PROGRAMDATA") end M.PROGRAMFILES = function() return os.getenv("PROGRAMW6432") end M.PROGRAMFILESx86 = function() return os.getenv("PROGRAMFILES(X86)") end M.APPDATA = function() return os.getenv("APPDATA") end M.WINDIR = function() return os.getenv("WINDIR") end M.COMMONPROGRAMFILES = function() return os.getenv("COMMONPROGRAMFILES") end M.COMMONPROGRAMFILESx86 = function() return os.getenv("COMMONPROGRAMFILES(x86)") end M.TEMP = function() local path = os.getenv("TEMP") if nil == path or '' == path then path = os.getenv("TMP") end return path end M.SYSTEMDRIVE = function() return os.getenv("SYSTEMDRIVE") end M.currentDir = function() local info = debug.getinfo(2) --debug.getinfo(2), 2: 返回调用 currentDir 的函数的信息 --解析info.source所在的路径 local path = info.source path = string.sub(path, 2, -1) -- 去掉开头的"@" path = string.gsub(path,'\\','/') -- 路径格式由 c:\\Users\\san.zhang\\ 转换为 c:/Users/san.zhang/ path = string.match(path, "^(.*)/") -- 捕获最后一个 "/" 之前的部分 就是我们最终要的目录部分 return path end M.test = function(printPrefix) if nil == printPrefix then printPrefix = ' ' end if dbgFlg then print(printPrefix..'sysInfo test starting...') print(printPrefix, 'currentDir is:', M.currentDir()) print(printPrefix, 'computerName is:', M.computerName()) print(printPrefix, 'homePath is:', M.homePath()) print(printPrefix, 'userName is:', M.userName()) end end return M
utf8String.lua
--utf8String.lua --这个模块主要用于处理一些utf8字符串相关的操作 -- 定义一个全局变量,用于记录一个随机数种子 randomseed = os.time() local M={} local dbgFlg = false --左侧标点,例如左侧括号,左侧引号等,以及单符号标点也被识为左侧标点,例如 | , 等 local punctuationsAtLeft = {[','] = true,[','] = true, ['。'] = true, ['.'] = true, [';'] = true,[';'] = true, ['、'] = true,['\\'] = true, ['?'] = true,['?'] = true, ['!'] = true,['!'] = true, ['@'] = true,['@'] = true, ['&'] = true,['&'] = true, ['/'] = true, ['…'] = true, [' '] = true, ['('] = true,['('] = true, ['‘'] = true,['“'] = true, ['['] = true,['['] = true,['【'] = true, ['<'] = true,['《'] = true,['〈'] = true } --右侧标点,例如右侧括号,右侧绰号等,以及单符号标点也被识别为右侧标点,例如 | , 等 local punctuationsAtRight = {[','] = true,[','] = true, ['。'] = true, ['.'] = true, [';'] = true,[';'] = true, ['、'] = true,['\\'] = true, ['?'] = true,['?'] = true, ['!'] = true,['!'] = true, ['@'] = true,['@'] = true, ['&'] = true,['&'] = true, ['/'] = true, ['…'] = true, [' '] = true, [')'] = true,[')'] = true, ['’'] = true,['”'] = true, [']'] = true,[']'] = true,['】'] = true, ['>'] = true,['》'] = true,['〉'] = true } local lettersForPwd = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "~", "!", "@", "#", "$", "%", "^", "&", "*", "-", "=", "+"} --设置 dbg 开关 local function setDbg(flg) dbgFlg = flg print('utf8String dbgFlg is '..tostring(dbgFlg)) end --判断给定的一个字符头,实际占用的字节数 local function chsize(char) if not char then return 0 elseif char > 240 then return 4 elseif char > 225 then return 3 elseif char > 192 then return 2 else return 1 end end --判断给定的一个字符串的实际字符长度 local function utf8Len(str) local len = 0 local currentIndex = 1 while currentIndex <= #str do local char = string.byte(str,currentIndex) currentIndex = currentIndex + chsize(char) len = len + 1 end return len end --根据给定的字符串,和指定的起始位置和字符数,截取子串 local function utf8Sub(str,startChar,numChars) local startIndex = 1 while startChar > 1 do local char = string.byte(str,startIndex) startIndex = startIndex + chsize(char) startChar = startChar - 1 end local currentIndex = startIndex while numChars > 0 and currentIndex <= #str do local char = string.byte(str,currentIndex) currentIndex = currentIndex + chsize(char) numChars = numChars - 1 end return str:sub(startIndex,currentIndex - 1) end --根据给定的字符串,去除其头尾的空白符 local function utf8Trim(str) str = str or '' local cnt = 0 local subChar = utf8Sub(str,1,1) --去除其头部的 空白 while subChar:match("%s") do str = utf8Sub(str,2,utf8Len(str)-1) subChar = utf8Sub(str,1,1) cnt = cnt + 1 end --去除其尾部的 空白 subChar = utf8Sub(str,utf8Len(str),1) while subChar:match("%s") do str = utf8Sub(str,1,utf8Len(str)-1) subChar = utf8Sub(str,utf8Len(str),1) cnt = cnt + 1 end return str,cnt end --根据给定的字符串,去除其头尾部的 符号 字符 local function utf8PunctuationsGo(str) str = str or '' local cnt = 0 local subChar = utf8Sub(str,1,1) --去除其头部的 右侧 标点 while punctuationsAtRight[subChar] do str = utf8Sub(str,2,utf8Len(str)-1) subChar = utf8Sub(str,1,1) cnt = cnt + 1 end --去除其尾部的 左侧 标点 subChar = utf8Sub(str,utf8Len(str),1) while punctuationsAtLeft[subChar] do str = utf8Sub(str,1,utf8Len(str)-1) subChar = utf8Sub(str,utf8Len(str),1) cnt = cnt + 1 end return str,cnt end --根据给定的字符串,去除其头尾部的 符号 和 空白 local function utf8PunctuationsTrim(str) str = str or '' local cnt = 0 local subChar = utf8Sub(str,1,1) --去除其头部的 右侧 标点 while punctuationsAtRight[subChar] do str = utf8Sub(str,2,utf8Len(str)-1) subChar = utf8Sub(str,1,1) cnt = cnt + 1 end --去除其尾部的 左侧 标点 subChar = utf8Sub(str,utf8Len(str),1) while punctuationsAtLeft[subChar] do str = utf8Sub(str,1,utf8Len(str)-1) subChar = utf8Sub(str,utf8Len(str),1) cnt = cnt + 1 end return str,cnt end --生成一个指定长度的随机密码 function newPwd(len, easyRead) len = len or 8 easyRead = easyRead or true local pwd = '' local tmpChar = '' local cntForOptions = #lettersForPwd -- 初始化随机数种子 math.randomseed(randomseed) repeat -- 重置随机数种子 randomseed = math.random(0, 100000000) --随机挑选一个字符 tmpChar = lettersForPwd[math.random(cntForOptions)] if easyRead then --如果要求易读,则禁用 1,l,o,O,0 这些字符 if not ({['1']=true, ['l']=true, ['o']=true, ['O']=true, ['0']=true})[tmpChar] then pwd = pwd .. tmpChar end else pwd = pwd .. tmpChar end until (#pwd >= len) return pwd end --这是用于测试的函数 local function test(printPrefix) if nil == printPrefix then printPrefix = ' ' end if dbgFlg then print(printPrefix,'utf8StringModule test starting...') print(printPrefix,utf8Len("好好学习5天天向上")) print(printPrefix,utf8Sub("好好学习5天天向上",5,2)) end end --Module function M.init(...) M.utf8Sub = utf8Sub M.utf8Len = utf8Len M.utf8Trim = utf8Trim M.utf8PunctuationsGo = utf8PunctuationsGo M.utf8PunctuationsTrim = utf8PunctuationsTrim M.newPwd = newPwd M.setDbg = setDbg M.test = test end M.init() return M
敏感词脱敏滤镜
lua文件夹
phraseReplace.txt
# 以下为敏感词列表 操 操作 撒尿 叫春 淫荡 裸体 全裸 发情 母狗 肉欲 肛门 做爱 作爱 阴蒂 英帝 阴道 英伦三岛 下体 外阴 骚货 扫货 骚逼 阴唇 子宫 乳房 乳头 乳晕 奶子 包皮 龟头 阴茎 阴囊 射精 屌 大屌 阴毛 阴户 骚毛 屌毛 逼毛 穴毛 小穴 骚穴 射精 遗精 梦遗 口交 口角 肛交 乳交 颜射 抖阴 抖音 情妇 情侣 强奸 发骚 内射 吃精 精液 交媾 干逼 嫩穴 嫩逼 咪咪 自慰 大屌 少妇 少婦 开鲍 开苞 处女 处女座 私处 色情 鸡巴 套套 情趣 鸡鸡 发浪 下贱 野战 摸胸 性功能 性行为 援交 胸罩 胸围 三围 月经 奶水 下身 骚气 性交 交配 交媾 女同事 奸淫
使用符号 # 来进行注释
第一列是要脱敏的敏感词
第二列是脱敏后的替代词,如果没有,则默认处理成 * 号
phraseReplaceModule.lua
-- phraseReplaceModule.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> local M={} local dict={} local dbgFlg = false --引入系统变更处理模块 local ok, sysInfoRes = pcall(require, 'sysInfo') local currentDir = sysInfoRes.currentDir local userName = sysInfoRes.userName --设置 dbg 开关 local function setDbg(flg) dbgFlg = flg sysInfoRes.setDbg(flg) print('phraseReplace dbgFlg is '..tostring(dbgFlg)) end --将文档处理成行数组 local function files_to_lines(...) if dbgFlg then print("--->files_to_lines called here") end local tab=setmetatable({},{__index=table}) local index=1 for i,filename in next,{...} do local fn = io.open(filename) if fn then for line in fn:lines() do if not line or #line > 0 then tab:insert(line) end end fn:close() end end if dbgFlg then print("--->files_to_lines completed here") end return tab end local function dictload(...) -- filename) if dbgFlg then print("-->dictload called here") end local lines=files_to_lines(...) local thisDict={} for i,line in next ,lines do if not line:match("^%s*#") then -- 第一字 # 为注释行 local key,val = string.match(line,"(.+)\t(.+)") if nil == key then key = string.match(line,'(%S+)') val = '' end if nil ~= key then --此处,如果key 已经存在,则使用后来的值顶替旧的值 thisDict[key] = val end end end if dbgFlg then print("-->dictload completed here") end return thisDict end --===========================test======================== local function test(printPrefix) if nil == printPrefix then printPrefix = ' ' end if dbgFlg then print('phraseReplace test starting...') sysInfoRes.test(printPrefix..' ') for k,v in pairs(dict) do if dbgFlg then print(printPrefix..k..'\t'..v) end end end end --获取字典中的phrase local function getShownPhrase(k) if nil == k then return '' elseif '' == k then return '' end --尝试获取 dictPhraseList 中 k 的列表 return dict[k] end function M.init(...) local files={...} --文件名不支持中文,其中 # 开始的行为注释行 table.insert(files,"phraseReplace.txt") for i,v in next, files do files[i] = currentDir().."/".. v end dict= dictload(table.unpack(files)) --抛出功能函数 M.getShownPhrase = getShownPhrase M.userName = userName M.setDbg = setDbg M.test = test end M.init() return M
phraseReplace_Filter.lua
-- phraseReplace_Filter.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> --[[ 这个过滤器的主要作用是,对于候选项中命中的选项(OR 内容),用其指定的内容来代替,如果没有指定,则使用 * 替换 由于这个过滤器会改变候选项的内容(主要是会减少候选项数量),所以请将这个过滤器放在其它过滤器的最前端使用 ]] local phraseShown = '' local ok, res = pcall(require, 'phraseReplaceModule') local getShownPhrase = res.getShownPhrase --最长的comment长度限制 local maxLenOfComment = 250 local function phraseReplace_Filter(input, env) --获取选项敏感词替换开关状态 local on = env.engine.context:get_option("phraseReplace") local candsHasBeenHidden = {} local candStart,candEnd for cand in input:iter() do candStart = cand.start candEnd = cand._end local candTxt = cand.text:gsub("%s","") or "" phraseShown = getShownPhrase(candTxt) if nil ~= phraseShown then --不管是否开启选项替换,如果该选项是被命中的替换项,则加上替换标记 cand.comment = ''..cand.comment if '' ~= phraseShown then if on then --如果开启了选项替换功能,且存在替换内容 yield(Candidate("word", cand.start, cand._end, phraseShown, cand.comment)) else --如果未开启选项替换功能 yield(cand) end else if on then --如果开启了选项替换功能,且这个选项应该被隐藏 table.insert(candsHasBeenHidden,candTxt) else --如果未开启选项替换功能 yield(cand) end end else yield(cand) end end --如果有被隐藏的选项,则抛出一个 * 选项提示 if 0 < #candsHasBeenHidden then yield(Candidate("word", candEnd-1, candEnd, '*', '')) end end return phraseReplace_Filter
sysInfo.lua
local M={} local dbgFlg = false --设置 dbg 开关 M.setDbg = function(flg) dbgFlg = flg print('sysInfo dbgFlg is '..tostring(dbgFlg)) end M.homePath = function() return os.getenv("HOMEPATH") end M.computerName = function() return os.getenv("COMPUTERNAME") end M.userName = function() return os.getenv("USERNAME") end M.osName = function() return os.getenv("OS") end M.NUMBER_OF_PROCESSORS = function() return os.getenv("NUMBER_OF_PROCESSORS") end M.PROCESSOR_IDENTIFIER = function() return os.getenv("PROCESSOR_IDENTIFIER") end M.PROGRAMDATA = function() return os.getenv("PROGRAMDATA") end M.PROGRAMFILES = function() return os.getenv("PROGRAMW6432") end M.PROGRAMFILESx86 = function() return os.getenv("PROGRAMFILES(X86)") end M.APPDATA = function() return os.getenv("APPDATA") end M.WINDIR = function() return os.getenv("WINDIR") end M.COMMONPROGRAMFILES = function() return os.getenv("COMMONPROGRAMFILES") end M.COMMONPROGRAMFILESx86 = function() return os.getenv("COMMONPROGRAMFILES(x86)") end M.TEMP = function() local path = os.getenv("TEMP") if nil == path or '' == path then path = os.getenv("TMP") end return path end M.SYSTEMDRIVE = function() return os.getenv("SYSTEMDRIVE") end M.currentDir = function() local info = debug.getinfo(2) --debug.getinfo(2), 2: 返回调用 currentDir 的函数的信息 --解析info.source所在的路径 local path = info.source path = string.sub(path, 2, -1) -- 去掉开头的"@" path = string.gsub(path,'\\','/') -- 路径格式由 c:\\Users\\san.zhang\\ 转换为 c:/Users/san.zhang/ path = string.match(path, "^(.*)/") -- 捕获最后一个 "/" 之前的部分 就是我们最终要的目录部分 return path end M.test = function(printPrefix) if nil == printPrefix then printPrefix = ' ' end if dbgFlg then print(printPrefix..'sysInfo test starting...') print(printPrefix, 'currentDir is:', M.currentDir()) print(printPrefix, 'computerName is:', M.computerName()) print(printPrefix, 'homePath is:', M.homePath()) print(printPrefix, 'userName is:', M.userName()) end end return M
生字/汉字注音滤镜
lua文件夹
pinyinAdding.txt
冔 冔(xǔ) 玏 玏(lè) 鹯 鹯(zhān) 亶 亶(dǎn) 荥 荥(yíng) 荥阳 荥(xíng)阳
pinyinAddingModule.lua
-- pinyinAddingModule.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> local M={} local dict={} local dbgFlg = true --引入系统变更处理模块 local ok, sysInfoRes = pcall(require, 'sysInfo') local currentDir = sysInfoRes.currentDir local userName = sysInfoRes.userName --引入utf8String,用于处理utf8字符串 local of,utf8Str = pcall(require, 'utf8String') local utf8Sub = utf8Str.utf8Sub local utf8Len = utf8Str.utf8Len --设置 dbg 开关 local function setDbg(flg) dbgFlg = flg sysInfoRes.setDbg(flg) print('pinyinAddingModule dbgFlg is '..tostring(dbgFlg)) end --将文档处理成行数组 local function files_to_lines(...) if dbgFlg then print("--->files_to_lines called here") end local tab=setmetatable({},{__index=table}) local index=1 for i,filename in next,{...} do local fn = io.open(filename) if fn then for line in fn:lines() do if not line or #line > 0 then tab:insert(line) end end fn:close() end end if dbgFlg then print("--->files_to_lines completed here") end return tab end local function dictload(...) -- filename) if dbgFlg then print("-->dictload called here") end local lines=files_to_lines(...) local thisDict={} for i,line in next ,lines do if not line:match("^%s*#") then -- 第一字 # 为注释行 local key,val = string.match(line,"(.+)\t(.+)") if nil ~= key then --此处,如果key 已经存在,则使用后来的值顶替旧的值 if ''~=val then thisDict[key] = val end end end end if dbgFlg then print("-->dictload completed here") end return thisDict end --===========================test======================== local function test(printPrefix) if nil == printPrefix then printPrefix = ' ' end if dbgFlg then print(printPrefix,'pinyinAddingModule test starting...') sysInfoRes.test(printPrefix..' ') for k,v in pairs(dict) do if dbgFlg then print(printPrefix..k..'\t'..v) end end end end --这是一个递归函数,用于在给定的字符串中查找最大能匹配的子串 local function getItmInDicByStr(Str) Str = Str or '' if ''==Str then --返回子串值,匹配值,匹配长度 return '','',0 end local itmKey,itmLen,itmVal,strLen,flg strLen = utf8Len(Str) flg=false for idx=strLen,1,-1 do itmKey = utf8Sub(Str,1,idx) if''~=itmKey then itmVal = dict[itmKey] if nil~=itmVal then itmLen = idx flg = true break end end end if flg then return itmKey,itmVal,itmLen else return '','',0 end end local function pinyinAdding(k) k = k or '' if ''==k then return k end local valStr,kLen local subK,subKVal,subKLen local matchPosition valStr = '' kLen = utf8Len(k) matchPosition = 1 while matchPosition <= kLen do subK,subKVal,subKLen = getItmInDicByStr(utf8Sub(k,matchPosition,kLen)) if ''==subK then valStr = valStr..utf8Sub(k,matchPosition,1) matchPosition = matchPosition + 1 else valStr =valStr..subKVal matchPosition = matchPosition + subKLen end end return valStr end function M.init(...) local files={...} --文件名不支持中文,其中 # 开始的行为注释行 table.insert(files,"pinyinAdding.txt") for i,v in next, files do files[i] = currentDir().."/".. v end dict= dictload(table.unpack(files)) --抛出功能函数 M.pinyinAdding = pinyinAdding M.pinyinAddingT = pinyinAdding M.setDbg = setDbg M.test = test end M.init() return M
pinyinAdding_Filter.lua
-- phraseReplace_Filter.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> --[[ 这个过滤器的主要作用是,对于候选项中命中的选项(OR 内容),用其指定的内容来代替,如果没有指定,则使用 * 替换 由于这个过滤器会改变候选项的内容(主要是会减少候选项数量),所以请将这个过滤器放在其它过滤器的最前端使用 ]] local phraseShown = '' local ok, py = pcall(require, 'pinyinAddingModule') --最长的comment长度限制 local maxLenOfComment = 250 local function pinyinAdding(input, env) --获取选项pinyin开关状态 local pySwitchFlg = env.engine.context:get_option("pinyin") or false --如果pySwitchFlg是true状态,则替换原选项,如果是false状态,则在comment中注音 local pyInCommentFlg = true if pySwitchFlg then pyInCommentFlg = false end for cand in input:iter() do local txtWithPy = py.pinyinAdding(cand.text) if nil == txtWithPy then --没有获取到 txtWithPy,则不做处理 yield(cand) elseif txtWithPy == cand.text then --txtWithPy 与 原候选词一致,则不做处理 yield(cand) else --获取到了 txtWithPy,且不与原候选词一致 if pyInCommentFlg or string.find(cand.comment,'') then --如果需要加到comment里,或者这是一个自造词,为了不影响自造词功能,也需要加到commnet里 if ''==cand.comment then cand:get_genuine().comment = txtWithPy else if utf8.len(cand.comment) < 5 then cand:get_genuine().comment = cand.comment..''..txtWithPy else cand:get_genuine().comment = cand.comment..'\r'..txtWithPy end end yield(cand) else --如果不加到comment,则替换原选项,注意,替换原选项,会影响自动调频功能 cand.text = txtWithPy if cand.text == txtWithPy then yield(cand) else yield(Candidate("word", cand.start, cand._end, txtWithPy, cand.comment)) end end end end end return pinyinAdding
日期/农历 时间 事件 节气 滤镜
农历与二十四节气
lua文件夹
lunarjieQiModule.lua
--该计算脚本取自 博文 https://www.cnblogs.com/moodlxs/archive/2012/09/15/2686472.html --感谢博主 绿色冰点 对脚本的贡献和分享 local dbgFlg = false local function setDbg(flg, printPrefix) dbgFlg = flg if nil == printPrefix then printPrefix = '' end if flg then print(printPrefix..'flg in lunar is true') end end --节气表 local jqB={"春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至","小寒","大寒","立春","雨水","惊蛰"} local yueMing={"正","二","三","四","五","六","七","八","九","十","冬","腊"} --存储以当前日期所在年分为中心,前后各1年,共3年的节气数据,以及对应的节气名 local jq3Y={} local jqN3Y={} --*******农历节气计算部分 --========角度变换=============== --每弧度的角秒数 local rad = 180*3600/math.pi --每弧度的角度数 local RAD = 180/math.pi --取整数部分 local function int2(v) v=math.floor(v) if v<0 then return v+1 else return v end end --对超过0-2PI的角度转为0-2PI local function rad2mrad(v) v=math.fmod(v ,2*math.pi) if v<0 then return v+2*math.pi else return v end end --将弧度转为字串 local function rad2str(d,tim) ---tim=0输出格式示例: -23°59' 48.23" ---tim=1输出格式示例: 18h 29m 44.52s local s="+" local w1="°" w2="’" w3="”" if d<0 then d=-d s='-' end if tim~= 0 then d=d*12/math.pi w1="h " w2="m " w3="s " else d=d*180/math.pi end local a=math.floor(d) d=(d-a)*60 local b=math.floor(d) d=(d-b)*60 local c=math.floor(d) d=(d-c)*100 d=math.floor(d+0.5) if d>=100 then d=d-100 c=c+1 end if c>=60 then c=c-60 b=b+1 end if b>=60 then b=b-60 a=a+1 end a=" "+a b="0"+b c="0"+c d="0"+d local alen = string.len(a) local blen = string.len(b) local clen = string.len(c) local dlen = string.len(d) s = s..string.sub(a, alen-3,alen)+w1 s = s..string.sub(b, blen-2,blen)+w2 s = s..string.sub(c, clen-2,clen)+"." s = s..string.sub(d, dlen-2,dlen)+w3 return s end --================日历计算=============== --2000年前儒略日数(2000-1-1 12:00:00格林威治平时) local J2000=2451545 --日期元件 local JDate={ Y=2000, M=1, D=1, h=12, m=0, s=0, --世界时与原子时之差计算表 dts = {-4000,108371.7,-13036.80,392.000, 0.0000, -500, 17201.0, -627.82, 16.170,-0.3413, -150, 12200.6, -346.41, 5.403,-0.1593, 150, 9113.8, -328.13, -1.647, 0.0377, 500, 5707.5, -391.41, 0.915, 0.3145, 900, 2203.4, -283.45, 13.034,-0.1778, 1300, 490.1, -57.35, 2.085,-0.0072, 1600, 120.0, -9.81, -1.532, 0.1403, 1700, 10.2, -0.91, 0.510,-0.0370, 1800, 13.4, -0.72, 0.202,-0.0193, 1830, 7.8, -1.81, 0.416,-0.0247, 1860, 8.3, -0.13, -0.406, 0.0292, 1880, -5.4, 0.32, -0.183, 0.0173, 1900, -2.3, 2.06, 0.169,-0.0135, 1920, 21.2, 1.69, -0.304, 0.0167, 1940, 24.2, 1.22, -0.064, 0.0031, 1960, 33.2, 0.51, 0.231,-0.0109, 1980, 51.0, 1.29, -0.026, 0.0032, 2000, 64.7, -1.66, 5.224,-0.2905, 2150, 279.4, 732.95,429.579, 0.0158, 6000}, --计算世界时与原子时之差,传入年 deltatT = function(JDate,y) local i local d=JDate.dts for x=1,100, 5 do if y<d[x+5] or x==96 then i=x break end end local t1=(y-d[i])/(d[i+5]-d[i])*10 local t2=t1*t1 local t3=t2*t1 return d[i+1] +d[i+2]*t1 +d[i+3]*t2 +d[i+4]*t3 end, --传入儒略日(J2000起算),计算UTC与原子时的差(单位:日) deltatT2 = function(JDate,jd,info) return JDate:deltatT(jd/365.2425+2000)/86400.0 end, --公历转儒略日,UTC=1表示原日期是UTC toJD = function(JDate,UTC) --取出年月 local y=JDate.Y m=JDate.M n=0 if m<=2 then m=m+12 y=y-1 end --判断是否为格里高利历日1582*372+10*31+15 if JDate.Y*372+JDate.M*31+JDate.D>=588829 then --加百年闰 n =int2(y/100) n =2-n+int2(n/4) end --加上年引起的偏移日数 n = n + int2(365.2500001*(y+4716)) --加上月引起的偏移日数及日偏移数 n = n + int2(30.6*(m+1))+JDate.D n = n + ((JDate.s/60+JDate.m)/60+JDate.h)/24 - 1524.5 if(UTC == 1) then return n+JDate:deltatT2(n-J2000,'142') else return n end end, --儒略日数转公历,UTC=1表示目标公历是UTC setFromJD = function(JDate,jd,UTC) if UTC==1 then jd= jd - JDate:deltatT2(jd-J2000,'150') end jd=jd+0.5 --取得日数的整数部份A及小数部分F local A=int2(jd) local F=jd-A local D=0 if A>2299161 then D=int2((A-1867216.25)/36524.25) A=A+1+D-int2(D/4) end --向前移4年零2个月 A = A + 1524 --年 JDate.Y =int2((A-122.1)/365.25) --去除整年日数后余下日数 D =A-int2(365.25*JDate.Y) --月数 JDate.M =int2(D/30.6001) --去除整月日数后余下日数 JDate.D =D-int2(JDate.M*30.6001) JDate.Y=JDate.Y-4716 JDate.M=JDate.M-1 if JDate.M>12 then JDate.M=JDate.M - 12 end if JDate.M<=2 then JDate.Y = JDate.Y+1 end --日的小数转为时分秒 F=F*24 JDate.h=int2(F) F=F - JDate.h F=F*60 JDate.m=int2(F) F=F - JDate.m F=F*60 JDate.s=F end, --设置时间,参数例:"20000101 120000"或"20000101" setFromStr = function(JDate, s) JDate.Y=string.sub(s, 1,4) JDate.M=string.sub(s, 5, 6) JDate.D=string.sub(s,7, 8) JDate.h=string.sub(s, 10, 11) JDate.m=string.sub(s, 12,13) JDate.s=string.sub(s, 14,18) end, --日期转为串 toStr = function(JDate) local Y="0"..JDate.Y local M="0"..JDate.M local D="0"..JDate.D local h=JDate.h local m=JDate.m local s=math.floor(JDate.s+.5) if s>=60 then s=s-60 m=m+1 end if m>=60 then m=m-60 h=h+1 end h="0".. h m="0"..m s="0"..s local Ylen = string.len(Y) local Mlen = string.len(M) local Dlen = string.len(D) local hlen = string.len(h) local mlen = string.len(m) local slen = string.len(s) Y=string.sub(Y, Ylen-3,Ylen) M=string.sub(M, Mlen-1,Mlen) D=string.sub(D,Dlen-1, Dlen) h=string.sub(h, hlen-1, hlen) m=string.sub(m, mlen-1,mlen) s=string.sub(s, slen-1,slen) return Y.."-"..M.."-"..D.." "..h..":"..m..":"..s end, --输出节气日期的秒数 JQ = function(JDate) local t = {} t.year=JDate.Y t.month=JDate.M t.day=JDate.D t.hour=JDate.h t.min=JDate.m t.sec=math.floor(JDate.s+.5) if t.sec>=60 then t.sec=t.sec-60 t.min=t.min+1 end if t.min>=60 then t.min=t.min-60 t.hour=t.hour+1 end return os.time(t) end, --算出:jd 转到当地UTC后,UTC日数的整数部分或小数部分 Dint_dec = function(JDate,jd,shiqu,int_dec) --基于J2000力学时jd的起算点是12:00:00时,所以跳日时刻发生在12:00:00,这与日历计算发生矛盾 --把jd改正为00:00:00起算,这样儒略日的跳日动作就与日期的跳日同步 --改正方法为jd=jd+0.5-deltatT+shiqu/24 --把儒略日的起点移动-0.5(即前移12小时) --式中shiqu是时区,北京的起算点是-8小时,shiqu取8 local u=jd+0.5-JDate:deltatT2(jd,'252')+shiqu/24 if int_dec~= 0 then --返回整数部分 return math.floor(u) else --返回小数部分 return u-math.floor(u) end end, --计算两个日期的相差的天数,输入字串格式日期,如:"20080101" d1_d2 = function(JDate,d1,d2) --备份原来的数据 local Y=JDate.Y local M=JDate.M local D=JDate.D local h=JDate.h local m=JDate.m local s=JDate.s JDate.setFromStr(string.sub(d1,1,8)+" 120000") local jd1=JDate.toJD(0) JDate.setFromStr(string.sub(d2,1,8)+" 120000") local jd2=JDate.toJD(0) --还原 JDate.Y=Y JDate.M=M JDate.D=D JDate.h=h JDate.m=m JDate.s=s if jd1>jd2 then return math.floor(jd1-jd2+.0001) else return -Math.floor(jd2-jd1+.0001) end end, } --=========黄赤交角及黄赤坐标变换=========== --黄赤交角系数表 local hcjjB = {84381.448, -46.8150, -0.00059, 0.001813} --Date黄道上的岁差p local preceB= {0,50287.92262,111.24406,0.07699,-0.23479,-0.00178,0.00018,0.00001} --返回黄赤交角(常规精度),短期精度很高 local function hcjj1 (t) local t1=t/36525 local t2=t1*t1 local t3=t2*t1 return (hcjjB[1] +hcjjB[2]*t1 +hcjjB[3]*t2 +hcjjB[4]*t3)/rad end --黄赤转换(黄赤坐标旋转) local function HCconv(JW,E) --黄道赤道坐标变换,赤到黄E取负 local HJ=rad2mrad(JW[1]) local HW=JW[2] local sinE =math.sin(E) local cosE =math.cos(E) local sinW=cosE*math.sin(HW)+sinE*math.cos(HW)*math.sin(HJ) local J=math.atan2( math.sin(HJ)*cosE-math.tan(HW)*sinE, math.cos(HJ)) JW[1]=rad2mrad(J) JW[2]=math.asin(sinW) end --补岁差 local function addPrece(jd,zb) local i local t=1 local v=0 local t1=jd/365250 for i=2,8 do t=t*t1 v=v+preceB[i]*t end zb[1]=rad2mrad(zb[1]+(v+2.9965*t1)/rad) end --===============光行差================== --离心率 local GXC_e={0.016708634, -0.000042037,-0.0000001267} --近点 local GXC_p={102.93735/RAD,1.71946/RAD, 0.00046/RAD} --太平黄经 local GXC_l={280.4664567/RAD,36000.76982779/RAD,0.0003032028/RAD,1/49931000/RAD,-1/153000000/RAD} --光行差常数 local GXC_k=20.49552/rad --恒星周年光行差计算(黄道坐标中) local function addGxc(t,zb) local t1=t/36525 local t2=t1*t1 local t3=t2*t1 local t4=t3*t1 local L=GXC_l[1] +GXC_l[2]*t1 +GXC_l[3]*t2 +GXC_l[4]*t3 +GXC_l[5]*t4 local p=GXC_p[1] +GXC_p[2]*t1 +GXC_p[3]*t2 local e=GXC_e[1] +GXC_e[2]*t1 +GXC_e[3]*t2 local dL=L-zb[1] local dP=p-zb[1] zb[1]=zb[1] - (GXC_k * (math.cos(dL)-e*math.cos(dP)) / math.cos(zb[2])) zb[2]=zb[2] - (GXC_k * math.sin(zb[2]) * (math.sin(dL)-e*math.sin(dP))) --print('aa', L,p,e,dL,dP,zb[1], zb[2]) zb[1]=rad2mrad(zb[1]) end --===============章动计算================== --章动表 local nutB={2.1824391966, -33.757045954, 0.0000362262, 3.7340E-08,-2.8793E-10,-171996,-1742,92025, 89, 3.5069406862, 1256.663930738, 0.0000105845, 6.9813E-10,-2.2815E-10, -13187, -16, 5736,-31, 1.3375032491, 16799.418221925,-0.0000511866, 6.4626E-08,-5.3543E-10, -2274, -2, 977, -5, 4.3648783932, -67.514091907, 0.0000724525, 7.4681E-08,-5.7586E-10, 2062, 2, -895, 5, 0.0431251803, -628.301955171, 0.0000026820, 6.5935E-10, 5.5705E-11, -1426, 34, 54, -1, 2.3555557435, 8328.691425719, 0.0001545547, 2.5033E-07,-1.1863E-09, 712, 1, -7, 0, 3.4638155059, 1884.965885909, 0.0000079025, 3.8785E-11,-2.8386E-10, -517, 12, 224, -6, 5.4382493597, 16833.175267879,-0.0000874129, 2.7285E-08,-2.4750E-10, -386, -4, 200, 0, 3.6930589926, 25128.109647645, 0.0001033681, 3.1496E-07,-1.7218E-09, -301, 0, 129, -1, 3.5500658664, 628.361975567, 0.0000132664, 1.3575E-09,-1.7245E-10, 217, -5, -95, 3} --计算黄经章动及交角章动 local function nutation(t) local d={} d.Lon=0 d.Obl=0 t=t/36525 local i,c local t1=t local t2=t1*t1 local t3=t2*t1 local t4=t3*t1 local t5=t4*t1 for i=1,#nutB,9 do c=nutB[i] +nutB[i+1]*t1 +nutB[i+2]*t2 +nutB[i+3]*t3 +nutB[i+4]*t4 --黄经章动 d.Lon=d.Lon + (nutB[i+5]+nutB[i+6]*t/10)*math.sin(c) --交角章动 d.Obl=d.Obl + (nutB[i+7]+nutB[i+8]*t/10)*math.cos(c) end --黄经章动 d.Lon=d.Lon/(rad*10000) --交角章动 d.Obl=d.Obl/(rad*10000) return d end --本函数计算赤经章动及赤纬章动 local function nutationRaDec(t,zb) local Ra=zb[1] local Dec=zb[2] local E=hcjj1(t) local sinE=math.sin(E) --计算黄赤交角 local cosE=math.cos(E) --计算黄经章动及交角章动 local d=nutation(t) local cosRa=math.cos(Ra) local sinRa=math.sin(Ra) local tanDec=math.tan(Dec) --赤经章动 zb[1]=zb[1] + (cosE+sinE*sinRa*tanDec)*d.Lon-cosRa*tanDec*d.Obl --赤纬章动 zb[2]= zb[2] + sinE*cosRa*d.Lon+sinRa*d.Obl zb[1]=rad2mrad(zb[1]) end --=================以下是月球及地球运动参数表=================== --[[*************************************** * 如果用记事本查看此代码,请在"格式"菜单中去除"自动换行" * E10是关于地球的,格式如下: * 它是一个数组,每3个数看作一条记录,每条记录的3个数记为A,B,C * rec=A*cos(B+C*t) 式中t是J2000起算的儒略千年数 * 每条记录的计算结果(即rec)取和即得地球的日心黄经的周期量L0 * E11格式如下: rec = A*cos*(B+C*t) *t, 取和后得泊松量L1 * E12格式如下: rec = A*cos*(B+C*t) *t*t, 取和后得泊松量L2 * E13格式如下: rec = A*cos*(B+C*t) *t*t*t, 取和后得泊松量L3 * 最后地球的地心黄经:L = L0+L1+L2+L3+... * E20,E21,E22,E23...用于计算黄纬 * M10,M11等是关于月球的,参数的用法请阅读Mnn()函数 ***************************************** --]] --地球运动VSOP87参数 --黄经周期项 local E10={1.75347045673, 0.00000000000, 0.0000000000, 0.03341656456, 4.66925680417, 6283.0758499914, 0.00034894275, 4.62610241759, 12566.1516999828, 0.00003417571, 2.82886579606, 3.5231183490, 0.00003497056, 2.74411800971, 5753.3848848968, 0.00003135896, 3.62767041758, 77713.7714681205, 0.00002676218, 4.41808351397, 7860.4193924392, 0.00002342687, 6.13516237631, 3930.2096962196, 0.00001273166, 2.03709655772, 529.6909650946, 0.00001324292, 0.74246356352, 11506.7697697936, 0.00000901855, 2.04505443513, 26.2983197998, 0.00001199167, 1.10962944315, 1577.3435424478, 0.00000857223, 3.50849156957, 398.1490034082, 0.00000779786, 1.17882652114, 5223.6939198022, 0.00000990250, 5.23268129594, 5884.9268465832, 0.00000753141, 2.53339053818, 5507.5532386674, 0.00000505264, 4.58292563052, 18849.2275499742, 0.00000492379, 4.20506639861, 775.5226113240, 0.00000356655, 2.91954116867, 0.0673103028, 0.00000284125, 1.89869034186, 796.2980068164, 0.00000242810, 0.34481140906, 5486.7778431750, 0.00000317087, 5.84901952218, 11790.6290886588, 0.00000271039, 0.31488607649, 10977.0788046990, 0.00000206160, 4.80646606059, 2544.3144198834, 0.00000205385, 1.86947813692, 5573.1428014331, 0.00000202261, 2.45767795458, 6069.7767545534, 0.00000126184, 1.08302630210, 20.7753954924, 0.00000155516, 0.83306073807, 213.2990954380, 0.00000115132, 0.64544911683, 0.9803210682, 0.00000102851, 0.63599846727, 4694.0029547076, 0.00000101724, 4.26679821365, 7.1135470008, 0.00000099206, 6.20992940258, 2146.1654164752, 0.00000132212, 3.41118275555, 2942.4634232916, 0.00000097607, 0.68101272270, 155.4203994342, 0.00000085128, 1.29870743025, 6275.9623029906, 0.00000074651, 1.75508916159, 5088.6288397668, 0.00000101895, 0.97569221824, 15720.8387848784, 0.00000084711, 3.67080093025, 71430.6956181291, 0.00000073547, 4.67926565481, 801.8209311238, 0.00000073874, 3.50319443167, 3154.6870848956, 0.00000078756, 3.03698313141, 12036.4607348882, 0.00000079637, 1.80791330700, 17260.1546546904, 0.00000085803, 5.98322631256,161000.6857376741, 0.00000056963, 2.78430398043, 6286.5989683404, 0.00000061148, 1.81839811024, 7084.8967811152, 0.00000069627, 0.83297596966, 9437.7629348870, 0.00000056116, 4.38694880779, 14143.4952424306, 0.00000062449, 3.97763880587, 8827.3902698748, 0.00000051145, 0.28306864501, 5856.4776591154, 0.00000055577, 3.47006009062, 6279.5527316424, 0.00000041036, 5.36817351402, 8429.2412664666, 0.00000051605, 1.33282746983, 1748.0164130670, 0.00000051992, 0.18914945834, 12139.5535091068, 0.00000049000, 0.48735065033, 1194.4470102246, 0.00000039200, 6.16832995016, 10447.3878396044, 0.00000035566, 1.77597314691, 6812.7668150860, 0.00000036770, 6.04133859347, 10213.2855462110, 0.00000036596, 2.56955238628, 1059.3819301892, 0.00000033291, 0.59309499459, 17789.8456197850, 0.00000035954, 1.70876111898, 2352.8661537718} --黄经泊松1项 local E11={6283.31966747491,0.00000000000, 0.0000000000, 0.00206058863, 2.67823455584, 6283.0758499914, 0.00004303430, 2.63512650414, 12566.1516999828, 0.00000425264, 1.59046980729, 3.5231183490, 0.00000108977, 2.96618001993, 1577.3435424478, 0.00000093478, 2.59212835365, 18849.2275499742, 0.00000119261, 5.79557487799, 26.2983197998, 0.00000072122, 1.13846158196, 529.6909650946, 0.00000067768, 1.87472304791, 398.1490034082, 0.00000067327, 4.40918235168, 5507.5532386674, 0.00000059027, 2.88797038460, 5223.6939198022, 0.00000055976, 2.17471680261, 155.4203994342, 0.00000045407, 0.39803079805, 796.2980068164, 0.00000036369, 0.46624739835, 775.5226113240, 0.00000028958, 2.64707383882, 7.1135470008, 0.00000019097, 1.84628332577, 5486.7778431750, 0.00000020844, 5.34138275149, 0.9803210682, 0.00000018508, 4.96855124577, 213.2990954380, 0.00000016233, 0.03216483047, 2544.3144198834, 0.00000017293, 2.99116864949, 6275.9623029906} --黄经泊松2项 local E12={0.00052918870, 0.00000000000, 0.0000000000, 0.00008719837, 1.07209665242, 6283.0758499914, 0.00000309125, 0.86728818832, 12566.1516999828, 0.00000027339, 0.05297871691, 3.5231183490, 0.00000016334, 5.18826691036, 26.2983197998, 0.00000015752, 3.68457889430, 155.4203994342, 0.00000009541, 0.75742297675, 18849.2275499742, 0.00000008937, 2.05705419118, 77713.7714681205, 0.00000006952, 0.82673305410, 775.5226113240, 0.00000005064, 4.66284525271, 1577.3435424478} local E13={0.00000289226, 5.84384198723, 6283.0758499914, 0.00000034955, 0.00000000000, 0.0000000000, 0.00000016819, 5.48766912348, 12566.1516999828} local E14={0.00000114084, 3.14159265359, 0.0000000000, 0.00000007717, 4.13446589358, 6283.0758499914, 0.00000000765, 3.83803776214, 12566.1516999828} local E15={0.00000000878, 3.14159265359, 0.0000000000 } --黄纬周期项 local E20={0.00000279620, 3.19870156017, 84334.6615813083, 0.00000101643, 5.42248619256, 5507.5532386674, 0.00000080445, 3.88013204458, 5223.6939198022, 0.00000043806, 3.70444689758, 2352.8661537718, 0.00000031933, 4.00026369781, 1577.3435424478, 0.00000022724, 3.98473831560, 1047.7473117547, 0.00000016392, 3.56456119782, 5856.4776591154, 0.00000018141, 4.98367470263, 6283.0758499914, 0.00000014443, 3.70275614914, 9437.7629348870, 0.00000014304, 3.41117857525, 10213.2855462110} local E21={0.00000009030, 3.89729061890, 5507.5532386674, 0.00000006177, 1.73038850355, 5223.6939198022} --距离周期项 local E30={1.00013988799, 0.00000000000, 0.0000000000, 0.01670699626, 3.09846350771, 6283.0758499914, 0.00013956023, 3.05524609620, 12566.1516999828, 0.00003083720, 5.19846674381, 77713.7714681205, 0.00001628461, 1.17387749012, 5753.3848848968, 0.00001575568, 2.84685245825, 7860.4193924392, 0.00000924799, 5.45292234084, 11506.7697697936, 0.00000542444, 4.56409149777, 3930.2096962196} local E31={0.00103018608, 1.10748969588, 6283.0758499914, 0.00001721238, 1.06442301418, 12566.1516999828, 0.00000702215, 3.14159265359, 0.0000000000} local E32={0.00004359385, 5.78455133738, 6283.0758499914 } local E33={0.00000144595, 4.27319435148, 6283.0758499914 } --月球运动参数 local M10={22639.5858800, 2.3555545723, 8328.6914247251, 1.5231275E-04, 2.5041111E-07,-1.1863391E-09, 4586.4383203, 8.0413790709, 7214.0628654588,-2.1850087E-04,-1.8646419E-07, 8.7760973E-10, 2369.9139357, 10.3969336431, 15542.7542901840,-6.6188121E-05, 6.3946925E-08,-3.0872935E-10, 769.0257187, 4.7111091445, 16657.3828494503, 3.0462550E-04, 5.0082223E-07,-2.3726782E-09, -666.4175399, -0.0431256817, 628.3019552485,-2.6638815E-06, 6.1639211E-10,-5.4439728E-11, -411.5957339, 3.2558104895, 16866.9323152810,-1.2804259E-04,-9.8998954E-09, 4.0433461E-11, 211.6555524, 5.6858244986, -1114.6285592663,-3.7081362E-04,-4.3687530E-07, 2.0639488E-09, 205.4359530, 8.0845047526, 6585.7609102104,-2.1583699E-04,-1.8708058E-07, 9.3204945E-10, 191.9561973, 12.7524882154, 23871.4457149091, 8.6124629E-05, 3.1435804E-07,-1.4950684E-09, 164.7286185, 10.4400593249, 14914.4523349355,-6.3524240E-05, 6.3330532E-08,-2.5428962E-10, -147.3213842, -2.3986802540, -7700.3894694766,-1.5497663E-04,-2.4979472E-07, 1.1318993E-09, -124.9881185, 5.1984668216, 7771.3771450920,-3.3094061E-05, 3.1973462E-08,-1.5436468E-10, -109.3803637, 2.3124288905, 8956.9933799736, 1.4964887E-04, 2.5102751E-07,-1.2407788E-09, 55.1770578, 7.1411231536, -1324.1780250970, 6.1854469E-05, 7.3846820E-08,-3.4916281E-10, -45.0996092, 5.6113650618, 25195.6237400061, 2.4270161E-05, 2.4051122E-07,-1.1459056E-09, 39.5333010, -0.9002559173, -8538.2408905558, 2.8035534E-04, 2.6031101E-07,-1.2267725E-09, 38.4298346, 18.4383127140, 22756.8171556428,-2.8468899E-04,-1.2251727E-07, 5.6888037E-10, 36.1238141, 7.0666637168, 24986.0742741754, 4.5693825E-04, 7.5123334E-07,-3.5590172E-09, 30.7725751, 16.0827581417, 14428.1257309177,-4.3700174E-04,-3.7292838E-07, 1.7552195E-09, -28.3971008, 7.9982533891, 7842.3648207073,-2.2116475E-04,-1.8584780E-07, 8.2317000E-10, -24.3582283, 10.3538079614, 16171.0562454324,-6.8852003E-05, 6.4563317E-08,-3.6316908E-10, -18.5847068, 2.8429122493, -557.3142796331,-1.8540681E-04,-2.1843765E-07, 1.0319744E-09, 17.9544674, 5.1553411398, 8399.6791003405,-3.5757942E-05, 3.2589854E-08,-2.0880440E-10, 14.5302779, 12.7956138971, 23243.1437596606, 8.8788511E-05, 3.1374165E-07,-1.4406287E-09, 14.3796974, 15.1080427876, 32200.1371396342, 2.3843738E-04, 5.6476915E-07,-2.6814075E-09, 14.2514576,-24.0810366320, -2.3011998397, 1.5231275E-04, 2.5041111E-07,-1.1863391E-09, 13.8990596, 20.7938672862, 31085.5085803679,-1.3237624E-04, 1.2789385E-07,-6.1745870E-10, 13.1940636, 3.3302699264, -9443.3199839914,-5.2312637E-04,-6.8728642E-07, 3.2502879E-09, -9.6790568, -4.7542348263,-16029.0808942018,-3.0728938E-04,-5.0020584E-07, 2.3182384E-09, -9.3658635, 11.2971895604, 24080.9951807398,-3.4654346E-04,-1.9636409E-07, 9.1804319E-10, 8.6055318, 5.7289501804, -1742.9305145148,-3.6814974E-04,-4.3749170E-07, 2.1183885E-09, -8.4530982, 7.5540213938, 16100.0685698171, 1.1921869E-04, 2.8238458E-07,-1.3407038E-09, 8.0501724, 10.4831850066, 14286.1503796870,-6.0860358E-05, 6.2714140E-08,-1.9984990E-10, -7.6301553, 4.6679834628, 17285.6848046987, 3.0196162E-04, 5.0143862E-07,-2.4271179E-09, -7.4474952, -0.0862513635, 1256.6039104970,-5.3277630E-06, 1.2327842E-09,-1.0887946E-10, 7.3712011, 8.1276304344, 5957.4589549619,-2.1317311E-04,-1.8769697E-07, 9.8648918E-10, 7.0629900, 0.9591375719, 33.7570471374,-3.0829302E-05,-3.6967043E-08, 1.7385419E-10, -6.3831491, 9.4966777258, 7004.5133996281, 2.1416722E-04, 3.2425793E-07,-1.5355019E-09, -5.7416071, 13.6527441326, 32409.6866054649,-1.9423071E-04, 5.4047029E-08,-2.6829589E-10, 4.3740095, 18.4814383957, 22128.5152003943,-2.8202511E-04,-1.2313366E-07, 6.2332010E-10, -3.9976134, 7.9669196340, 33524.3151647312, 1.7658291E-04, 4.9092233E-07,-2.3322447E-09, -3.2096876, 13.2398458924, 14985.4400105508,-2.5159493E-04,-1.5449073E-07, 7.2324505E-10, -2.9145404, 12.7093625336, 24499.7476701576, 8.3460748E-05, 3.1497443E-07,-1.5495082E-09, 2.7318890, 16.1258838235, 13799.8237756692,-4.3433786E-04,-3.7354477E-07, 1.8096592E-09, -2.5679459, -2.4418059357, -7072.0875142282,-1.5764051E-04,-2.4917833E-07, 1.0774596E-09, -2.5211990, 7.9551277074, 8470.6667759558,-2.2382863E-04,-1.8523141E-07, 7.6873027E-10, 2.4888871, 5.6426988169, -486.3266040178,-3.7347750E-04,-4.3625891E-07, 2.0095091E-09, 2.1460741, 7.1842488353, -1952.4799803455, 6.4518350E-05, 7.3230428E-08,-2.9472308E-10, 1.9777270, 23.1494218585, 39414.2000050930, 1.9936508E-05, 3.7830496E-07,-1.8037978E-09, 1.9336825, 9.4222182890, 33314.7656989005, 6.0925100E-04, 1.0016445E-06,-4.7453563E-09, 1.8707647, 20.8369929680, 30457.2066251194,-1.2971236E-04, 1.2727746E-07,-5.6301898E-10, -1.7529659, 0.4873576771, -8886.0057043583,-3.3771956E-04,-4.6884877E-07, 2.2183135E-09, -1.4371624, 7.0979974718, -695.8760698485, 5.9190587E-05, 7.4463212E-08,-4.0360254E-10, -1.3725701, 1.4552986550, -209.5494658307, 4.3266809E-04, 5.1072212E-07,-2.4131116E-09, 1.2618162, 7.5108957121, 16728.3705250656, 1.1655481E-04, 2.8300097E-07,-1.3951435E-09} local M11={1.6768000, -0.0431256817, 628.3019552485,-2.6638815E-06, 6.1639211E-10,-5.4439728E-11, 0.5164200, 11.2260974062, 6585.7609102104,-2.1583699E-04,-1.8708058E-07, 9.3204945E-10, 0.4138300, 13.5816519784, 14914.4523349355,-6.3524240E-05, 6.3330532E-08,-2.5428962E-10, 0.3711500, 5.5402729076, 7700.3894694766, 1.5497663E-04, 2.4979472E-07,-1.1318993E-09, 0.2756000, 2.3124288905, 8956.9933799736, 1.4964887E-04, 2.5102751E-07,-1.2407788E-09, 0.2459863,-25.6198212459, -2.3011998397, 1.5231275E-04, 2.5041111E-07,-1.1863391E-09, 0.0711800, 7.9982533891, 7842.3648207073,-2.2116475E-04,-1.8584780E-07, 8.2317000E-10, 0.0612800, 10.3538079614, 16171.0562454324,-6.8852003E-05, 6.4563317E-08,-3.6316908E-10} local M12={0.0048700, -0.0431256817, 628.3019552485,-2.6638815E-06, 6.1639211E-10,-5.4439728E-11, 0.0022800,-27.1705318325, -2.3011998397, 1.5231275E-04, 2.5041111E-07,-1.1863391E-09, 0.0015000, 11.2260974062, 6585.7609102104,-2.1583699E-04,-1.8708058E-07, 9.3204945E-10} local M20={18461.2400600, 1.6279052448, 8433.4661576405,-6.4021295E-05,-4.9499477E-09, 2.0216731E-11, 1010.1671484, 3.9834598170, 16762.1575823656, 8.8291456E-05, 2.4546117E-07,-1.1661223E-09, 999.6936555, 0.7276493275, -104.7747329154, 2.1633405E-04, 2.5536106E-07,-1.2065558E-09, 623.6524746, 8.7690283983, 7109.2881325435,-2.1668263E-06, 6.8896872E-08,-3.2894608E-10, 199.4837596, 9.6692843156, 15647.5290230993,-2.8252217E-04,-1.9141414E-07, 8.9782646E-10, 166.5741153, 6.4134738261, -1219.4032921817,-1.5447958E-04,-1.8151424E-07, 8.5739300E-10, 117.2606951, 12.0248388879, 23976.2204478244,-1.3020942E-04, 5.8996977E-08,-2.8851262E-10, 61.9119504, 6.3390143893, 25090.8490070907, 2.4060421E-04, 4.9587228E-07,-2.3524614E-09, 33.3572027, 11.1245829706, 15437.9795572686, 1.5014592E-04, 3.1930799E-07,-1.5152852E-09, 31.7596709, 3.0832038997, 8223.9166918098, 3.6864680E-04, 5.0577218E-07,-2.3928949E-09, 29.5766003, 8.8121540801, 6480.9861772950, 4.9705523E-07, 6.8280480E-08,-2.7450635E-10, 15.5662654, 4.0579192538, -9548.0947169068,-3.0679233E-04,-4.3192536E-07, 2.0437321E-09, 15.1215543, 14.3803934601, 32304.9118725496, 2.2103334E-05, 3.0940809E-07,-1.4748517E-09, -12.0941511, 8.7259027166, 7737.5900877920,-4.8307078E-06, 6.9513264E-08,-3.8338581E-10, 8.8681426, 9.7124099974, 15019.2270678508,-2.7985829E-04,-1.9203053E-07, 9.5226618E-10, 8.0450400, 0.6687636586, 8399.7091105030,-3.3191993E-05, 3.2017096E-08,-1.5363746E-10, 7.9585542, 12.0679645696, 23347.9184925760,-1.2754553E-04, 5.8380585E-08,-2.3407289E-10, 7.4345550, 6.4565995078, -1847.7052474301,-1.5181570E-04,-1.8213063E-07, 9.1183272E-10, -6.7314363, -4.0265854988,-16133.8556271171,-9.0955337E-05,-2.4484477E-07, 1.1116826E-09, 6.5795750, 16.8104074692, 14323.3509980023,-2.2066770E-04,-1.1756732E-07, 5.4866364E-10, -6.4600721, 1.5847795630, 9061.7681128890,-6.6685176E-05,-4.3335556E-09,-3.4222998E-11, -6.2964773, 4.8837157343, 25300.3984729215,-1.9206388E-04,-1.4849843E-08, 6.0650192E-11, -5.6323538, -0.7707750092, 733.0766881638,-2.1899793E-04,-2.5474467E-07, 1.1521161E-09, -5.3683961, 6.8263720663, 16204.8433027325,-9.7115356E-05, 2.7023515E-08,-1.3414795E-10, -5.3112784, 3.9403341353, 17390.4595376141, 8.5627574E-05, 2.4607756E-07,-1.2205621E-09, -5.0759179, 0.6845236457, 523.5272223331, 2.1367016E-04, 2.5597745E-07,-1.2609955E-09, -4.8396143, -1.6710309265, -7805.1642023920, 6.1357413E-05, 5.5663398E-09,-7.4656459E-11, -4.8057401, 3.5705615768, -662.0890125485, 3.0927234E-05, 3.6923410E-08,-1.7458141E-10, 3.9840545, 8.6945689615, 33419.5404318159, 3.9291696E-04, 7.4628340E-07,-3.5388005E-09, 3.6744619, 19.1659620415, 22652.0424227274,-6.8354947E-05, 1.3284380E-07,-6.3767543E-10, 2.9984815, 20.0662179587, 31190.2833132833,-3.4871029E-04,-1.2746721E-07, 5.8909710E-10, 2.7986413, -2.5281611620,-16971.7070481963, 3.4437664E-04, 2.6526096E-07,-1.2469893E-09, 2.4138774, 17.7106633865, 22861.5918885581,-5.0102304E-04,-3.7787833E-07, 1.7754362E-09, 2.1863132, 5.5132179088, -9757.6441827375, 1.2587576E-04, 7.8796768E-08,-3.6937954E-10, 2.1461692, 13.4801375428, 23766.6709819937, 3.0245868E-04, 5.6971910E-07,-2.7016242E-09, 1.7659832, 11.1677086523, 14809.6776020201, 1.5280981E-04, 3.1869159E-07,-1.4608454E-09, -1.6244212, 7.3137297434, 7318.8375983742,-4.3483492E-04,-4.4182525E-07, 2.0841655E-09, 1.5813036, 5.4387584720, 16552.6081165349, 5.2095955E-04, 7.5618329E-07,-3.5792340E-09, 1.5197528, 16.7359480324, 40633.6032972747, 1.7441609E-04, 5.5981921E-07,-2.6611908E-09, 1.5156341, 1.7023646816,-17876.7861416319,-4.5910508E-04,-6.8233647E-07, 3.2300712E-09, 1.5102092, 5.4977296450, 8399.6847301375,-3.3094061E-05, 3.1973462E-08,-1.5436468E-10, -1.3178223, 9.6261586339, 16275.8309783478,-2.8518605E-04,-1.9079775E-07, 8.4338673E-10, -1.2642739, 11.9817132061, 24604.5224030729,-1.3287330E-04, 5.9613369E-08,-3.4295235E-10, 1.1918723, 22.4217725310, 39518.9747380084,-1.9639754E-04, 1.2294390E-07,-5.9724197E-10, 1.1346110, 14.4235191419, 31676.6099173011, 2.4767216E-05, 3.0879170E-07,-1.4204120E-09, 1.0857810, 8.8552797618, 5852.6842220465, 3.1609367E-06, 6.7664088E-08,-2.2006663E-10, -1.0193852, 7.2392703065, 33629.0898976466,-3.9751134E-05, 2.3556127E-07,-1.1256889E-09, -0.8227141, 11.0814572888, 16066.2815125171, 1.4748204E-04, 3.1992438E-07,-1.5697249E-09, 0.8042238, 3.5274358950, -33.7870573000, 2.8263353E-05, 3.7539802E-08,-2.2902113E-10, 0.8025939, 6.7832463846, 16833.1452579809,-9.9779237E-05, 2.7639907E-08,-1.8858767E-10, -0.7931866, -6.3821400710,-24462.5470518423,-2.4326809E-04,-4.9525589E-07, 2.2980217E-09, -0.7910153, 6.3703481443, -591.1013369332,-1.5714346E-04,-1.8089785E-07, 8.0295327E-10, -0.6674056, 9.1819266386, 24533.5347274576, 5.5197395E-05, 2.7743463E-07,-1.3204870E-09, 0.6502226, 4.1010449356,-10176.3966721553,-3.0412845E-04,-4.3254175E-07, 2.0981718E-09, -0.6388131, 6.2958887075, 25719.1509623392, 2.3794032E-04, 4.9648867E-07,-2.4069012E-09} local M21={0.0743000, 11.9537467337, 6480.9861772950, 4.9705523E-07, 6.8280480E-08,-2.7450635E-10, 0.0304300, 8.7259027166, 7737.5900877920,-4.8307078E-06, 6.9513264E-08,-3.8338581E-10, 0.0222900, 12.8540026510, 15019.2270678508,-2.7985829E-04,-1.9203053E-07, 9.5226618E-10, 0.0199900, 15.2095572232, 23347.9184925760,-1.2754553E-04, 5.8380585E-08,-2.3407289E-10, 0.0186900, 9.5981921614, -1847.7052474301,-1.5181570E-04,-1.8213063E-07, 9.1183272E-10, 0.0169600, 7.1681781524, 16133.8556271171, 9.0955337E-05, 2.4484477E-07,-1.1116826E-09, 0.0162300, 1.5847795630, 9061.7681128890,-6.6685176E-05,-4.3335556E-09,-3.4222998E-11, 0.0141900, -0.7707750092, 733.0766881638,-2.1899793E-04,-2.5474467E-07, 1.1521161E-09} local M30={385000.5290396, 1.5707963268, 0.0000000000, 0.0000000E+00, 0.0000000E+00, 0.0000000E+00,-20905.3551378, 3.9263508990, 8328.6914247251, 1.5231275E-04, 2.5041111E-07,-1.1863391E-09,-3699.1109330, 9.6121753977, 7214.0628654588,-2.1850087E-04,-1.8646419E-07, 8.7760973E-10,-2955.9675626, 11.9677299699, 15542.7542901840,-6.6188121E-05, 6.3946925E-08,-3.0872935E-10, -569.9251264, 6.2819054713, 16657.3828494503, 3.0462550E-04, 5.0082223E-07,-2.3726782E-09, 246.1584797, 7.2566208254, -1114.6285592663,-3.7081362E-04,-4.3687530E-07, 2.0639488E-09, -204.5861179, 12.0108556517, 14914.4523349355,-6.3524240E-05, 6.3330532E-08,-2.5428962E-10, -170.7330791, 14.3232845422, 23871.4457149091, 8.6124629E-05, 3.1435804E-07,-1.4950684E-09, -152.1378118, 9.6553010794, 6585.7609102104,-2.1583699E-04,-1.8708058E-07, 9.3204945E-10, -129.6202242, -0.8278839272, -7700.3894694766,-1.5497663E-04,-2.4979472E-07, 1.1318993E-09, 108.7427014, 6.7692631483, 7771.3771450920,-3.3094061E-05, 3.1973462E-08,-1.5436468E-10, 104.7552944, 3.8832252173, 8956.9933799736, 1.4964887E-04, 2.5102751E-07,-1.2407788E-09, 79.6605685, 0.6705404095, -8538.2408905558, 2.8035534E-04, 2.6031101E-07,-1.2267725E-09, 48.8883284, 1.5276706450, 628.3019552485,-2.6638815E-06, 6.1639211E-10,-5.4439728E-11, -34.7825237, 20.0091090408, 22756.8171556428,-2.8468899E-04,-1.2251727E-07, 5.6888037E-10, 30.8238599, 11.9246042882, 16171.0562454324,-6.8852003E-05, 6.4563317E-08,-3.6316908E-10, 24.2084985, 9.5690497159, 7842.3648207073,-2.2116475E-04,-1.8584780E-07, 8.2317000E-10, -23.2104305, 8.6374600436, 24986.0742741754, 4.5693825E-04, 7.5123334E-07,-3.5590172E-09, -21.6363439, 17.6535544685, 14428.1257309177,-4.3700174E-04,-3.7292838E-07, 1.7552195E-09, -16.6747239, 6.7261374666, 8399.6791003405,-3.5757942E-05, 3.2589854E-08,-2.0880440E-10, 14.4026890, 4.9010662531, -9443.3199839914,-5.2312637E-04,-6.8728642E-07, 3.2502879E-09, -12.8314035, 14.3664102239, 23243.1437596606, 8.8788511E-05, 3.1374165E-07,-1.4406287E-09, -11.6499478, 22.3646636130, 31085.5085803679,-1.3237624E-04, 1.2789385E-07,-6.1745870E-10, -10.4447578, 16.6788391144, 32200.1371396342, 2.3843738E-04, 5.6476915E-07,-2.6814075E-09, 10.3211071, 8.7119194804, -1324.1780250970, 6.1854469E-05, 7.3846820E-08,-3.4916281E-10, 10.0562033, 7.2997465071, -1742.9305145148,-3.6814974E-04,-4.3749170E-07, 2.1183885E-09, -9.8844667, 12.0539813334, 14286.1503796870,-6.0860358E-05, 6.2714140E-08,-1.9984990E-10, 8.7515625, 6.3563649081, -9652.8694498221,-9.0458282E-05,-1.7656429E-07, 8.3717626E-10, -8.3791067, 4.4137085761, -557.3142796331,-1.8540681E-04,-2.1843765E-07, 1.0319744E-09, -7.0026961, -3.1834384995,-16029.0808942018,-3.0728938E-04,-5.0020584E-07, 2.3182384E-09, 6.3220032, 9.1248177206, 16100.0685698171, 1.1921869E-04, 2.8238458E-07,-1.3407038E-09, 5.7508579, 6.2387797896, 17285.6848046987, 3.0196162E-04, 5.0143862E-07,-2.4271179E-09, -4.9501349, 9.6984267611, 5957.4589549619,-2.1317311E-04,-1.8769697E-07, 9.8648918E-10, -4.4211770, 3.0260949818, -209.5494658307, 4.3266809E-04, 5.1072212E-07,-2.4131116E-09, 4.1311145, 11.0674740526, 7004.5133996281, 2.1416722E-04, 3.2425793E-07,-1.5355019E-09, -3.9579827, 20.0522347225, 22128.5152003943,-2.8202511E-04,-1.2313366E-07, 6.2332010E-10, 3.2582371, 14.8106422192, 14985.4400105508,-2.5159493E-04,-1.5449073E-07, 7.2324505E-10, -3.1483020, 4.8266068163, 16866.9323152810,-1.2804259E-04,-9.8998954E-09, 4.0433461E-11, 2.6164092, 14.2801588604, 24499.7476701576, 8.3460748E-05, 3.1497443E-07,-1.5495082E-09, 2.3536310, 9.5259240342, 8470.6667759558,-2.2382863E-04,-1.8523141E-07, 7.6873027E-10, -2.1171283, -0.8710096090, -7072.0875142282,-1.5764051E-04,-2.4917833E-07, 1.0774596E-09, -1.8970368, 17.6966801503, 13799.8237756692,-4.3433786E-04,-3.7354477E-07, 1.8096592E-09, -1.7385258, 2.0581540038, -8886.0057043583,-3.3771956E-04,-4.6884877E-07, 2.2183135E-09, -1.5713944, 22.4077892948, 30457.2066251194,-1.2971236E-04, 1.2727746E-07,-5.6301898E-10, -1.4225541, 24.7202181853, 39414.2000050930, 1.9936508E-05, 3.7830496E-07,-1.8037978E-09, -1.4189284, 17.1661967915, 23314.1314352759,-9.9282182E-05, 9.5920387E-08,-4.6309403E-10, 1.1655364, 3.8400995356, 9585.2953352221, 1.4698499E-04, 2.5164390E-07,-1.2952185E-09, -1.1169371, 10.9930146158, 33314.7656989005, 6.0925100E-04, 1.0016445E-06,-4.7453563E-09, 1.0656723, 1.4845449633, 1256.6039104970,-5.3277630E-06, 1.2327842E-09,-1.0887946E-10, 1.0586190, 11.9220903668, 8364.7398411275,-2.1850087E-04,-1.8646419E-07, 8.7760973E-10, -0.9333176, 9.0816920389, 16728.3705250656, 1.1655481E-04, 2.8300097E-07,-1.3951435E-09, 0.8624328, 12.4550876470, 6656.7485858257,-4.0390768E-04,-4.0490184E-07, 1.9095841E-09, 0.8512404, 4.3705828944, 70.9876756153,-1.8807069E-04,-2.1782126E-07, 9.7753467E-10, -0.8488018, 16.7219647962, 31571.8351843857, 2.4110126E-04, 5.6415276E-07,-2.6269678E-09, -0.7956264, 3.5134526588, -9095.5551701890, 9.4948529E-05, 4.1873358E-08,-1.9479814E-10} local M31={0.5139500, 12.0108556517, 14914.4523349355,-6.3524240E-05, 6.3330532E-08,-2.5428962E-10, 0.3824500, 9.6553010794, 6585.7609102104,-2.1583699E-04,-1.8708058E-07, 9.3204945E-10, 0.3265400, 3.9694765808, 7700.3894694766, 1.5497663E-04, 2.4979472E-07,-1.1318993E-09, 0.2639600, 0.7416325637, 8956.9933799736, 1.4964887E-04, 2.5102751E-07,-1.2407788E-09, 0.1230200, -1.6139220085, 628.3019552485,-2.6638815E-06, 6.1639211E-10,-5.4439728E-11, 0.0775400, 8.7830116346, 16171.0562454324,-6.8852003E-05, 6.4563317E-08,-3.6316908E-10, 0.0606800, 6.4274570623, 7842.3648207073,-2.2116475E-04,-1.8584780E-07, 8.2317000E-10, 0.0497000, 12.0539813334, 14286.1503796870,-6.0860358E-05, 6.2714140E-08,-1.9984990E-10} --月球平黄经系数 local M1n={3.81034392032, 8.39968473021E+03,-3.31919929753E-05,3.20170955005E-08,-1.53637455544E-10 } --==================日位置计算=================== --调用Enn前先设置EnnT时间变量 local EnnT=0 --计算E10,E11,E20等,即:某一组周期项或泊松项算出,计算前先设置EnnT时间 local function Enn(F) local i local v=0 for i=1,#F,3 do v=v+F[i]*math.cos(F[i+1]+EnnT*F[i+2]) --print('Fsize='..#F, 'i='..i, 'v='..v, 'F[i]='..F[i], 'm='..math.cos(F[i+1]+EnnT*F[i+2])) end return v end --返回地球位置,日心Date黄道分点坐标 local function earCal(jd) EnnT=jd/365250 --print('EnnT='..EnnT) local llr={} local t1=EnnT local t2=t1*t1 local t3=t2*t1 local t4=t3*t1 local t5=t4*t1 --print('t1='..t1, 't2='..t2, 't3='..t3, 't4='..t4, 't5='..t5) llr[1] =Enn(E10) +Enn(E11)*t1 +Enn(E12)*t2 +Enn(E13)*t3 +Enn(E14)*t4 +Enn(E15)*t5 --print('sppp') llr[2] =Enn(E20) +Enn(E21)*t1 --print('eppp') llr[3] =Enn(E30) +Enn(E31)*t1 +Enn(E32)*t2 +Enn(E33)*t3 llr[1]=rad2mrad(llr[1]) --print('llr[0]='..llr[1], 'llr[1]='..llr[2], 'llr[2]='..llr[3]) return llr end --传回jd时刻太阳的地心视黄经及黄纬 local function sunCal2(jd) --计算太阳真位置 local sun=earCal(jd) sun[1]=sun[1] + math.pi sun[2]=-sun[2] local d=nutation(jd) --补章动 sun[1]=rad2mrad(sun[1]+d.Lon) --补周年黄经光行差 addGxc(jd,sun) --返回太阳视位置 return sun end --==================月位置计算=================== --调用Mnn前先设置MnnT时间变量 local MnnT=0 --计算M10,M11,M20等,计算前先设置MnnT时间 local function Mnn(F) local i local v=0 local t1=MnnT local t2=t1*t1 local t3=t2*t1 local t4=t3*t1 for i=1,#F,6 do v=v+F[i]*math.sin(F[i+1] +t1*F[i+2] +t2*F[i+3] +t3*F[i+4] +t4*F[i+5]) end return v end --返回月球位置,返回地心Date黄道坐标 local function moonCal(jd) MnnT=jd/36525 local t1=MnnT local t2=t1*t1 local t3=t2*t1 local t4=t3*t1 local llr={} llr[1] =(Mnn(M10) +Mnn(M11)*t1 +Mnn(M12)*t2)/rad llr[2] =(Mnn(M20) +Mnn(M21)*t1)/rad llr[3] =(Mnn(M30) +Mnn(M31)*t1)*0.999999949827 llr[1] =llr[1] +M1n[1] +M1n[2]*t1 +M1n[3]*t2 +M1n[4]*t3 +M1n[5]*t4 --地心Date黄道原点坐标(不含岁差) llr[1] =rad2mrad(llr[1]) --补岁差 addPrece(jd,llr) return llr end --传回月球的地心视黄经及视黄纬 local function moonCal2(jd) local moon=moonCal(jd) local d=nutation(jd) --补章动 moon[1]=rad2mrad(moon[1]+d.Lon) return moon end --传回月球的地心视赤经及视赤纬 local function moonCal3(jd) local moon=moonCal(jd) HCconv(moon,hcjj1(jd)) --补赤经及赤纬章动 nutationRaDec(jd,moon) --如果黄赤转换前补了黄经章动及交章动,就不能再补赤经赤纬章动 return moon end --==================地心坐标中的日月位置计算=================== local function jiaoCai(lx,t,jiao) --lx=1时计算t时刻日月角距与jiao的差, lx=0计算t时刻太阳黄经与jiao的差 --计算太阳真位置(先算出日心坐标中地球的位置) local sun=earCal(t) --转为地心坐标 sun[1]=sun[1] + math.pi sun[2]=-sun[2] --补周年光行差 addGxc(t,sun) --print('sun[1]='..sun[1], 'sun[2]='..sun[2]) if lx==0 then --补黄经章动 local d=nutation(t) sun[1]=sun[1] + d.Lon return rad2mrad(jiao-sun[1]) else --日月角差与章动无关 local moon=moonCal(t) return rad2mrad(jiao-(moon[1]-sun[1])) end end --==================已知位置反求时间=================== local function jiaoCal(t1,jiao,lx) --t1是J2000起算儒略日数 --已知角度(jiao)求时间(t) --lx=0是太阳黄经达某角度的时刻计算(用于节气计算) --lx=1是日月角距达某角度的时刻计算(用于定朔望等) --传入的t1是指定角度对应真时刻t的前一些天 --对于节气计算,应满足t在t1到t1+360天之间,对于Y年第n个节气(n=0是春分),t1可取值Y*365.2422+n*15.2 --对于朔望计算,应满足t在t1到t1+25天之间,在此范围之外,求右边的根 local t2=t1 local t=0 local v if lx==0 then --在t1到t2范围内求解(范气360天范围),结果置于t t2=t2+360 else t2=t2+25 end --待搜索目标角 jiao=jiao*math.pi/180 --利用截弦法计算 --v1,v2为t1,t2时对应的黄经 local v1=jiaoCai(lx,t1,jiao) local v2=jiaoCai(lx,t2,jiao) if v1<v2 then --减2pi作用是将周期性角度转为连续角度 v2=v2 - 2*math.pi end --k是截弦的斜率 local k=1 local k2 local i --快速截弦求根,通常截弦三四次就已达所需精度 for i=1,10 do --算出斜率 k2=(v2-v1)/(t2-t1) if math.abs(k2)>1e-15 then --差商可能为零,应排除 k=k2 end --直线逼近法求根(直线方程的根) t=t1-v1/k v=jiaoCai(lx,t,jiao) --一次逼近后,v1就已接近0,如果很大,则应减1周 if v>1 then v=v-2*math.pi end if math.abs(v)<1e-8 then --已达精度 break end --下一次截弦 t1=t2 v1=v2 t2=t v2=v end return t end --==================节气计算=================== --返回一年中各个节气的时间表,从春分开始,y是阳历的年分/北京时 local function jqFromChunFen(y) local i local jd=365.2422*(y-2000) local q local jq = {} for i=0,23 do --计算第i个节气(i=0是春分),结果转为北京时 q=jiaoCal(jd+i*15.2,i*15,0)+J2000+8/24 --将节气时转成世界时 JDate:setFromJD(q,1) jq[i+1] = JDate:JQ() end return jq end --返回一年的二十四个节气,从立春开始,y是阳历的年分/北京时 local function jqFromLiChun(y) --上一年 local jq1 = jqFromChunFen(y-1) -- 当年 local jq2 = jqFromChunFen(y) local jq = {} for i=1,3 do jq[i] = jq1[i+21] end for i=1,21 do jq[i+3] = jq2[i] end return jq end --==================节气暂存,用于快速查询=================== --初始化当前年份前后三年内的节气数据 local function jq3Y_Build() --取日期:20230508 local date_YYYYMMDD = os.date("%Y%m%d") --取年: 2023 local date_y=os.date("%Y") --取月: 05 local date_m=os.date("%m") --取日: 08 local date_d=os.date("%d") local jq_lastYear = jqFromChunFen(date_y-1) local jq_thisYear = jqFromChunFen(date_y) local jq_nextYear = jqFromChunFen(date_y+1) local i for i=1,24 do jq3Y[i] = jq_lastYear[i] jqN3Y[i] = jqB[i] end for i=1,24 do jq3Y[24+i] = jq_thisYear[i] jqN3Y[24+i] = jqB[i] end for i=1,24 do jq3Y[48+i] = jq_nextYear[i] jqN3Y[48+i] = jqB[i] end end -- 以 jbB 为 base,创建jqIdx查询字典,用于快速查询某一给定的节气在jqB中的索引位置 local jqIdxDic={} local function jqIdxBuild() local idx for idx=1,#jqB do jqIdxDic[jqB[idx]] = idx end end --根据指定的时间基准,获取此时间之后的jq信息,返回两个table:timeList, nameList local function jqComming(t) local timeList = {} local nameList = {} t = t or os.time() local tBase = os.time() if type(t) == type(tBase) then tBase = t end tBase = os.time() local tBaseStruct = os.date('!*t',tBase) if tBase>43200 then --校准tBase到00:00:00 tBase = os.time({year=tBaseStruct.year,month=tBaseStruct.month,day=tBaseStruct.day,hour=0}) end local idx for idx=1,#jq3Y do if jq3Y[idx]>=tBase then table.insert(timeList,jq3Y[idx]) table.insert(nameList,jqN3Y[idx]) end end return timeList,nameList end --获取给定的节气名称在 jbB中的索引位置,这个主要用于查询某个关键字是否是一个节气名称 local function jqIdxByName(jqName) return jqIdxDic[jqName] or 0 end --根据给定的一个时间戳,查询这天是否存在节气 local function jqInfoByTime(t) t = t or os.time() local thisDay = os.date("%Y%m%d",t) local idx = 1 for idx=1,#jq3Y do if thisDay == os.date("%Y%m%d",jq3Y[idx]) then return jq3Y[idx],jqN3Y[idx] end end return 0,'' end --这个函数将建立节气列表,用于节气信息的查询 local function jqListBuild() jq3Y_Build() jqIdxBuild() end local function test(printPrefix) if nil == printPrefix then printPrefix = '' end --调用引用模块的 test 方法 --开始本模块的 test 方法 print(printPrefix..'test in lunarJieQiModule start') end --=========================模块化封装========================= local M={} function M.init(...) --抛出功能函数 M.jqListBuild = jqListBuild M.jqFromChunFen = jqFromChunFen M.jqComming = jqComming M.jqIdxByName = jqIdxByName M.jqInfoByTime = jqInfoByTime M.setDbg = setDbg M.test = test end M.init() return M
lunarModule.lua
--此处获取农历的代码来自博客 --https://blog.csdn.net/BlueMustard/article/details/120907984 local dbgFlg = false --引入24节气计算模块 local ok, jq = pcall(require, 'lunarjieQiModule') local function setDbg(flg,printPrefix) dbgFlg = flg if nil == printPrefix then printPrefix = '' end --设置引用子模块的 dbgFlg jq.setDbg(flg,' '..printPrefix) if flg then print(printPrefix..'flg in lunarJieQiModule is true') end end --天干名称 local tianGan = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"} --地支名称 local diZhi = {"子","丑","寅","卯","辰","巳","午", "未","申","酉","戌","亥"} --属相名称 local shengXiao = {"鼠","牛","虎","兔","龙","蛇", "马","羊","猴","鸡","狗","猪"} --农历日期名 local lunarDayShuXu = {"初一","初二","初三","初四","初五","初六","初七","初八","初九","初十", "十一","十二","十三","十四","十五","十六","十七","十八","十九","二十", "廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"} --农历月份名 local lunarMonthShuXu = {"正","二","三","四","五","六", "七","八","九","十","冬","腊"} local daysToMonth365= {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334} local daysToMonth366= {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335} --每个农历月所属的季节名称和季节符号表 local jiJieNames = {'春','春','春','夏','夏','夏','秋','秋','秋','冬','冬','冬'} local jiJieLogos = {'','','','','','','','','','','',''} --[[dateLunarInfo说明: 自1901年起,至2100年每年的农历信息,与万年历核对完成 每年第1个数字为闰月月份 每年第2、3个数字为当年春节所在的阳历月份和日期 每年第4个数字为当年中对应月分的大小进,左边起为1月,往后依次为2月,3月,4月,。。。]] local BEGIN_YEAR = 1901 local NUMBER_YEAR = 199 local dateLunarInfo= {{0, 2, 19, 19168}, {0, 2, 8, 42352}, {5, 1, 29, 21096}, {0, 2, 16, 53856}, {0, 2, 4, 55632}, {4, 1, 25, 27304}, {0, 2, 13, 22176}, {0, 2, 2, 39632}, {2, 1, 22, 19176}, {0, 2, 10, 19168}, {6, 1, 30, 42200}, {0, 2, 18, 42192}, {0, 2, 6, 53840}, {5, 1, 26, 54568}, {0, 2, 14, 46400}, {0, 2, 3, 54944}, {2, 1, 23, 38608}, {0, 2, 11, 38320}, {7, 2, 1, 18872}, {0, 2, 20, 18800}, {0, 2, 8, 42160}, {5, 1, 28, 45656}, {0, 2, 16, 27216}, {0, 2, 5, 27968}, {4, 1, 24, 44456}, {0, 2, 13, 11104}, {0, 2, 2, 38256}, {2, 1, 23, 18808}, {0, 2, 10, 18800}, {6, 1, 30, 25776}, {0, 2, 17, 54432}, {0, 2, 6, 59984}, {5, 1, 26, 27976}, {0, 2, 14, 23248}, {0, 2, 4, 11104}, {3, 1, 24, 37744}, {0, 2, 11, 37600}, {7, 1, 31, 51560}, {0, 2, 19, 51536}, {0, 2, 8, 54432}, {6, 1, 27, 55888}, {0, 2, 15, 46416}, {0, 2, 5, 22176}, {4, 1, 25, 43736}, {0, 2, 13, 9680}, {0, 2, 2, 37584}, {2, 1, 22, 51544}, {0, 2, 10, 43344}, {7, 1, 29, 46248}, {0, 2, 17, 27808}, {0, 2, 6, 46416}, {5, 1, 27, 21928}, {0, 2, 14, 19872}, {0, 2, 3, 42416}, {3, 1, 24, 21176}, {0, 2, 12, 21168}, {8, 1, 31, 43344}, {0, 2, 18, 59728}, {0, 2, 8, 27296}, {6, 1, 28, 44368}, {0, 2, 15, 43856}, {0, 2, 5, 19296}, {4, 1, 25, 42352}, {0, 2, 13, 42352}, {0, 2, 2, 21088}, {3, 1, 21, 59696}, {0, 2, 9, 55632}, {7, 1, 30, 23208}, {0, 2, 17, 22176}, {0, 2, 6, 38608}, {5, 1, 27, 19176}, {0, 2, 15, 19152}, {0, 2, 3, 42192}, {4, 1, 23, 53864}, {0, 2, 11, 53840}, {8, 1, 31, 54568}, {0, 2, 18, 46400}, {0, 2, 7, 46752}, {6, 1, 28, 38608}, {0, 2, 16, 38320}, {0, 2, 5, 18864}, {4, 1, 25, 42168}, {0, 2, 13, 42160}, {10, 2, 2, 45656}, {0, 2, 20, 27216}, {0, 2, 9, 27968}, {6, 1, 29, 44448}, {0, 2, 17, 43872}, {0, 2, 6, 38256}, {5, 1, 27, 18808}, {0, 2, 15, 18800}, {0, 2, 4, 25776}, {3, 1, 23, 27216}, {0, 2, 10, 59984}, {8, 1, 31, 27432}, {0, 2, 19, 23232}, {0, 2, 7, 43872}, {5, 1, 28, 37736}, {0, 2, 16, 37600}, {0, 2, 5, 51552}, {4, 1, 24, 54440}, {0, 2, 12, 54432}, {0, 2, 1, 55888}, {2, 1, 22, 23208}, {0, 2, 9, 22176}, {7, 1, 29, 43736}, {0, 2, 18, 9680}, {0, 2, 7, 37584}, {5, 1, 26, 51544}, {0, 2, 14, 43344}, {0, 2, 3, 46240}, {4, 1, 23, 46416}, {0, 2, 10, 44368}, {9, 1, 31, 21928}, {0, 2, 19, 19360}, {0, 2, 8, 42416}, {6, 1, 28, 21176}, {0, 2, 16, 21168}, {0, 2, 5, 43312}, {4, 1, 25, 29864}, {0, 2, 12, 27296}, {0, 2, 1, 44368}, {2, 1, 22, 19880}, {0, 2, 10, 19296}, {6, 1, 29, 42352}, {0, 2, 17, 42208}, {0, 2, 6, 53856}, {5, 1, 26, 59696}, {0, 2, 13, 54576}, {0, 2, 3, 23200}, {3, 1, 23, 27472}, {0, 2, 11, 38608}, {11, 1, 31, 19176}, {0, 2, 19, 19152}, {0, 2, 8, 42192}, {6, 1, 28, 53848}, {0, 2, 15, 53840}, {0, 2, 4, 54560}, {5, 1, 24, 55968}, {0, 2, 12, 46496}, {0, 2, 1, 22224}, {2, 1, 22, 19160}, {0, 2, 10, 18864}, {7, 1, 30, 42168}, {0, 2, 17, 42160}, {0, 2, 6, 43600}, {5, 1, 26, 46376}, {0, 2, 14, 27936}, {0, 2, 2, 44448}, {3, 1, 23, 21936}, {0, 2, 11, 37744}, {8, 2, 1, 18808}, {0, 2, 19, 18800}, {0, 2, 8, 25776}, {6, 1, 28, 27216}, {0, 2, 15, 59984}, {0, 2, 4, 27424}, {4, 1, 24, 43872}, {0, 2, 12, 43744}, {0, 2, 2, 37600}, {3, 1, 21, 51568}, {0, 2, 9, 51552}, {7, 1, 29, 54440}, {0, 2, 17, 54432}, {0, 2, 5, 55888}, {5, 1, 26, 23208}, {0, 2, 14, 22176}, {0, 2, 3, 42704}, {4, 1, 23, 21224}, {0, 2, 11, 21200}, {8, 1, 31, 43352}, {0, 2, 19, 43344}, {0, 2, 7, 46240}, {6, 1, 27, 46416}, {0, 2, 15, 44368}, {0, 2, 5, 21920}, {4, 1, 24, 42448}, {0, 2, 12, 42416}, {0, 2, 2, 21168}, {3, 1, 22, 43320}, {0, 2, 9, 26928}, {7, 1, 29, 29336}, {0, 2, 17, 27296}, {0, 2, 6, 44368}, {5, 1, 26, 19880}, {0, 2, 14, 19296}, {0, 2, 3, 42352}, {4, 1, 24, 21104}, {0, 2, 10, 53856}, {8, 1, 30, 59696}, {0, 2, 18, 54560}, {0, 2, 7, 55968}, {6, 1, 27, 27472}, {0, 2, 15, 22224}, {0, 2, 5, 19168}, {4, 1, 25, 42216}, {0, 2, 12, 42192}, {0, 2, 1, 53584}, {2, 1, 21, 55592}, {0, 2, 9, 54560}} --将给定的十进制数转为二进制字符串 local function dec2Bin(num) local str = "" local tmp = num while (tmp > 0) do if (tmp % 2 == 1) then str = str.."1" else str = str.."0" end tmp = math.modf(tmp / 2) end str = string.reverse(str) return str end --将给定的两个十进制数转换为两个长度相等的二进制字符串 local function dec2BinWithSameLen(num1, num2) local str1 = dec2Bin(num1) local str2 = dec2Bin(num2) local len1 = string.len(str1) local len2 = string.len(str2) local len = 0 local x = 0 --长度较短的字符串前方补零 if (len1 > len2) then x = len1 - len2 for i = 1, x do str2 = "0"..str2 end len = len1 elseif (len2 > len1) then x = len2 - len1 for i = 1, x do str1 = "0"..str1 end len = len2 end len = len1 return str1, str2, len end --将给定的两个十进制数,进行按位与运算,返回算结果 local function bitAnd(num1, num2) local str1, str2, len = dec2BinWithSameLen(num1, num2) local rtmp = "" for i = 1, len do local st1 = tonumber(string.sub(str1, i, i)) local st2 = tonumber(string.sub(str2, i, i)) if(st1 == 0) then rtmp = rtmp.."0" else if (st2 ~= 0) then rtmp = rtmp.."1" else rtmp = rtmp.."0" end end end return tonumber(rtmp,2) end --判断所在年份是否为闰年 local function IsLeapYear(solarYear) if solarYear%4 ~= 0 then return 0 end if solarYear%100 ~= 0 then return 1 end if solarYear%400 == 0 then return 1 end return 0 end local function getYearInfo(lunarYear,index) if lunarYear < BEGIN_YEAR or lunarYear > BEGIN_YEAR + NUMBER_YEAR - 1 then return end return dateLunarInfo[lunarYear-1901+1][index] end --计算指定公历日期是这一年中的第几天 local function daysCntInSolar(solarYear,solarMonth,solarDay) local daysToMonth = daysToMonth365 if solarYear % 4 == 0 then if solarYear % 100 ~= 0 then daysToMonth = daysToMonth366 end if solarYear % 400 == 0 then daysToMonth = daysToMonth366 end end return daysToMonth[solarMonth] + solarDay end --[[根据指定的阳历日期,返回一个农历日期的结构体,结构如下: lunarDate.solarYear:对应的阳历日期年份 lunarDate.solarMonth:对应的阳历日期月份 lunarDate.solarDay:对应的阳历日期日期 lunarDate.solarDate_YYYYMMDD:对应的阳历日期 YYYYMMDD lunarDate.year:对应农历年份 lunarDate.month:对应农历月份 lunarDate.day:对应农历的日期 lunarDate.leap:是否为农历的闰年 lunarDate.year_shengXiao:用生肖表示的农历年份 lunarDate.year_ganZhi:用干支表示的农历年份 lunarDate.month_shuXu:农历月份的名称 lunarDate.month_ganZhi:用干支表示的农历月份 lunarDate.day_shuXu:农历日期的名称 lunarDate.day_ganZhi:用干支表示的农历日期 lunarDate.lunarDate_YYYYMMDD:以 YYYYMMDD 格式表示的农历日期 lunarDate.lunarDate_1:癸卯年四月十一 lunarDate.lunarDate_2:兔年四月十一 lunarDate.lunarDate_3:癸卯年四月丁亥日 lunarDate.lunarDate_4:癸卯(兔)年四月十一 lunarDate.jiJieName: 日期所属的季节名称 lunarDate.jiJieLogo:日期所属的季节的符号 ]] --阳历转阴历 local function solar2Lunar(solarYear,solarMonth,solarDay) local lunarDate = {} lunarDate.solarYear = solarYear lunarDate.solarMonth = solarMonth lunarDate.solarDay = solarDay lunarDate.solarDate='' lunarDate.solarDate_YYYYMMDD = '' lunarDate.year=solarYear lunarDate.month=0 lunarDate.day=0 lunarDate.leap=false lunarDate.year_shengXiao='' lunarDate.year_ganZhi='' lunarDate.month_shuXu='' lunarDate.month_ganZhi='' lunarDate.day_shuXu='' lunarDate.day_ganZhi='' lunarDate.lunarDate_YYYYMMDD='' lunarDate.lunarDate_1='' lunarDate.lunarDate_2='' lunarDate.lunarDate_3='' lunarDate.lunarDate_4='' lunarDate.jiJieName = '' lunarDate.jiJieLogo = '' --确定当前日期相对于2000年1月7日的天数,此日期是一个甲子记日的起点 local tBase = os.time({year=2000,month=1,day=7}) local tThisDay = os.time({year=math.min(solarYear,2037),month=solarMonth,day=solarDay}) lunarDate.daysToBase = math.floor((tThisDay-tBase)/86400) lunarDate.solarDate_YYYYMMDD = os.date("%Y%m%d",tThisDay) if lunarDate.solarYear <= BEGIN_YEAR or lunarDate.solarYear > BEGIN_YEAR + NUMBER_YEAR- 1 then return lunarDate end --春节的公历日期 local solarMontSpring = getYearInfo(lunarDate.year,2) local solarDaySpring = getYearInfo(lunarDate.year,3) --计算这天是公历年的第几天 local daysCntInSolarThisDate = daysCntInSolar(solarYear, solarMonth, solarDay) --计算春节是公历年的第几天 local daysCntInSolarSprint = daysCntInSolar(solarYear, solarMontSpring, solarDaySpring) --计算这天是农历年的第几天 local daysCntInLunarThisDate = daysCntInSolarThisDate - daysCntInSolarSprint + 1 if daysCntInLunarThisDate <= 0 then --如果 daysCntInLunarThisDate 为负,说明指定的日期在农历中位于上一年的年度内 lunarDate.year = lunarDate.year-1 if lunarDate.year <= BEGIN_YEAR then return lunar_date end --重新确定农历春节所在的公历日期 solarMontSpring = getYearInfo(lunarDate.year,2) solarDaySpring = getYearInfo(lunarDate.year,3) --重新计算上一年春节是第几天 daysCntInSolarSprint = daysCntInSolar(solarYear-1, solarMontSpring, solarDaySpring) --计算上一年共几天 local daysCntInSolarTotal = daysCntInSolar(solarYear-1, 12, 31) --上一年农历年的第几天 daysCntInLunarThisDate = daysCntInSolarThisDate + daysCntInSolarTotal - daysCntInSolarSprint + 1 end --开始计算月份 local lunarMonth = 1 local lunarDaysCntInMonth = 0 --dec 32768 =bin 1000000000000000,一个掩码 local bitMask = 32768 --大小月份的flg数据 local lunarMonth30Flg = getYearInfo(lunarDate.year,4) --从正月开始,每个月进行以下计算 while lunarMonth <= 13 do --计算这个月总共有多少天 if bitAnd(lunarMonth30Flg,bitMask) ~= 0 then lunarDaysCntInMonth = 30 else lunarDaysCntInMonth = 29 end --检查thisDate距离这个月初一的天数是否小于这个月的总天数 if daysCntInLunarThisDate <= lunarDaysCntInMonth then lunarDate.month = lunarMonth lunarDate.day = daysCntInLunarThisDate break else --如果剩余天数还大于这个月的天数,则继续往下个月算 daysCntInLunarThisDate = daysCntInLunarThisDate - lunarDaysCntInMonth lunarMonth = lunarMonth + 1 --掩码除2,相当于bit位向右移动一位 bitMask = bitMask/2 end end --闰月所在的月份 local leapMontInLunar = getYearInfo(lunarDate.year,1) --确定闰月信息 if leapMontInLunar > 0 and leapMontInLunar < lunarDate.month then --如果存在闰月,且闰在前面判断的月份前面,则农历月份需要减 1 处理 lunarDate.month = lunarDate.month - 1 if leapMontInLunar == lunarDate.month then --如果恰好闰在这个月,则把闰月标记位置 lunarDate.leap = true end end --合成农历的年月日格式:20240215 local tmpMonthStr = '0'..lunarDate.month tmpMonthStr = string.sub(tmpMonthStr,(#tmpMonthStr<3 and 1 or 2),(#tmpMonthStr<3 and 2 or 3)) local tmpDayStr = '0'..lunarDate.day tmpDayStr = string.sub(tmpDayStr,(#tmpDayStr<3 and 1 or 2),(#tmpDayStr<3 and 2 or 3)) lunarDate.lunarDate_YYYYMMDD = lunarDate.year..tmpMonthStr..tmpDayStr lunarDate.jiJieName = jiJieNames[lunarDate.month] lunarDate.jiJieLogo = jiJieLogos[lunarDate.month] --确定年份的生肖 lunarDate.year_shengXiao = shengXiao[(((lunarDate.year - 4) % 60) % 12) + 1] --确定年份的干支 lunarDate.year_ganZhi = tianGan[(((lunarDate.year - 4) % 60) % 10)+1]..diZhi[(((lunarDate.year - 4) % 60) % 12) + 1] --确定月份的数序 lunarDate.month_shuXu = (lunarDate.leap and '闰' or '')..lunarMonthShuXu[lunarDate.month] --确定月份的干支,暂不支持计算 lunarDate.month_ganZhi = '' --确定日期的数序 lunarDate.day_shuXu = lunarDayShuXu[lunarDate.day] --确定日期的干支 lunarDate.day_ganZhi = tianGan[(((lunarDate.daysToBase) % 60) % 10)+1]..diZhi[(((lunarDate.daysToBase) % 60) % 12) + 1] --提供国标第一类计年表示格式 lunarDate.lunarDate_1 = lunarDate.year_ganZhi..'年'..lunarDate.month_shuXu..'月'..lunarDate.day_shuXu --提供国标第二类计年表示格式 lunarDate.lunarDate_2 = lunarDate.year_shengXiao..'年'..lunarDate.month_shuXu..'月'..lunarDate.day_shuXu --提供国标第三类计年表示格式 lunarDate.lunarDate_3 = lunarDate.year_ganZhi..'年'..lunarDate.month_shuXu..'月'..lunarDate.day_ganZhi..'日' --提供非国标的第四类计年表示格式 lunarDate.lunarDate_4 = lunarDate.year_ganZhi..'('..lunarDate.year_shengXiao..')年'..lunarDate.month_shuXu..'月'..lunarDate.day_shuXu return lunarDate end --通过传入的阳历时间,返回一个阴历数据结构 local function solar2LunarByTime(t) local solarDate = os.date('*t',t) return solar2Lunar(solarDate.year,solarDate.month,solarDate.day) end --抛出 农历节气 信息,今年自今天起未来的 农历节气 信息 local function jqListComming(t) t = t or os.time() local timeBase = os.time() if type(t) == type(timeBase) then timeBase = t end local lunarList = {} local jqList = {} local timeList = {} --获取 timeBase开始的农历信息 local jqTimeList, jqNameList = jq.jqComming(timeBase) --整理未来的节气信息 local idx local thisY,thisM,thisD,thisYL local thisLunarDate local jqName local jqTime for idx=1,#jqTimeList do jqName = jqNameList[idx] jqTime = jqTimeList[idx] if jqName ~= jqToday then thisY = tonumber(os.date('%Y',jqTime)) thisM = tonumber(os.date('%m',jqTime)) thisD = tonumber(os.date('%d',jqTime)) thisLunarDate = solar2Lunar(thisY,thisM,thisD) table.insert(lunarList,thisLunarDate.lunarDate_4) table.insert(jqList,jqName) table.insert(timeList,jqTime) end end --输出 lunar 信息 return lunarList,jqList,timeList end --[[根据指定的节气名,整理并输出这个节气的信息,节气的信息是个如下的结构体 jqInfo.jqName:节气的名称 jqInfo.jqTimeList:节气的时间序列 jqInfo.lunarList:节气的农历日期序列 ]] local function jqInfoByName(jqN) local jqInfo = {} jqInfo.jqName = jqN or '' jqInfo.jqTimeList = {} jqInfo.lunarList = {} if '' == jqInfo.jqName then return jqInfo end --以 0 为参数,获取所有的节气信息 local jqTimeList, jqNameList = jq.jqComming(0) local idx = 0 for idx=1,#jqNameList do if jqNameList[idx] == jqInfo.jqName then table.insert(jqInfo.jqTimeList, jqTimeList[idx]) local thisLunarDate = solar2LunarByTime(jqTimeList[idx]) table.insert(jqInfo.lunarList, thisLunarDate.lunarDate_4) end end return jqInfo end --=========================这是测试函数======================= local function test(printPrefix) if nil == printPrefix then printPrefix = '' end --调用引用模块的 test 方法 res.test(' '..printPrefix) --开始本模块的 test 方法 print(printPrefix..'test in lunarModule start') local idx local lunarList,jqList,timeList = jqListComming() print(printPrefix..'idx\tlunar\t\t\t\tjqName\t\t\t\tdateYL') for idx=1,#lunarList do print(printPrefix..idx..'\t'..lunarList[idx]..'\t\t'..jqList[idx]..'\t\t'..os.date("%Y%m%d",timeList[idx])) end end --=========================模块化封装========================= local M={} function M.init(...) --抛出功能函数 M.jqListBuild = jq.jqListBuild M.jqIdxByName = jq.jqIdxByName M.jqInfoByTime = jq.jqInfoByTime M.jqListComming = jqListComming M.solar2LunarByTime = solar2LunarByTime M.jqInfoByName = jqInfoByName M.setDbg = setDbg M.test = test end M.init() return M
eventsList.txt
# 常备节日信息,这里一般维护周期性的,相对比较稳定的事件/节日信息,例如每年 or 每月都会发生的事件 [lunar][Y][M01]-1 春节 过年 (中国)除夕 [lunar][Y]0101 春节 过年 (中国)春节 [solar][Y]0101 元旦 (中国)元旦休3天 [solar][Y]0110 警察 (中国)警察节
第一列是时间定义,关于时间的定义格式暂不成熟,暂不多表
第二列是事件关键字,可以有多个关键字,多关键字以空格分隔,滤镜将会响应命中的关键字
第三列是事件内容,即将要显示在候选项comment区的内容
eventsListModule.lua
-- eventsListModule.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> local M={} local dbgFlg = false --按照公历日期建立的事件索引表 local eventsDicBySolarDates={} --按照关键字建立的事件索引表 local eventsDicListByKeyW={} --[[事件是一个结构体,每一个事件的结构如下: e.c1:文档第一列的内容 e.c2:文档第二列的内容,如果没有内容,此为空 e.c3:文档第三列的内容,如果没有内容,此为空 e.kWs:这是文档第二列的内容通过空格切分后的关键字列表 e.time:这是事件的时间值 e.solarDate:这是事件的日期:20230102 ]] --一个农历日期表,用于根据农历反查对应阳历时间,提高查询效率 local lunarDatesList = {} --引入系统变更处理模块 local ok, sysInfoRes = pcall(require, 'sysInfo') --引入农历计算模块 local ok, lunar = pcall(require, 'lunarModule') --引入日期时间计算模块 local ok, dt = pcall(require,'dateTimeModule') --设置 dbg 开关 local function setDbg(flg) flg = flg or dbgFlg dbgFlg = flg sysInfoRes.setDbg(flg) lunar.setDbg(flg) dt.setDbg(flg) print('eventsListModule dbgFlg is '..tostring(dbgFlg)) end --将这附串拆散成 table local function stringSplit(str,sp,sp1) sp=(type(sp)=="string") and sp or " " if 0==#sp then sp="([%z\1-\127\194-\244][\128-\191]*)" elseif 1==#sp then sp="[^"..(sp=="%" and "%%" or sp).."]*" else sp1=sp1 or "^" str=str:gsub(sp,sp1) sp="[^"..sp1.."]*" end local tab={} for v in str:gmatch(sp) do if ''~=v then table.insert(tab,v) end end return tab end --将一个日期字符串转换为时间值,'20230125' -> xxxxxx local function dateStr2Time(dateStr) dateStr = dateStr or '' if #dateStr ~= 8 then dateStr = os.date("%Y%m%d") end local year = tonumber(string.sub(dateStr,1,4)) local month = tonumber(string.sub(dateStr,5,6)) local day = tonumber(string.sub(dateStr,7,8)) return os.time({year=year,month=month,day=day}) end --根据指定的天数偏移量,建立农历日期序列表,以借后期快速查询农历对应的阳历日期 local function lunarDatesListBuild(preDays,posDays) if nil == preDays then preDays = 100 end if nil == posDays then posDays = 365 end preDays = math.max(preDays,1) posDays = math.max(posDays,1) local idx = 0 local todayTime = os.date("*t") local tmpLunar,tmpSolar,tmpTime --以昨天为base,计算前preDays日期内的日期序列 for idx = 1, preDays do tmpTime = os.time({year=todayTime.year,month=todayTime.month,day=todayTime.day - idx}) tmpSolar = os.date("%Y%m%d",tmpTime) tmpLunar = lunar.solar2LunarByTime(tmpTime) lunarDatesList[tmpLunar.lunarDate_YYYYMMDD..(tmpLunar.leap and '.1' or '.0')] = tmpSolar end --以今天为base,计算后posDays日期内的日期序列 for idx = 0, posDays do tmpTime = os.time({year=todayTime.year,month=todayTime.month,day=todayTime.day + idx}) tmpSolar = os.date("%Y%m%d",tmpTime) tmpLunar = lunar.solar2LunarByTime(tmpTime) lunarDatesList[tmpLunar.lunarDate_YYYYMMDD..(tmpLunar.leap and '.1' or '.0')] = tmpSolar end end --以指定时间为基准,计算并把该基准前 or 后指定周数的周序对应的时间值 local function timeOfWeekDayBaseOnTime0(t,wCnt,wCntType,wDay) t = t or os.time() local tBase = os.time() if type(t)==type(tBase) then tBase = t end wCnt = wCnt or 0 if 0==wCnt then wCnt = 1 end wCntType = wCntType or 'w' if 'w'~=wCntType and 'W'~=wCntType then wCntType = 'w' end wDay = wDay or 0 if wDay < 0 or wDay > 6 then wDay = 0 end local fakeSolarDateTime = tBase local fakeSolarDate_wDay = tonumber(os.date("%w",fakeSolarDateTime)) if wCnt > 0 then --找描点之后第 wCnt 周的位置 if fakeSolarDate_wDay <= wDay then fakeSolarDateTime=fakeSolarDateTime+(wDay-fakeSolarDate_wDay+7*(wCnt-1))*86400 if 'W'==wCntType and 0~=fakeSolarDate_wDay then --如果要求整周且初一不为周日,则需要额外加7天 fakeSolarDateTime = fakeSolarDateTime + 7*86400 end else fakeSolarDateTime=fakeSolarDateTime+(wDay-fakeSolarDate_wDay+7*wCnt)*86400 end else --找描点之前第 wCnt 周的位置 if fakeSolarDate_wDay <= wDay then fakeSolarDateTime = fakeSolarDateTime + (wDay-fakeSolarDate_wDay+7*wCnt)*86400 else fakeSolarDateTime = fakeSolarDateTime + (wDay-fakeSolarDate_wDay+7*(wCnt+1))*86400 if 'W'==wCntType and 0~=fakeSolarDate_wDay then --如果要求整周且初一不为周日,则需要额外减7天 fakeSolarDateTime = fakeSolarDateTime - 7*86400 end end end return fakeSolarDateTime end --[[对传入的锚点信息进行解码:[solar][Y]0315 函数返回一个锚点结构体,说明如下: anchor.desc:锚点的描述 anchor.lunarFlg:锚点是否 base农历 anchor.solarFlg:锚点是否 base公历 anchor.yearFlg:锚点是否以 年 为循环周期 anchor.monthFlg:锚点是否以 月 为循环周期 anchor.weekFlg:锚点是否以 周 为循环周期 anchor.dayFlg:锚点是否为指定日期事件 anchor.jqFlg:锚点是否 base节气 anchor.eventFlg:锚点是否 base事件 anchor.solarDatesList:锚点解析的事件日期序列 ]] local function anchorDecode(anchorStr) local anchor = {} anchor.desc = '' anchor.lunarFlg = false anchor.solarFlg = false anchor.yearFlg = false anchor.monthFlg = false anchor.weekFlg = false anchor.dayFlg = false anchor.jqFlg = false anchor.eventFlg = false anchor.solarDatesList = {} anchorStr = anchorStr or '' if '' == anchorStr then return anchor end anchor.desc = anchorStr --1.1解码公历指定日期的事件 do local solarDate = string.match(anchor.desc,"%[solar%]%[D%](%d%d%d%d%d%d%d%d)") if nil ~= solarDate then table.insert(anchor.solarDatesList,solarDate) anchor.solarFlg = true anchor.dayFlg = true return anchor end end --2.1/2解码农历指定日期的事件 do local lunarDate = string.match(anchor.desc,"%[lunar%]%[D%](%d%d%d%d%d%d%d%d)") if nil ~= lunarDate then local solarDateOfThisLunarDate if string.find(anchor.desc,lunarDate..'%.1') then --这是一个带有.1标记的农历日期 solarDateOfThisLunarDate = lunarDatesList[lunarDate..'.1'] else --这是一个没有.1标记的农历日期 solarDateOfThisLunarDate = lunarDatesList[lunarDate..'.0'] end if nil ~= solarDateOfThisLunarDate then table.insert(anchor.solarDatesList,solarDateOfThisLunarDate) anchor.lunarFlg = true anchor.dayFlg = true end return anchor end end --3.1/2/3解码周循环事件 do local weekDay = string.match(anchor.desc,"%[solar%]%[[Ww]%]([0-9]+)$") if nil == weekDay then weekDay = string.match(anchor.desc,"%[lunar%]%[[Ww]%]([0-6]+)$") end if nil ~= weekDay then weekDay = tonumber(weekDay) if weekDay>6 then weekDay = nil end end if nil ~= weekDay then --获取今天的周序值,距离周日的天数 local daysToSundayToday = tostring(os.date('%w')) local timeBase = os.date("*t") timeBase.day = timeBase.day + weekDay - daysToSundayToday local tmpTime local idx --前查5周的日期 local preWs = 5 --后查10周的日期 local posWs = 10 for idx = 1,preWs do tmpTime = os.date("*t",os.time(timeBase)) tmpTime.day = tmpTime.day - 7*(preWs-idx+1) table.insert(anchor.solarDatesList,os.date("%Y%m%d",os.time(tmpTime))) end for idx = 0,posWs do tmpTime = os.date("*t",os.time(timeBase)) tmpTime.day = tmpTime.day + 7*idx table.insert(anchor.solarDatesList,os.date("%Y%m%d",os.time(tmpTime))) end if 0<#anchor.solarDatesList then anchor.solarFlg = true anchor.weekFlg = true end return anchor end end --4.1/2解码公历月循环事件 do local daysOffset = string.match(anchor.desc,"%[solar%]%[[Mm]%](-*[0-9]+)$") if nil ~= daysOffset then daysOffset = tonumber(daysOffset) if 0==daysOffset or daysOffset<-31 or daysOffset>31 then daysOffset = nil end end if nil ~= daysOffset then local timeBase = os.date("*t") timeBase = os.time({year=timeBase.year,month=timeBase.month,day=1}) local fakeTime local anchorMonth local idx --前查12个月的日期 local preMs = 12 --后查12个月的日期 local posMs = 10 for idx = 1,preMs do fakeTime = os.date('*t',timeBase) fakeTime.month = fakeTime.month - (preMs-idx+1) local t = os.time(fakeTime) anchorMonth = tonumber(os.date("%m",t)) t = t + (daysOffset-(daysOffset>0 and 1 or 0))*86400 if daysOffset > 0 then if tonumber(os.date('%m',t)) == anchorMonth then table.insert(anchor.solarDatesList,os.date("%Y%m%d",t)) end elseif daysOffset < 0 then if tonumber(os.date('%m',t)) == (anchorMonth==1 and 12 or anchorMonth-1) then table.insert(anchor.solarDatesList,os.date("%Y%m%d",t)) end end end for idx = 0,posMs do fakeTime = os.date('*t',timeBase) fakeTime.month = fakeTime.month + idx local t = os.time(fakeTime) anchorMonth = tonumber(os.date("%m",t)) t = t + (daysOffset-(daysOffset>0 and 1 or 0))*86400 if daysOffset > 0 then if tonumber(os.date('%m',t)) == anchorMonth then table.insert(anchor.solarDatesList,os.date("%Y%m%d",t)) end elseif daysOffset < 0 then if tonumber(os.date('%m',t)) == (anchorMonth==1 and 12 or anchorMonth-1) then table.insert(anchor.solarDatesList,os.date("%Y%m%d",t)) end end end if 0<#anchor.solarDatesList then anchor.solarFlg = true anchor.monthFlg = true end return anchor end end --5.1/2解码农历月循环事件 do local daysOffset = string.match(anchor.desc,"%[lunar%]%[[Mm]%](-*[0-9]+)$") if nil ~= daysOffset then daysOffset = tonumber(daysOffset) if 0==daysOffset or daysOffset<-31 or daysOffset>31 then daysOffset = nil end end if nil ~= daysOffset then local lunarYear = tonumber(os.date("%Y")) local fakeLunarDatesList = {} --合成去年1-9月度的月度字符串 for idx = 1,9 do table.insert(fakeLunarDatesList,(lunarYear-1)..'0'..idx..'01.0') end --合成去年10-12月度的月度字符串 for idx = 10,12 do table.insert(fakeLunarDatesList,(lunarYear-1)..idx..'01.0') end --合成今年1-9月度的月度字符串 for idx = 1,9 do table.insert(fakeLunarDatesList,lunarYear..'0'..idx..'01.0') end --合成今年10-12月度的月度字符串 for idx = 10,12 do table.insert(fakeLunarDatesList,lunarYear..idx..'01.0') end --合成明年1-9月度的月度字符串 for idx = 1,9 do table.insert(fakeLunarDatesList,(lunarYear+1)..'0'..idx..'01.0') end --合成明年10-12月度的月度字符串 for idx = 10,12 do table.insert(fakeLunarDatesList,(lunarYear+1)..idx..'01.0') end local fakeSolarDate for idx=1,#fakeLunarDatesList do fakeSolarDate = lunarDatesList[fakeLunarDatesList[idx]] local t = dateStr2Time(fakeSolarDate) local anchorMonth = tonumber(string.sub(fakeLunarDatesList[idx],5,6)) t = t + (daysOffset-(daysOffset>0 and 1 or 0))*86400 local lunarCheck = lunar.solar2LunarByTime(t) if daysOffset>0 then if anchorMonth == lunarCheck.month and false==lunarCheck.leap then table.insert(anchor.solarDatesList,os.date("%Y%m%d",t)) end elseif daysOffset<0 then if lunarCheck.month==(anchorMonth==1 and 12 or anchorMonth-1) then table.insert(anchor.solarDatesList,os.date("%Y%m%d",t)) end end end if 0<#anchor.solarDatesList then anchor.lunarFlg = true anchor.monthFlg = true end return anchor end end --6.1解码农历年循环事件 do local lunarYearMonth = string.match(anchor.desc,"%[lunar%]%[[Yy]%](%d%d%d%d)") if nil ~= lunarYearMonth then local lm,ld = string.match(anchor.desc,"%[lunar%]%[Y%](%d%d)(%d%d)") local ly = tonumber(os.date("%Y")) --预查前2年,后2年以及本年的农历日期,不考虑闰月 local fakeLunarDatesList = {(ly-2)..lm..ld..'.0', (ly-1)..lm..ld..'.0', (ly-0)..lm..ld..'.0', (ly+1)..lm..ld..'.0', (ly+2)..lm..ld..'.0'} local thisSolarDate for idx = 1,#fakeLunarDatesList do thisSolarDate = lunarDatesList[fakeLunarDatesList[idx]] if nil ~= thisSolarDate then table.insert(anchor.solarDatesList,thisSolarDate) end end if 0<#anchor.solarDatesList then anchor.lunarFlg = true anchor.yearFlg = true end return anchor end end --7.1解码公历年循环事件 do local solarYearMonth = string.match(anchor.desc,"%[solar%]%[[Yy]%](%d%d%d%d)") if nil ~= solarYearMonth then local m,d = string.match(anchor.desc,"%[solar%]%[Y%](%d%d)(%d%d)") local y = tonumber(os.date("%Y")) local fakeDateStr --定义去年的事件 fakeDateStr = (y - 1)..m..d if fakeDateStr == os.date("%Y%m%d",dateStr2Time(fakeDateStr)) then table.insert(anchor.solarDatesList,fakeDateStr) end --定义今年的事件 fakeDateStr = y..m..d if fakeDateStr == os.date("%Y%m%d",dateStr2Time(fakeDateStr)) then table.insert(anchor.solarDatesList,fakeDateStr) end --定义明年的事件 fakeDateStr = (y + 1)..m..d if fakeDateStr == os.date("%Y%m%d",dateStr2Time(fakeDateStr)) then table.insert(anchor.solarDatesList,fakeDateStr) end if 0<#anchor.solarDatesList then anchor.solarFlg = true anchor.yearFlg = true end return anchor end end --8.1/2解码锚定在农历月份+指定周序上的事件 --[lunar][Y][M05][1Ww]4 do local anchorLunarMonth,anchorWCnt,anchorWType,anchorWDay = string.match(anchor.desc,"%[[Ll]unar%]%[[Yy]%]%[[Mm]([0-9]+)%]%[(-*[0-9]+)([Ww])%]([0-9]+)$") if nil~=anchorLunarMonth and nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then anchorLunarMonth = tonumber(anchorLunarMonth) if anchorLunarMonth<1 or anchorLunarMonth>12 then anchorLunarMonth = nil elseif anchorLunarMonth<10 then anchorLunarMonth = '0'..anchorLunarMonth else anchorLunarMonth = tostring(anchorLunarMonth) end anchorWCnt = tonumber(anchorWCnt) if 0==anchorWCnt then anchorWCnt = nil end anchorWDay = tonumber(anchorWDay) if anchorWDay<0 or anchorWDay>6 then anchorWDay = nil end end if nil~=anchorLunarMonth and nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then local fakeLunarYear = 0 local fakeSolarDate = '' local fakeSolarDateTime = '' local fakeLunarDate = '' local idx = 0 --处理去年,今年,明天三年内的事件 for idx=1,3 do fakeLunarYear = tonumber(os.date('%Y'))+(idx-2) --找到农历对应月的初一,做为基准日期 fakeLunarDate = fakeLunarYear..anchorLunarMonth..'01.0' fakeSolarDate = lunarDatesList[fakeLunarDate] if nil ~= fakeSolarDate then table.insert(anchor.solarDatesList,os.date('%Y%m%d',timeOfWeekDayBaseOnTime0(dateStr2Time(fakeSolarDate),anchorWCnt,anchorWType,anchorWDay))) end end if 0<#anchor.solarDatesList then anchor.lunarFlg = true anchor.yearFlg = true end return anchor end end --9.1/2解码锚定在公历月份+指定周序上的事件 --[solar][Y][M05][1Ww]4 do local anchorSolarMonth,anchorWCnt,anchorWType,anchorWDay = string.match(anchor.desc,"%[[Ss]olar%]%[[Yy]%]%[[Mm]([0-9]+)%]%[(-*[0-9]+)([Ww])%]([0-9]+)$") if nil~=anchorSolarMonth and nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then anchorSolarMonth = tonumber(anchorSolarMonth) if anchorSolarMonth<1 or anchorSolarMonth>12 then anchorSolarMonth = nil elseif anchorSolarMonth<10 then anchorSolarMonth = '0'..anchorSolarMonth else anchorSolarMonth = tostring(anchorSolarMonth) end anchorWCnt = tonumber(anchorWCnt) if 0==anchorWCnt then anchorWCnt = nil end anchorWDay = tonumber(anchorWDay) if anchorWDay<0 or anchorWDay>6 then anchorWDay = nil end end if nil~=anchorSolarMonth and nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then local fakeSolarYear = 0 local fakeSolarDate = '' local fakeSolarDateTime = '' local idx = 0 --处理去年,今年,明天三年内的事件 for idx=1,3 do fakeSolarYear = tonumber(os.date('%Y'))+(idx-2) --以每指定月的1号作为指定的基准日期 fakeSolarDate = fakeSolarYear..anchorSolarMonth..'01' if nil ~= fakeSolarDate then table.insert(anchor.solarDatesList,os.date('%Y%m%d',timeOfWeekDayBaseOnTime0(dateStr2Time(fakeSolarDate),anchorWCnt,anchorWType,anchorWDay))) end end if 0<#anchor.solarDatesList then anchor.solarFlg = true anchor.yearFlg = true end return anchor end end --10.1/2/3/4解码锚定在节气上的+指定周序上的事件 --[lunar][Y][JQ清明][1w]4 do local anchorJqName,anchorWCnt,anchorWType,anchorWDay = string.match(anchor.desc,"%[[Ll]unar%]%[[Yy]%]%[[Jj][Qq](.+)%]%[(-*[0-9]+)([Ww])%]([0-9]+)$") if nil~=anchorJqName and nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then if 0==lunar.jqIdxByName(anchorJqName) then anchorJqName = nil end anchorWCnt = tonumber(anchorWCnt) if 0==anchorWCnt then anchorWCnt = nil end anchorWDay = tonumber(anchorWDay) if anchorWDay<0 or anchorWDay>6 then anchorWDay = nil end end if nil~=anchorJqName and nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then local jqInfo = lunar.jqInfoByName(anchorJqName) if #jqInfo.jqTimeList>0 then local idx for idx =1,#jqInfo.jqTimeList do --以每一个节气的时间为指定的基准时间 table.insert(anchor.solarDatesList,os.date('%Y%m%d',timeOfWeekDayBaseOnTime0(jqInfo.jqTimeList[idx],anchorWCnt,anchorWType,anchorWDay))) end end if 0<#anchor.solarDatesList then anchor.lunarFlg = true anchor.yearFlg = true anchor.jqFlg = true end return anchor end end --11.1/2/3/4解码锚定在公历每月+指定周序上的事件 --[solar][M][2w]2 do local anchorWCnt,anchorWType,anchorWDay = string.match(anchor.desc,"%[[Ss]olar%]%[[Mm]%]%[(-*[0-9]+)([Ww])%]([0-9]+)$") if nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then anchorWCnt = tonumber(anchorWCnt) if 0==anchorWCnt then anchorWCnt = nil end anchorWDay = tonumber(anchorWDay) if anchorWDay<0 or anchorWDay>6 then anchorWDay = nil end end if nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then local solarDateBase = os.date('*t') solarDateBase = os.date('*t',os.time({year=solarDateBase.year,month=solarDateBase.month,day=1})) local idx = 0 local fakeSolarDate for idx=1,24 do fakeSolarDate = os.date('*t',os.time(solarDateBase)) fakeSolarDate.month = fakeSolarDate.month + (idx - 13) table.insert(anchor.solarDatesList,os.date('%Y%m%d',timeOfWeekDayBaseOnTime0(os.time(fakeSolarDate),anchorWCnt,anchorWType,anchorWDay))) end if 0<#anchor.solarDatesList then anchor.solarFlg = true anchor.monthFlg = true end return anchor end end --12.1/2/3/4解码锚定在农历每月+指定周序上的事件 --[lunar][M][2w]2 do local anchorWCnt,anchorWType,anchorWDay = string.match(anchor.desc,"%[[Ll]unar%]%[[Mm]%]%[(-*[0-9]+)([Ww])%]([0-9]+)$") if nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then anchorWCnt = tonumber(anchorWCnt) if 0==anchorWCnt then anchorWCnt = nil end anchorWDay = tonumber(anchorWDay) if anchorWDay<0 or anchorWDay>6 then anchorWDay = nil end end if nil~=anchorWCnt and nil~=anchorWType and nil~=anchorWDay then local lunarDateBase = lunar.solar2LunarByTime(os.time()) local fakeLunarDate = '' local fakeSolarDate = '' local idx --处理前12个月以及后12个月的事件 --第一步,处理去年的月份事件 for idx=lunarDateBase.month,12 do if idx < 10 then fakeSolarDate = lunarDatesList[(lunarDateBase.year-1)..'0'..idx..'01.0'] else fakeSolarDate = lunarDatesList[(lunarDateBase.year-1)..idx..'01.0'] end if nil ~= fakeSolarDate then table.insert(anchor.solarDatesList,os.date('%Y%m%d',timeOfWeekDayBaseOnTime0(dateStr2Time(fakeSolarDate),anchorWCnt,anchorWType,anchorWDay))) end end --第二步,处理今年的月份事件 for idx=1,12 do if idx < 10 then fakeSolarDate = lunarDatesList[lunarDateBase.year..'0'..idx..'01.0'] else fakeSolarDate = lunarDatesList[lunarDateBase.year..idx..'01.0'] end if nil ~= fakeSolarDate then table.insert(anchor.solarDatesList,os.date('%Y%m%d',timeOfWeekDayBaseOnTime0(dateStr2Time(fakeSolarDate),anchorWCnt,anchorWType,anchorWDay))) end end --第三步,处理明年的月份事件 for idx=1,lunarDateBase.month do if idx < 10 then fakeSolarDate = lunarDatesList[(lunarDateBase.year+1)..'0'..idx..'01.0'] else fakeSolarDate = lunarDatesList[(lunarDateBase.year+1)..idx..'01.0'] end if nil ~= fakeSolarDate then table.insert(anchor.solarDatesList,os.date('%Y%m%d',timeOfWeekDayBaseOnTime0(dateStr2Time(fakeSolarDate),anchorWCnt,anchorWType,anchorWDay))) end end if 0<#anchor.solarDatesList then anchor.lunarFlg = true anchor.monthFlg = true end return anchor end end --13.1解码锚定在农历指定月+指定天数上的事件 --[lunar][Y][M05]4 do local anchorMonth,anchorDayOffset = string.match(anchor.desc,"%[[Ll]unar%]%[[Yy]%]%[[Mm]([0-9]+)%](-*[0-9]+)$") if nil~=anchorMonth and nil~=anchorDayOffset then anchorMonth = tonumber(anchorMonth) if anchorMonth<1 or anchorMonth>12 then anchorMonth = nil end anchorDayOffset = tonumber(anchorDayOffset) if 0==anchorDayOffset then anchorDayOffset = nil end end if nil~=anchorMonth and nil~=anchorDayOffset then local lunarDateBase = lunar.solar2LunarByTime(os.time()) local fakeSolarDate = '' --第一步,处理去年的事件 if anchorMonth < 10 then fakeSolarDate = lunarDatesList[(lunarDateBase.year-1)..'0'..anchorMonth..'01.0'] else fakeSolarDate = lunarDatesList[(lunarDateBase.year-1)..anchorMonth..'01.0'] end if nil ~= fakeSolarDate then fakeSolarDate = os.date('*t',dateStr2Time(fakeSolarDate)) fakeSolarDate.day = fakeSolarDate.day + anchorDayOffset - (anchorDayOffset>0 and 1 or 0) table.insert(anchor.solarDatesList,os.date('%Y%m%d',os.time(fakeSolarDate))) end --第二步,处理今年的事件 if anchorMonth < 10 then fakeSolarDate = lunarDatesList[lunarDateBase.year..'0'..anchorMonth..'01.0'] else fakeSolarDate = lunarDatesList[lunarDateBase.year..anchorMonth..'01.0'] end if nil ~= fakeSolarDate then fakeSolarDate = os.date('*t',dateStr2Time(fakeSolarDate)) fakeSolarDate.day = fakeSolarDate.day + anchorDayOffset - (anchorDayOffset>0 and 1 or 0) table.insert(anchor.solarDatesList,os.date('%Y%m%d',os.time(fakeSolarDate))) end --第三步,处理明年的事件 if anchorMonth < 10 then fakeSolarDate = lunarDatesList[(lunarDateBase.year+1)..'0'..anchorMonth..'01.0'] else fakeSolarDate = lunarDatesList[(lunarDateBase.year+1)..anchorMonth..'01.0'] end if nil ~= fakeSolarDate then fakeSolarDate = os.date('*t',dateStr2Time(fakeSolarDate)) fakeSolarDate.day = fakeSolarDate.day + anchorDayOffset - (anchorDayOffset>0 and 1 or 0) table.insert(anchor.solarDatesList,os.date('%Y%m%d',os.time(fakeSolarDate))) end if 0<#anchor.solarDatesList then anchor.lunarFlg = true anchor.yearFlg = true end return anchor end end --14.1解码锚定在公历指定月+指定天数上的事件 --[solar][Y][M05]4 do local anchorMonth,anchorDayOffset = string.match(anchor.desc,"%[[Ss]olar%]%[[Yy]%]%[[Mm]([0-9]+)%](-*[0-9]+)$") if nil~=anchorMonth and nil~=anchorDayOffset then anchorMonth = tonumber(anchorMonth) if anchorMonth<1 or anchorMonth>12 then anchorMonth = nil end anchorDayOffset = tonumber(anchorDayOffset) if 0==anchorDayOffset then anchorDayOffset = nil end end if nil~=anchorMonth and nil~=anchorDayOffset then local solarDateBase = os.date('*t') local fakeSolarDate --第一步,处理去年的事件 fakeSolarDate = os.date('*t',os.time({year=solarDateBase.year,month=anchorMonth,day=1})) fakeSolarDate.year = fakeSolarDate.year - 1 fakeSolarDate.day = fakeSolarDate.day + anchorDayOffset - (anchorDayOffset>0 and 1 or 0) table.insert(anchor.solarDatesList,os.date('%Y%m%d',os.time(fakeSolarDate))) --第二步,处理今年的事件 fakeSolarDate = os.date('*t',os.time({year=solarDateBase.year,month=anchorMonth,day=1})) fakeSolarDate.day = fakeSolarDate.day + anchorDayOffset - (anchorDayOffset>0 and 1 or 0) table.insert(anchor.solarDatesList,os.date('%Y%m%d',os.time(fakeSolarDate))) --第三步,处理明年的事件 fakeSolarDate = os.date('*t',os.time({year=solarDateBase.year,month=anchorMonth,day=1})) fakeSolarDate.year = fakeSolarDate.year + 1 fakeSolarDate.day = fakeSolarDate.day + anchorDayOffset - (anchorDayOffset>0 and 1 or 0) table.insert(anchor.solarDatesList,os.date('%Y%m%d',os.time(fakeSolarDate))) if 0<#anchor.solarDatesList then anchor.solarFlg = true anchor.yearFlg = true end return anchor end end --15.1/2解码锚定在指定节气+指定天数上的事件 --[lunar][Y][JQ春分]4 do local anchorJqName,anchorDayOffset = string.match(anchor.desc,"%[[Ll]unar%]%[[Yy]%]%[[Jj][Qq](.+)%](-*[0-9]+)$") if nil~=anchorJqName and nil~=anchorDayOffset then if 0==lunar.jqIdxByName(anchorJqName) then anchorJqName = nil end anchorDayOffset = tonumber(anchorDayOffset) if 0==anchorDayOffset then anchorDayOffset = nil end end if nil~=anchorJqName and nil~=anchorDayOffset then local jqInfo = lunar.jqInfoByName(anchorJqName) if #jqInfo.jqTimeList>0 then local idx local t for idx =1,#jqInfo.jqTimeList do --以每一个节气的时间为指定的基准时间 t = jqInfo.jqTimeList[idx] t = t + (anchorDayOffset - (anchorDayOffset>0 and 1 or 0))*86400 table.insert(anchor.solarDatesList,os.date('%Y%m%d',t)) end end if 0<#anchor.solarDatesList then anchor.lunarFlg = true anchor.yearFlg = true anchor.jqFlg = true end return anchor end end return anchor end --将文档处理成行数组 local function files_to_lines(...) if dbgFlg then print("--->files_to_lines called here") end local tab=setmetatable({},{__index=table}) local index=1 for i,filename in next,{...} do local fn = io.open(filename) if fn then for line in fn:lines() do if not line or #line > 0 then tab:insert(line) end end fn:close() end end if dbgFlg then print("--->files_to_lines completed here") end return tab end --根据加载的文档,创建事件字典,以公历日期为索引 local function eventsDicBySolarDatesBuild(...) if dbgFlg then print("-->eventsDicBySolarDatesBuild called here") end local lines=files_to_lines(...) for i,line in next ,lines do if dbgFlg then print('line is: ', line) end if not line:match("^%s*#") then -- 第一字 # 为注释行 local d,kW,c = string.match(line,"(.+)\t(%C*)\t(%C*)") if nil ~= d then local thisEvent = {} thisEvent.d = d thisEvent.kW = kW or '' thisEvent.c = c or thisEvent.kW if '' ~= thisEvent.kW then thisEvent.kWs = stringSplit(thisEvent.kW,' ') end if nil == thisEvent.kWs then thisEvent.kWs = {thisEvent.kW} end local anchorInfo = anchorDecode(thisEvent.d) local thisKw = '' for idx = 1,#anchorInfo.solarDatesList do local subEvent = {} subEvent.c1 = thisEvent.d subEvent.c2 = thisEvent.kW subEvent.c3 = thisEvent.c subEvent.kWs = thisEvent.kWs local thisSolarDate = anchorInfo.solarDatesList[idx] subEvent.time = dateStr2Time(thisSolarDate) subEvent.solarDate = thisSolarDate local tDiff = dt.timeDiff(subEvent.time) if tDiff.monthsDiff<-1 then --如果这个事件的时间点已经过去大于一个月了,则不做处理 if dbgFlg then print('这个事件放弃:',subEvent.c1,thisSolarDate) end else --添加一个新的事件 if nil == eventsDicBySolarDates[thisSolarDate] then eventsDicBySolarDates[thisSolarDate] = {subEvent} else table.insert(eventsDicBySolarDates[thisSolarDate],subEvent) end for subIdx = 1, #subEvent.kWs do thisKw = subEvent.kWs[subIdx] or '' if ''~=thisKw then if nil == eventsDicListByKeyW[thisKw] then --这是一个新的 kW eventsDicListByKeyW[thisKw] = {subEvent} else --这不是一个新的 kW table.insert(eventsDicListByKeyW[thisKw],subEvent) end end end end end end end end if dbgFlg then print("-->eventsDicBySolarDatesBuild completed here") end end --通过keyWord来获取对应的事件列表 local function getEventsByKw(kW) local eventsList = {} kW = kW or '' if '' == kW then return eventsList end if nil==eventsDicListByKeyW then eventsList = {} else eventsList = eventsDicListByKeyW[kW] or {} end --需要进行一个排序处理,以方便后端使用 if #eventsList > 0 then --做一个排序,按time升序排列 table.sort(eventsList, function(a,b) if a.time < b.time then return true end return false end) end return eventsList end --通过时间来获取对应的事件列表 local function getEventsByTime(t) local eventsList = {} if nil == t then t = os.time() end if nil==eventsDicBySolarDates then eventsList = {} else eventsList = eventsDicBySolarDates[os.date('%Y%m%d',t)] end return eventsList or {} end --===========================test======================== local function test(printPrefix) if nil == printPrefix then printPrefix = ' ' end if dbgFlg then print('eventsListModule test starting...') end --sysInfoRes.test(printPrefix..' ') --lunar.test(printPrefix..' ') --dt.test(printPrefix..' ') for k,v in pairs(eventsDicBySolarDates) do if dbgFlg then print(printPrefix..k..'\t'..v) end end end function M.init(...) --准备日期序列,包括去年一整年,以及将来一整年的日期在内 local daysCntThisYear = tonumber(os.date("%j")) lunarDatesListBuild(370+daysCntThisYear,740-daysCntThisYear) --创建节气表 lunar.jqListBuild() --加载文档中的事件信息 local files={...} --文件名不支持中文,其中 # 开始的行为注释行 table.insert(files,"eventsList.txt") for i,v in next, files do files[i] = sysInfoRes.currentDir().."/".. v end eventsDicBySolarDatesBuild(table.unpack(files)) --抛出功能函数 M.getEventsByKw = getEventsByKw M.getEventsByTime = getEventsByTime M.setDbg = setDbg M.test = test end M.init() return M
日期与时间
lua文件夹
dateTimeModule.lua
--dateTimeModule.lua --Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> --该模块主要提供一些当前的时间和日期的相关信息 local M={} local dbgFlg = false --引入农历计算模块 local lunarEnable, lunar = pcall(require, 'lunarModule') -- 导入log模块记录日志 local logEnable, log = pcall(require, "runLog") --设置 dbg 开关 local function setDbg(flg) flg = flg or dbgFlg dbgFlg = flg if lunarEnable then lunar.setDbg(flg) end if logEnable then log.setDbg(flg) end print('dateTimeModule dbgFlg is '..tostring(dbgFlg)) end local wNames_CN = {'星期日','星期一','星期二','星期三','星期四','星期五','星期六'} local wNames_EN = {'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'} local wNames_Short = {'Sun.','Mon.','Tues.','Wed.','Thur.','Fri.','Sat.'} local mName_EN = {'January','February','March','April','May','June','July','August','September','October','November','December'} local mName_Short = {'Jan.','Feb.','Mar.','Apr.','May.','Jun.','Jul.','Aug.','Sep.','Oct.','Nov.','Dec.'} local numSymbals = {'st','nd','rd','th'} local timeLogos = {['0000']='',['0030']='',['0100']='',['0130']='',['0200']='',['0230']='',['0300']='',['0330']='',['0400']='',['0430']='',['0500']='',['0530']='',['0600']='',['0630']='',['0700']='',['0730']='',['0800']='',['0830']='',['0900']='',['0930']='',['1000']='',['1030']='',['1100']='',['1130']='',['1200']='',['1230']='',['1300']='',['1330']='',['1400']='',['1430']='',['1500']='',['1530']='',['1600']='',['1630']='',['1700']='',['1730']='',['1800']='',['1830']='',['1900']='',['1930']='',['2000']='',['2030']='',['2100']='',['2130']='',['2200']='',['2230']='',['2300']='',['2330']='',['2400']=''} local diZhi = {"子","丑","寅","卯","辰","巳","午", "未","申","酉","戌","亥"} local function numSymbal(num) if num > 4 then return numSymbals[4] else return numSymbals[num] end end --获取timeLogo local function timeLogo(t) t = t or os.time() local timeNow = os.time() if type(t) == type(timeNow) then timeNow = t end local hourValue = os.date("%H",timeNow) local minValue=tonumber(os.date("%M",timeNow)) if 15 < minValue and minValue < 45 then return timeLogos[string.format("%02d30",hourValue)] elseif 15 > minValue then return timeLogos[string.format("%02d00",hourValue)] else return timeLogos[string.format("%02d00",hourValue+1)] end end --[[提供一个timeInfo的时间结构,定义如下 timeInfo.time: 以秒为单位的时间戳 timeInfo.shiChen:时辰 timeInfo.time1:22:47:12 timeInfo.time2:22:47 timeInfo.time3:22点47分16秒 timeInfo.timeLogo: 时间对应的钟表符号 ]] local function timeInfoByTime(t) t = t or os.time() local tBase=os.time() if type(t)==type(tBase) then tBase = t end local timeInfo = {} timeInfo.time = tBase timeInfo.shiChen = '' timeInfo.time1 = os.date("%H:%M:%S",tBase) timeInfo.time2 = os.date("%H:%M",tBase) timeInfo.time3 = os.date("%H点%M分%S秒",tBase) local h = tonumber(os.date('%H',tBase)) h = math.floor((h + 1)/2)+1 timeInfo.shiChen = (diZhi[h] or diZhi[1])..'时' timeInfo.timeLogo = timeLogo(tBase) return timeInfo end --[[根据指定的时间,返回结构化的 alltimeInfo 对象,结构如下 alltimeInfo.time: 时间值 alltimeInfo.YYYYMMDD_hhmmss: 2022-05-09 22:47:12 alltimeInfo.YYYYMMDD_hhmm: 2022-05-09 22:47 alltimeInfo.YYYYMMDD_W_hhmmss: 2022年5月9日 星期一 22点47分16秒 alltimeInfo.W_M_Date_hhmmss_YYYY: Mon. May. 09th, 22:47:01, 2022 alltimeInfo.timeLogo: 时间对应的时钟符号 ]] local function alltimeInfo(t) t = t or os.time() local tBase = os.time() if type(t) == type(tBase) then tBase = t end local alltimeInfo = {} alltimeInfo.time = tBase --处理星期信息, os.date("%w"): 距离周日的天数 local wN=tonumber(os.date("%w",tBase)) + 1 local wInfo={wNames_CN[wN],wNames_EN[wN],wNames_Short[wN]} --处理月份信息 local mN=tonumber(os.date("%m",tBase)) local mInfo={mName_EN[mN],mName_Short[mN]} --处理日期信息 local dN=tonumber(os.date("%d",tBase)) local dInfo={os.date("%d")..numSymbal(dN)} --处理时分信息 local timeInfo = timeInfoByTime(tBase) --合成alltime信息 --2022-05-09 22:47:12 alltimeInfo.YYYYMMDD_hhmmss=os.date("%Y-%m-%d")..' '..timeInfo.time1 --2022-05-09 22:47 alltimeInfo.YYYYMMDD_hhmm=os.date("%Y-%m-%d")..' '..timeInfo.time2 --2022年5月9日 星期一 22点47分16秒 alltimeInfo.YYYYMMDD_W_hhmmss = os.date("%Y年")..tonumber(os.date("%m"))..'月'..tonumber(os.date('%d'))..'日 '..wInfo[1]..' '..timeInfo.time3 --Mon. May. 09th, 22:47:01, 2022 alltimeInfo.W_M_Date_hhmmss_YYYY = wInfo[3]..' '..mInfo[2]..' '..dInfo[1]..' '..timeInfo.time1..', '..os.date("%Y") alltimeInfo.timeLogo = timeInfo.timeLogo --返回alltime信息 return alltimeInfo end --提供 alltList 信息 local function allt() --处理星期信息, os.date("%w"): 距离周日的天数 local wN=tonumber(os.date("%w")) + 1 local wInfo={wNames_CN[wN],wNames_EN[wN],wNames_Short[wN]} --处理月份信息 local mN=tonumber(os.date("%m")) local mInfo={mName_EN[mN],mName_Short[mN]} --处理日期信息 local dN=tonumber(os.date("%d")) local dInfo={os.date("%d")..numSymbal(dN)} --处理时分信息 local timeInfo = timeInfoByTime() --合成alltime信息 --2022-05-09 22:47:12 local allt_1 = os.date("%Y-%m-%d")..' '..timeInfo.time1 --2022-05-09 22:47 local allt_2 = os.date("%Y-%m-%d")..' '..timeInfo.time2 --2022年5月9日 星期一 22点47分16秒 local allt_3 = os.date("%Y年")..tonumber(os.date("%m"))..'月'..tonumber(os.date('%d'))..'日 '..wInfo[1]..' '..timeInfo.time3 --Mon. May. 09th, 22:47:01, 2022 local allt_4 = wInfo[3]..' '..mInfo[2]..' '..dInfo[1]..' '..timeInfo.time1..', '..os.date("%Y") --返回alltime信息 return {allt_1,allt_2,allt_3,allt_4} end --[[根据时间返回日期信息,一个日期信息结构如下 dateInfo.time:日期的时间值 dateInfo.YYYY:日期的年份值 dateInfo.MM:日期的年份值 dateInfo.DD:日期的年份值 dateInfo.date_YYYYMMDD_1:2022/05/09 dateInfo.date_MMDD_1:05/09 dateInfo.date_YYYYMMDD_2:2022-05-09 dateInfo.date_MMDD_2:05-09 dateInfo.date_YYYY_MM_DD_1:2022年05月09日 dateInfo.date_YYYY_M_D_1:2022年5月9日 dateInfo.date_M_D_1:5月9日 dateInfo.date_M_Dth_YYYY:Mar. 09th, 2022 dateInfo.date_M_Dth_YYYY_2:May 09th, 2022 dateInfo.date10:二〇二二年五月九日 dateInfo.date_yyMxx:23M04 dateInfo.date_YYYYMMDD:20230412 dateInfo.lunarInfo: 一个lunar的结构体 ]] local function dateInfoByTime(t) t = t or os.time() local baseTime = os.time() if type(t) == type(baseTime) then baseTime = t end --处理年份信息 local yN=tonumber(os.date("%Y",baseTime)) local yN_1='' yN_1=os.date("%Y",baseTime):gsub("%d",{["1"]="一",["2"]="二",["3"]="三",["4"]="四",["5"]="五",["6"]="六",["7"]="七",["8"]="八",["9"]="九",["0"]="〇",}) local yInfo={yN_1.."年"} --处理月份信息 local mN=tonumber(os.date("%m",baseTime)) local mN_1='' mN_1=os.date("%m",baseTime):gsub("%d",{["1"]="一",["2"]="二",["3"]="三",["4"]="四",["5"]="五",["6"]="六",["7"]="七",["8"]="八",["9"]="九",["0"]="",}) if mN == 10 then mN_1 = '十' elseif mN == 11 then mN_1 = '十一' elseif mN == 12 then mN_1 = '十二' end local mInfo={mName_EN[mN],mName_Short[mN],mN_1..'月'} --处理日期信息 local dN=tonumber(os.date("%d",baseTime)) local dN_1='' dN_1=os.date("%d",baseTime):gsub("%d",{["1"]="一",["2"]="二",["3"]="三",["4"]="四",["5"]="五",["6"]="六",["7"]="七",["8"]="八",["9"]="九",["0"]="",}) if dN > 19 then dN_1 = string.sub(dN_1,1,3).."十"..string.sub(dN_1,4,#dN_1) elseif dN > 9 then dN_1="十"..string.sub(dN_1,4,#dN_1) end dN_1 = dN_1..'日' local dInfo={os.date("%d",baseTime)..numSymbal(dN),dN_1} local dateInfo = {} dateInfo.time = baseTime dateInfo.YYYY = os.date("%Y",baseTime) dateInfo.MM = os.date("%m",baseTime) dateInfo.DD = os.date("%d",baseTime) --合成 dateInfo 信息 --2022/05/09 dateInfo.date_YYYYMMDD_1 = os.date("%Y/%m/%d",baseTime) --05/09 dateInfo.date_MMDD_1 = os.date("%m/%d",baseTime) --2022-05-09 dateInfo.date_YYYYMMDD_2 = os.date("%Y-%m-%d",baseTime) --05-09 dateInfo.date_MMDD_2 = os.date("%m-%d",baseTime) --2022年05月09日 dateInfo.date_YYYY_MM_DD_1 = os.date("%Y年%m月%d日",baseTime) --2022年5月9日 dateInfo.date_YYYY_M_D_1 = os.date("%Y年",baseTime)..tonumber(os.date("%m",baseTime)).."月"..tonumber(os.date("%d",baseTime)).."日" --5月9日 dateInfo.date_M_D_1 = tonumber(os.date("%m",baseTime)).."月"..tonumber(os.date("%d",baseTime)).."日" --May. 09th, 2022 dateInfo.date_M_Dth_YYYY_1 = mInfo[2]..' '..dInfo[1]..', '..os.date("%Y",baseTime) --May 09th, 2022 dateInfo.date_M_Dth_YYYY_2 = mInfo[1]..' '..dInfo[1]..', '..os.date("%Y",baseTime) --二〇二二年五月九日 dateInfo.date10 = yInfo[1]..mInfo[3]..dInfo[2] --23M04 dateInfo.date_yyMxx = os.date("%yM%m",baseTime) --20230412 dateInfo.date_YYYYMMDD = os.date("%Y%m%d",baseTime) dateInfo.lunarInfo = lunar.solar2LunarByTime(baseTime) --输出 dateInfo 信息 return dateInfo end --提供 date信息 local function dateInfoByDaysOffset(daysOffset) --baseDate准备 daysOffset = daysOffset or 0 local thisOffset = 0 if type(thisOffset) == type(daysOffset) then thisOffset = daysOffset end local baseTime = os.date("*t") baseTime.day = baseTime.day + thisOffset local info = dateInfoByTime(os.time(baseTime)) --输出 dateInfo 信息 return info end --提供指定时间的 wInfo 信息 --[[week结构如下 wInfo.time:时间戳 wInfo.nameCN:周名称,中文 wInfo.nameEN:周名称,英文 wInfo.nameShort:周名称,简写 wInfo.xxWxx:周序,23W29 wInfo.offset2Sun:距离周日的天数 wInfo.offset2Year:年内周数,同步于xxWxx ]] local function wInfoByTime(t) t = t or os.time() local timeBase = os.time() if type(t) == type(timeBase) then timeBase = t end --处理星期信息, os.date("%w"): 距离周日的天数 local wN=tonumber(os.date("%w",timeBase)) --计算今年以来的周数 local weekNo=os.date("%W",timeBase) + 1 local wInfo = {} wInfo.time = timeBase wInfo.nameCN = wNames_CN[wN+1] wInfo.nameEN = wNames_EN[wN+1] wInfo.nameShort = wNames_Short[wN+1] wInfo.offset2Sun = wN wInfo.offset2Year = weekNo wInfo.xxWxx = os.date("%y",timeBase).."W"..wInfo.offset2Year return wInfo end --提供指定时间的 week 信息 local function week(t) local thisInfo = wInfoByTime(t) return {thisInfo.nameCN,thisInfo.nameEN,thisInfo.nameShort,thisInfo.xxWxx} end --[[计算两个时间之间的差别,以 t1 为参考点,返回结构体如下: diff.tRef:这是计算的基准时间 diff.tTgt:这是计算的目标时间 diff.timeDiff:这是时间戳差,单位是s diff.daysDiff:这是天数差,单位是天 diff.monthsDiff:这是月数差,单位是月 diff.yearsDiff:这是年数差,单位是年 diff.weeksDiff:这是周数差,单位是周 ]] local function timeDiff(t1,t2) local diff = {} if nil == t1 then t1 = os.time() end if nil == t2 then --如果只有一个参数,则计算所给的 t1与当前时间的差值 t2 = t1 t1 = os.time() end diff.tRef = t1 diff.tTgt = t2 diff.timeDiff = 0 diff.daysDiff = 0 diff.monthsDiff = 0 diff.yearsDiff = 0 diff.weeksDiff = 0 local t11 = os.date("*t", t1) local t22 = os.date("*t", t2) --计算时间差 diff.timeDiff = t2 - t1 --计算天数差 local t11_noTime = os.time({year=t11.year, month=t11.month, day=t11.day}) local t22_noTime = os.time({year=t22.year, month=t22.month, day=t22.day}) diff.daysDiff = math.floor((t22_noTime - t11_noTime) / (3600 * 24)) --计算年数差 diff.yearsDiff = t22.year - t11.year --计算月数差 diff.monthsDiff = diff.yearsDiff * 12 + t22.month - t11.month --计算周数差 local t1_wn = tonumber(os.date("%w",t1)) local t2_wn = tonumber(os.date("%w",t2)) local daysDiffToWeekStart = diff.daysDiff + t1_wn - t2_wn diff.weeksDiff = math.floor(daysDiffToWeekStart/7) return diff end --计算时间偏差的语义,以 t1 为base,计算 t2 的偏离量 local function daysDiffName(t1,t2) local tDiff = timeDiff(t1,t2) local comment = '' if tDiff.daysDiff == -3 then comment = '大前天' elseif tDiff.daysDiff == -2 then comment = '前天' elseif tDiff.daysDiff == 0 then comment = '今天' elseif tDiff.daysDiff == -1 then comment = '昨天' elseif tDiff.daysDiff == 1 then comment = '明天' elseif tDiff.daysDiff == 2 then comment = '后天' elseif tDiff.daysDiff == 3 then comment = '大后天' elseif tDiff.weeksDiff == -2 then comment = '上上周' elseif tDiff.weeksDiff == -1 then comment = '上周' elseif tDiff.weeksDiff == 1 then comment = '下周' elseif tDiff.weeksDiff == 2 then comment = '下下周' elseif tDiff.monthsDiff == -2 then comment = '上上月' elseif tDiff.monthsDiff == -1 then comment = '上月' elseif tDiff.monthsDiff == 1 then comment = '下月' elseif tDiff.monthsDiff == 2 then comment = '下下月' elseif tDiff.yearsDiff == -3 then comment = '大前年' elseif tDiff.yearsDiff == -2 then comment = '前年' elseif tDiff.yearsDiff == -1 then comment = '去年' elseif tDiff.yearsDiff == 1 then comment = '明年' elseif tDiff.yearsDiff == 2 then comment = '后年' elseif tDiff.yearsDiff == 3 then comment = '大后年' elseif tDiff.yearsDiff ~= 0 then comment = math.abs(tDiff.yearsDiff)..'年'..((tDiff.yearsDiff<0) and '前' or '后') elseif tDiff.monthsDiff ~= 0 then comment = math.abs(tDiff.monthsDiff)..'个月'..((tDiff.monthsDiff<0) and '前' or '后') elseif tDiff.weeksDiff ~= 0 then comment = math.abs(tDiff.weeksDiff)..'周'..((tDiff.weeksDiff<0) and '前' or '后') elseif tDiff.daysDiff ~= 0 then comment = math.abs(tDiff.daysDiff)..'天'..((tDiff.daysDiff<0) and '前' or '后') end return comment end --=========================这是测试函数======================= local function test() local alltList = allt() local idx print("allt") for idx=1,#alltList do print('\t'..alltList[idx]) end local lunarList,jqList,dateList = lunar.jqListComming() print("lunarInfo") for idx=1,#lunarList do print('\t'..lunarList[idx]..'\t'..jqList[idx]..'\t'..dateList[idx]) end local wInfo = week() print("week info") for idx=1,#wInfo do print('\t'..wInfo[idx]) end end --=========================模块化封装========================= function M.init(...) print("-> M.init called here") --抛出功能函数 M.jqListComming = lunar.jqListComming M.jqIdxByName = lunar.jqIdxByName M.jqInfoByTime = lunar.jqInfoByTime M.jqListBuild = lunar.jqListBuild M.timeInfoByTime = timeInfoByTime M.alltimeInfo = alltimeInfo M.allt = allt M.dateInfoByTime = dateInfoByTime M.dateInfoByDaysOffset = dateInfoByDaysOffset M.week = week M.wInfoByTime = wInfoByTime M.timeLogo = timeLogo M.timeDiff = timeDiff M.daysDiffName = daysDiffName M.setDbg = setDbg M.test = test end M.init() return M
dateTime_filter.lua
--dateTime_filter.lua --Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> --本脚本主要用于提供一些与时间日期信息相关的处理服务 --引入支持模块,处理日期和时间信息 local ok, res = pcall(require, 'dateTimeModule') local alltimeInfo = res.alltimeInfo local jqListComming = res.jqListComming local jqIdxByName = res.jqIdxByName local jqInfoByTime = res.jqInfoByTime local wInfoByTime = res.wInfoByTime local daysDiffName = res.daysDiffName local dateInfoByTime = res.dateInfoByTime local dateInfoByDaysOffset = res.dateInfoByDaysOffset local timeInfoByTime = res.timeInfoByTime -- 导入log模块记录日志 local logEnable, log = pcall(require, "runLog") --创建节气表 res.jqListBuild() --引入 eventsList 模块,处理日期相关事件信息 local ok, res1 = pcall(require, 'eventsListModule') local getEventsByKw = res1.getEventsByKw local getEventsByTime = res1.getEventsByTime --最长的comment长度限制 local maxLenOfComment = 250 --加载农历信息 local lunarList,jqList,timeList local thisLunar,thisJq,thisTime local cands local theCands local candTxt_lower local thisComment local alltInfo local dateInfoList local jqTime local jqName local eventsList local thisEvent local thisTxt local wInfo local timeBase local timeReBase local dateInfo local function Filter(input, env) --获取dateTimeInfo开关状态 local on = true --env.engine.context:get_option("dateTime") cands={} for cand in input:iter() do --抛出原选项 if nil == cands[cand.text] then yield(cand) cands[cand.text]=true end if on then candTxt_lower = cand.text:lower() --时间选项整理 if ({['time']=true,['时间']=true,['现在']=true,['now']=true,['此刻']=true,['此时']=true})[candTxt_lower] then --处理时间信息 alltInfo = alltimeInfo() theCands={} if ({['现在']=true,['now']=true,['此刻']=true,['此时']=true})[candTxt_lower] then table.insert(theCands,{candTxt_lower.."("..alltInfo.YYYYMMDD_hhmmss..")",alltInfo.timeLogo}) end table.insert(theCands,{alltInfo.YYYYMMDD_hhmmss,alltInfo.timeLogo}) table.insert(theCands,{alltInfo.YYYYMMDD_hhmm,alltInfo.timeLogo}) table.insert(theCands,{alltInfo.YYYYMMDD_W_hhmmss,alltInfo.timeLogo}) table.insert(theCands,{alltInfo.W_M_Date_hhmmss_YYYY,alltInfo.timeLogo}) --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['时辰']=true})[candTxt_lower] then local timeInfo = timeInfoByTime() theCands={} table.insert(theCands,{timeInfo.shiChen,timeInfo.timeLogo}) for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['钟表']=true,['时钟']=true,['clock']=true,['表']=true})[candTxt_lower] then local timeInfo = timeInfoByTime() theCands={} table.insert(theCands,{timeInfo.timeLogo,''}) --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['date']=true,['日期']=true,['今天']=true,['今日']=true,['today']=true,['明天']=true,['明日']=true,['后天']=true,['昨天']=true,['前天']=true})[candTxt_lower] then --处理日期信息 if ({['date']=true,['日期']=true,['今天']=true,['今日']=true,['today']=true})[candTxt_lower] then dateInfo = dateInfoByDaysOffset(0) elseif ({['明天']=true,['明日']=true})[candTxt_lower] then dateInfo = dateInfoByDaysOffset(1) elseif ({['后天']=true})[candTxt_lower] then dateInfo = dateInfoByDaysOffset(2) elseif ({['昨天']=true})[candTxt_lower] then dateInfo = dateInfoByDaysOffset(-1) elseif ({['前天']=true})[candTxt_lower] then dateInfo = dateInfoByDaysOffset(-2) end --获取周序信息 wInfo = wInfoByTime(dateInfo.time) --获取今天的事件信息 eventsList = getEventsByTime(dateInfo.time) --获取今天的24节气信息 jqTime, jqName = jqInfoByTime(dateInfo.time) --如果今天有特殊事件,则合成事件的comment信息 local eventsStr = '' for idx = 1, #eventsList do thisEvent = eventsList[idx] if '' ~= eventsStr then eventsStr = eventsStr..'\r[]'..thisEvent.c3 else eventsStr = '[]'..thisEvent.c3 end end theCands = {} if ({['今天']=true,['今日']=true,['today']=true,['明天']=true,['明日']=true,['后天']=true,['昨天']=true,['前天']=true})[candTxt_lower] then if ''~=eventsStr then table.insert(theCands,{candTxt_lower.."("..dateInfo.date_YYYYMMDD..")",eventsStr}) else table.insert(theCands,{candTxt_lower.."("..dateInfo.date_YYYYMMDD..")",''}) end table.insert(theCands,{dateInfo.date_YYYYMMDD_1..' '..wInfo.nameCN,''}) else if ''~=eventsStr then table.insert(theCands,{dateInfo.date_YYYYMMDD_1..' '..wInfo.nameCN,eventsStr}) else table.insert(theCands,{dateInfo.date_YYYYMMDD_1..' '..wInfo.nameCN,''}) end end table.insert(theCands,{dateInfo.date_M_Dth_YYYY_1,''}) table.insert(theCands,{dateInfo.date_YYYYMMDD,''}) if jqTime>0 then table.insert(theCands,{dateInfo.lunarInfo.lunarDate_1,dateInfo.lunarInfo.jiJieLogo..jqName}) else table.insert(theCands,{dateInfo.lunarInfo.lunarDate_4,dateInfo.lunarInfo.jiJieLogo}) end --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['周日']=true,['周一']=true,['周二']=true,['周三']=true,['周四']=true,['周五']=true,['周六']=true})[candTxt_lower] then --获取今天的周信息 timeBase = os.date('*t') wInfo = wInfoByTime() local wOffsetInput = ({['周日']=0,['周一']=1,['周二']=2,['周三']=3,['周四']=4,['周五']=5,['周六']=6})[candTxt_lower] --调整 base timeBase.day = timeBase.day + wOffsetInput - wInfo.offset2Sun wInfo = wInfoByTime(os.time(timeBase)) jqTime, jqName = jqInfoByTime(os.time(timeBase)) dateInfo = dateInfoByDaysOffset(wOffsetInput-tonumber(os.date('%w'))) local daysDiff = daysDiffName(os.time(),os.time(timeBase)) eventsList = getEventsByTime(os.time(timeBase)) local eventsStr = '' for idx = 1, #eventsList do thisEvent = eventsList[idx] if '' ~= eventsStr then eventsStr = eventsStr..'\r[]'..thisEvent.c3 else eventsStr = '[]'..thisEvent.c3 end end local commentStr = '' if '今天'==daysDiff then commentStr = '[]' elseif ''~=daysDiff then if os.time() < os.time(timeBase) then commentStr = '['..daysDiff..']' else commentStr = '['..daysDiff..']' end end if ''~=jqName then if ''==commentStr then commentStr = jqName else commentStr = commentStr..'\r'..jqName end end if ''~=eventsStr then if ''==commentStr then commentStr = eventsStr else commentStr = commentStr..'\r'..eventsStr end end dateInfoList = {dateInfo.date_YYYYMMDD_1,dateInfo.date_YYYYMMDD_2,dateInfo.date_M_Dth_YYYY_1,dateInfo.date_YYYYMMDD} for idx = 1, #dateInfoList do thisTxt = dateInfoList[idx] if nil == cands[thisTxt] then if 1==idx and ''~=commentStr then yield(Candidate("word", cand.start, cand._end, thisTxt, commentStr)) else yield(Candidate("word", cand.start, cand._end, thisTxt, '')) end cands[thisTxt]=true end end elseif ({['lunar']=true,['农历']=true,['节气']=true})[candTxt_lower] then --处理农历信息 lunarList,jqList,timeList = jqListComming() theCands={} for idx = 1, math.min(6,#lunarList) do thisJq = jqList[idx] thisTime = timeList[idx] dateInfo = dateInfoByTime(thisTime) thisLunar = dateInfo.lunarInfo.lunarDate_4 if os.date("%Y/%m/%d",thisTime) == os.date("%Y/%m/%d") then thisJq = '/'..dateInfo.lunarInfo.jiJieLogo..thisJq else local daysDiff = daysDiffName(os.time(),thisTime) if '' ~= daysDiff then if os.time() < thisTime then daysDiff = '['..daysDiff..']' else daysDiff = '['..daysDiff..']' end end thisLunar = dateInfo.lunarInfo.lunarDate_4..'('..thisJq..')' thisJq = dateInfo.lunarInfo.jiJieLogo..dateInfo.date_YYYYMMDD..daysDiff end table.insert(theCands,{thisLunar,thisJq}) end --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['wx']=true,['周序']=true,['周数']=true})[candTxt_lower] then --处理周信息 wInfo = wInfoByTime() theCands={} table.insert(theCands,{wInfo.xxWxx,''}) --抛出周序选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['本周']=true,['这周']=true,['上周']=true,['下周']=true})[candTxt_lower] then --处理周信息 timeBase = os.date('*t') --对齐到周一 timeBase.day = timeBase.day - os.date('%w') + 1 if ({['上周']=true})[candTxt_lower] then timeBase.day = timeBase.day - 7 elseif ({['下周']=true})[candTxt_lower] then timeBase.day = timeBase.day + 7 end wInfo = wInfoByTime(os.time(timeBase)) theCands={} if ({['本周']=true,['上周']=true,['下周']=true})[candTxt_lower] then table.insert(theCands,{candTxt_lower.."("..wInfo.xxWxx..")",''}) end table.insert(theCands,{wInfo.xxWxx,''}) for idx=0,6 do timeReBase = os.date('*t',os.time(timeBase)) timeReBase.day = timeReBase.day + idx local daysDiff = daysDiffName(os.time(),os.time(timeReBase)) --获取事件 eventsList = getEventsByTime(os.time(timeReBase)) --节取节气 local jqT,jqN = jqInfoByTime(os.time(timeReBase)) --日期信息 dateInfo = dateInfoByTime(os.time(timeReBase)) --周序信息 wInfo = wInfoByTime(os.time(timeReBase)) --如果存在节气,或者存在事件 if ''~=jqN or 0<#eventsList then thisComment = '' local daysDiffInfo = os.date("%Y/%m/%d",os.time(timeReBase)) if os.date("%Y/%m/%d") == os.date("%Y/%m/%d",os.time(timeReBase)) then daysDiffInfo = '[]' elseif ''~=daysDiff and candTxt_lower~=daysDiff then --为了避免关键字与日期差异的信息冗余,增加条件 candTxt_lower~=daysDiff if os.time() < os.time(timeReBase) then daysDiffInfo = '['..daysDiff..']' else daysDiffInfo = '['..daysDiff..']' end end --如果节气存在 if jqT>0 then if ''==thisComment then if ''~=daysDiffInfo then thisComment = dateInfo.lunarInfo.jiJieLogo..jqN..daysDiffInfo daysDiffInfo = '' else thisComment = dateInfo.lunarInfo.jiJieLogo..jqN end else if ''~=daysDiffInfo then thisComment = thisComment..'\r'..dateInfo.lunarInfo.jiJieLogo..jqN..daysDiffInfo daysDiffInfo = '' else thisComment = thisComment..'\r'..dateInfo.lunarInfo.jiJieLogo..jqN end end end --如果事件存在 for idx = 1,#eventsList do thisEvent = eventsList[idx] if ''~=thisEvent.c3 and ''~=thisEvent.cycleType then if ''~=daysDiffInfo then if ''==thisComment then thisComment = '[]'..thisEvent.c3..daysDiffInfo else thisComment = thisComment..'\r[]'..thisEvent.c3..daysDiffInfo end daysDiffInfo = '' else if ''==thisComment then thisComment = '[]'..thisEvent.c3 else thisComment = thisComment..'\r[]'..thisEvent.c3 end end end end if ''==thisComment then thisComment = '' end table.insert(theCands,{dateInfo.date_YYYYMMDD_1..' '..wInfo.nameCN,thisComment}) end end --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['week']=true,['星期']=true})[candTxt_lower] then --处理周信息 wInfo = wInfoByTime() theCands={} table.insert(theCands,{wInfo.nameCN,''}) table.insert(theCands,{wInfo.nameEN,''}) table.insert(theCands,{wInfo.nameShort,''}) --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['本月']=true,['上月']=true,['下月']=true})[candTxt_lower] then --处理月份信息 if ({['本月']=true})[candTxt_lower] then dateInfo = dateInfoByTime(os.time()) elseif ({['上月']=true})[candTxt_lower] then dateInfo = dateInfoByDaysOffset(-os.date("%d")-1) elseif ({['下月']=true})[candTxt_lower] then dateInfo = dateInfoByDaysOffset(45-os.date("%d")) end theCands={} if ({['本月']=true,['上月']=true,['下月']=true})[candTxt_lower] then table.insert(theCands,{candTxt_lower.."("..dateInfo.date_yyMxx..")",''}) end table.insert(theCands,{dateInfo.date_yyMxx,''}) --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif ({['今年']=true,['去年']=true,['明年']=true,['前年']=true,['后年']=true})[candTxt_lower] then if ({['今年']=true})[candTxt_lower] then dateInfo = dateInfoByTime(os.time({year = tonumber(os.date("%Y")), month = 5, day = 1, hour = 8, min = 0, sec = 0})) elseif ({['去年']=true})[candTxt_lower] then dateInfo = dateInfoByTime(os.time({year = tonumber(os.date("%Y"))-1, month = 5, day = 1, hour = 8, min = 0, sec = 0})) elseif ({['明年']=true})[candTxt_lower] then dateInfo = dateInfoByTime(os.time({year = tonumber(os.date("%Y"))+1, month = 5, day = 1, hour = 8, min = 0, sec = 0})) elseif ({['前年']=true})[candTxt_lower] then dateInfo = dateInfoByTime(os.time({year = tonumber(os.date("%Y"))-2, month = 5, day = 1, hour = 8, min = 0, sec = 0})) elseif ({['后年']=true})[candTxt_lower] then dateInfo = dateInfoByTime(os.time({year = tonumber(os.date("%Y"))+2, month = 5, day = 1, hour = 8, min = 0, sec = 0})) end theCands={} table.insert(theCands,{candTxt_lower.."("..dateInfo.YYYY..")",''}) table.insert(theCands,{dateInfo.lunarInfo.year_shengXiao..'年',''}) table.insert(theCands,{dateInfo.lunarInfo.year_ganZhi..'年',''}) table.insert(theCands,{dateInfo.lunarInfo.year_ganZhi.."("..dateInfo.lunarInfo.year_shengXiao..")"..'年',''}) --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end elseif jqIdxByName(candTxt_lower)>0 then --查找指定的节气信息 lunarList,jqList,timeList = jqListComming() local matchFlg = false local jqCnt = 0 theCands={} for idx = 1, #jqList do thisLunar = lunarList[idx] thisJq = jqList[idx] thisTime = timeList[idx] wInfo = wInfoByTime(thisTime) dateInfo = dateInfoByTime(thisTime) if not matchFlg then matchFlg = (thisJq == candTxt_lower) or false end if matchFlg then local daysDiff = daysDiffName(os.time(),thisTime) if '今天' == daysDiff then thisJq = ' '..thisJq else if '' ~= daysDiff then if os.time() < thisTime then daysDiff = '['..daysDiff..']' else daysDiff = '['..daysDiff..']' end end thisLunar = thisLunar..'('..thisJq..')' thisJq = dateInfo.lunarInfo.jiJieLogo..os.date("%Y/%m/%d",thisTime)..daysDiff end --加入周信息 thisLunar = thisLunar..' '..wInfo.nameCN if nil == cands[thisLunar] then table.insert(theCands,{thisLunar,thisJq}) jqCnt = jqCnt + 1 end if jqCnt >= 4 then break end end end --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end end do--事件选项整理 local eventsList = getEventsByKw(candTxt_lower) if 0<#eventsList then local timeNow = os.date('*t') --校准到零点 timeNow = os.time({year=timeNow.year,month=timeNow.month,day=timeNow.day,hour=0}) for idx=1,#eventsList do local thisE = eventsList[idx] if thisE.time > timeNow then dateInfo = dateInfoByTime(thisE.time) wInfo = wInfoByTime(thisE.time) local tDiff = daysDiffName(thisE.time) or '' local thisComment = thisE.c3 local thisCandTxt = dateInfo.date_YYYYMMDD_1..' '..wInfo.nameCN if nil==cands[thisCandTxt] and ''~= thisComment then if ''==tDiff then thisComment = '[]'..thisComment else if os.time() < thisE.time then thisComment = '['..tDiff..']'..thisComment else thisComment = '['..tDiff..']'..thisComment end end yield(Candidate("word", cand.start, cand._end, thisCandTxt, thisComment)) cands[thisCandTxt]=true end end end end end end end end return Filter
随机数 随机码 电脑信息 滤镜
lua文件夹
GUID.lua
--[[ Descripttion: version: Author: douyaoyuan Date: 2023-06-01 08:48:23 LastEditors: douyaoyuan LastEditTime: 2023-06-01 11:12:53 --]] --GUID.lua --这个模块主要用于处理一些utf8字符串相关的操作 local M={} local dbgFlg = false --设置 dbg 开关 local function setDbg(flg) dbgFlg = flg print('GUID dbgFlg is '..tostring(dbgFlg)) end --返回一个 GUID 字符串 function guid() local seed={'e','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'} local tb={} for i=1,32 do table.insert(tb,seed[math.random(1,16)]) end local sid=table.concat(tb) return string.format('%s-%s-%s-%s-%s', string.sub(sid,1,8), string.sub(sid,9,12), string.sub(sid,13,16), string.sub(sid,17,20), string.sub(sid,21,32) ) end --[[返回一个 guidInfo 结构,结构体如下: guidInfo.guid:正常的GUID guidInfo.noPunctuations:只包含字母和数字的GUID guidInfo.withUnderline:分隔符是下划线的 guid ]] function guidInfo() local id = {} local tmpId = guid() id.guid = tmpId id.noPunctuations = string.gsub(tmpId,"-","") id.withUnderline = string.gsub(tmpId,"-","_") return id end --这是测试函数 function test() local s=0 local start_time=os.clock() while s<50000 do s=s+1 print(s,guid()) end print('execute_time='..tostring(os.clock()-start_time)) end --Module function M.init(...) M.guidInfo = guidInfo M.setDbg = setDbg M.test = test end M.init() return M
sysInfo.lua
-- 导入log模块记录日志 local logEnable, log = pcall(require, "runLog") local M={} local dbgFlg = false --设置 dbg 开关 M.setDbg = function(flg) dbgFlg = flg print('sysInfo dbgFlg is '..tostring(dbgFlg)) end M.homePath = function() local tmpVar = os.getenv("HOMEPATH") or os.getenv("HOME") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.computerName = function() local tmpVar = os.getenv("COMPUTERNAME") or os.getenv("HOSTNAME") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.userName = function() local tmpVar = os.getenv("USERNAME") or os.getenv("USER") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.osName = function() local tmpVar = os.getenv("OS") if nil == tmpVar then tmpVar = 'UnixLike' end return tmpVar end M.NUMBER_OF_PROCESSORS = function() local tmpVar = os.getenv("NUMBER_OF_PROCESSORS") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.pwd = function() local tmpVar = os.getenv("PWD") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.oldPwd = function() local tmpVar = os.getenv("OLDPWD") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.PROCESSOR_IDENTIFIER = function() local tmpVar = os.getenv("PROCESSOR_IDENTIFIER") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.PROGRAMDATA = function() local tmpVar = os.getenv("PROGRAMDATA") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.PROGRAMFILES = function() local tmpVar = os.getenv("PROGRAMW6432") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.PROGRAMFILESx86 = function() local tmpVar = os.getenv("PROGRAMFILES(X86)") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.APPDATA = function() local tmpVar = os.getenv("APPDATA(X86)") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.WINDIR = function() local tmpVar = os.getenv("WINDIR") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.COMMONPROGRAMFILES = function() local tmpVar = os.getenv("COMMONPROGRAMFILES") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.COMMONPROGRAMFILESx86 = function() local tmpVar = os.getenv("COMMONPROGRAMFILES(x86)") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.TEMP = function() local tmpVar = os.getenv("TEMP") if nil == tmpVar or '' == tmpVar then tmpVar = os.getenv("TMP") end if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.SYSTEMDRIVE = function() local tmpVar = os.getenv("SYSTEMDRIVE") if nil == tmpVar then tmpVar = '未知' end return tmpVar end M.currentDir = function() local info = debug.getinfo(2) --debug.getinfo(2), 2: 返回调用 currentDir 的函数的信息 --解析info.source所在的路径 local path = info.source path = string.sub(path, 2, -1) -- 去掉开头的"@" path = string.gsub(path,'\\','/') -- 路径格式由 c:\\Users\\san.zhang\\ 转换为 c:/Users/san.zhang/ path = string.match(path, "^(.*)/") -- 捕获最后一个 "/" 之前的部分 就是我们最终要的目录部分 return path end M.writeLog = function(printPrefix) printPrefix = printPrefix or '' if logEnable then log.writeLog(printPrefix..'homePath: '..M.homePath()) log.writeLog(printPrefix..'computerName: '..M.computerName()) log.writeLog(printPrefix..'userName: '..M.userName()) log.writeLog(printPrefix..'osName: '..M.osName()) log.writeLog(printPrefix..'pwd: '..M.pwd()) log.writeLog(printPrefix..'oldPwd: '..M.oldPwd()) log.writeLog(printPrefix..'numberOfProcessors: '..M.NUMBER_OF_PROCESSORS()) log.writeLog(printPrefix..'progressorIdentifier: '..M.PROCESSOR_IDENTIFIER()) log.writeLog(printPrefix..'programData: '..M.PROGRAMDATA()) log.writeLog(printPrefix..'programFiles: '..M.PROGRAMFILES()) log.writeLog(printPrefix..'programFilesx86: '..M.PROGRAMFILESx86()) log.writeLog(printPrefix..'appData: '..M.APPDATA()) log.writeLog(printPrefix..'winDir: '..M.WINDIR()) log.writeLog(printPrefix..'commonProgramFiles: '..M.COMMONPROGRAMFILES()) log.writeLog(printPrefix..'commonProgramFilesx86: '..M.COMMONPROGRAMFILESx86()) log.writeLog(printPrefix..'temp: '..M.TEMP()) log.writeLog(printPrefix..'systemDrive: '..M.SYSTEMDRIVE()) log.writeLog(printPrefix..'currentDir: '..M.currentDir()) end end return M
socket.lua
-- socket.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> -- 这个模块仅用于导入 socket/core.dll 模块 -- 要求本 socket.lua 文件与 socket 文件夹位于同一路径下,core.dll 文件位于socket文件夹内 -- 使用时请注意 socket/core.dll 的版本 lua程序的版本是否一致 -- 使用时请注意 x86 与 x64 的区别 -- 导入log模块记录日志 local logEnable, log = pcall(require, "runLog") -- 定义一个模块 local M = {} -- 获取本 socket.lua文件的路径 local current_path = string.sub(debug.getinfo(1).source, 2, string.len("/socket.lua") * -1) local pathSpace = "\\" if string.find(current_path,'/') then pathSpace = '/' end current_path = current_path:gsub(pathSpace..'$','') local x86x64 = 'x86' -- 添加 cpath 路径,以使 lua 可以找到 current_path 路径下的 dll 库 if 'Lua 5.4' == _VERSION then local cpath = "\\luaSocket\\x86\\lua5.4\\?.dll" -- 引入 x86 lua54 版 socket.core if 'x64' == x86x64 then cpath = "\\luaSocket\\x64\\lua5.4\\?.dll" -- 引入 x64 lua54 版 socket.core end cpath = string.gsub(cpath,'\\',pathSpace) -- 调整路径分隔符 package.cpath = package.cpath..';'..current_path..cpath end local socketEnable, socket = pcall(require, "socket.core") -- 加载socket库 M.socketEnable = socketEnable M.socket = socket if not socketEnable then if logEnable then log.writeLog('socketEnable is False') log.writeLog(socket) end end return M
dynamicPhrase_Filter.lua
--[[ Descripttion: version: Author: douyaoyuan Date: 2023-06-01 08:48:23 LastEditors: douyaoyuan LastEditTime: 2023-06-09 13:27:57 --]] --dynamicPhrase_Filter.lua --Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> --本脚本主要用于提供一些与运行环境有关的词条信息 --引入支持模块,处理日期和时间信息 local GUIDEnable, GUID = pcall(require, 'GUID') local sysInfoEnable, sysInfo = pcall(require, 'sysInfo') local socketEnable, socket = pcall(require, "socket") local logEnable, log = pcall(require, "runLog") local utf8StrEnable, utf8Str = pcall(require, 'utf8String') if socketEnable then socketEnable = socket.socketEnable socket = socket.socket end local cands local theCands local candTxt_lower local thisTxt local thisComment local function Filter(input, env) cands={} for cand in input:iter() do --抛出原选项 if nil == cands[cand.text] then yield(cand) cands[cand.text]=true end theCands={} if true then candTxt_lower = cand.text:lower() if ({['id']=true,['标识']=true})[candTxt_lower] then --添加选项 if GUIDEnable then local guidInfo = GUID.guidInfo() table.insert(theCands,{guidInfo.noPunctuations,'GUID'}) table.insert(theCands,{guidInfo.guid,'GUID'}) table.insert(theCands,{guidInfo.withUnderline,'GUID'}) end elseif ({['电脑']=true,['系统']=true,['本机']=true})[candTxt_lower] then if sysInfoEnable then --添加选项 if ({['电脑']=true,['本机']=true})[candTxt_lower] then local computerName = sysInfo.computerName() if '未知' ~= computerName then table.insert(theCands,{computerName,'电脑名'}) end local cpu = sysInfo.PROCESSOR_IDENTIFIER() if '未知' ~= cpu then table.insert(theCands,{cpu,'CPU'}) end local coreCnt = sysInfo.NUMBER_OF_PROCESSORS() if '未知' ~= coreCnt then table.insert(theCands,{coreCnt..'核','Core'}) end end table.insert(theCands,{sysInfo.osName(),'系统'}) end elseif ({['ip']=true})[candTxt_lower] then if socketEnable then --添加选项 local ip = socket.dns.toip(socket.dns.gethostname()) if ip then table.insert(theCands,{ip,'ipv4'}) end local addrinfo = socket.dns.getaddrinfo(socket.dns.gethostname(), nil, {family = "inet6"}) if addrinfo then for _, info in ipairs(addrinfo) do if info.family == "inet6" then table.insert(theCands,{info.addr,'ipv6'}) end end end end elseif ({['用户']=true,['路径']=true})[candTxt_lower] then if sysInfoEnable then --添加选项 if ({['用户']=true})[candTxt_lower] then local userName = sysInfo.userName() if '未知' ~= userName then table.insert(theCands,{userName,'用户名'}) end local homePath = sysInfo.homePath() if '未知' ~= homePath then table.insert(theCands,{homePath,'用户路径'}) end end if ({['路径']=true})[candTxt_lower] then local WINDIR = sysInfo.WINDIR() if '未知' ~= sysInfo.WINDIR() then table.insert(theCands,{WINDIR,'WINDIR'}) end local homePath = sysInfo.homePath() if '未知' ~= homePath then table.insert(theCands,{homePath,'用户路径'}) end local pwd = sysInfo.pwd() if '未知' ~= pwd then table.insert(theCands,{pwd,'pwd'}) end local oldPwd = sysInfo.oldPwd() if '未知' ~= oldPwd then table.insert(theCands,{oldPwd,'oldPwd'}) end local PROGRAMDATA = sysInfo.PROGRAMDATA() if '未知' ~= PROGRAMDATA then table.insert(theCands,{PROGRAMDATA,'PROGRAMDATA'}) end local PROGRAMFILES = sysInfo.PROGRAMFILES() if '未知' ~= PROGRAMFILES then table.insert(theCands,{PROGRAMFILES,'PROGRAMFILES'}) end local PROGRAMFILESx86 = sysInfo.PROGRAMFILESx86() if '未知' ~= PROGRAMFILESx86 then table.insert(theCands,{PROGRAMFILESx86,'PROGRAMFILES(x86)'}) end local COMMONPROGRAMFILESx86 = sysInfo.COMMONPROGRAMFILESx86() if '未知' ~= COMMONPROGRAMFILESx86 then table.insert(theCands,{COMMONPROGRAMFILESx86,'COMMONPROGRAMFILES(x86)'}) end local TEMP = sysInfo.TEMP() if '未知' ~= TEMP then table.insert(theCands,{TEMP,'TEMP'}) end local APPDATA = sysInfo.APPDATA() if '未知' ~= APPDATA then table.insert(theCands,{APPDATA,'APPDATA'}) end end end elseif ({['随机']=true, ['密码']=true})[candTxt_lower] then if '随机' == candTxt_lower then --添加选项,返回一个随机数 table.insert(theCands,{math.random(),'0-1伪随机数'}) end if utf8StrEnable then table.insert(theCands, {utf8Str.newPwd(6), '6位随机密码'}) table.insert(theCands, {utf8Str.newPwd(8), '8位随机密码'}) table.insert(theCands, {utf8Str.newPwd(10, false), '10位随机密码'}) table.insert(theCands, {utf8Str.newPwd(14), '14位随机密码'}) table.insert(theCands, {utf8Str.newPwd(16), '16位随机密码'}) table.insert(theCands, {utf8Str.newPwd(18), '18位随机密码'}) end end end --抛出选项 for idx = 1, #theCands do thisTxt = theCands[idx][1] thisComment = theCands[idx][2] if nil ~= thisTxt and '' ~= thisTxt then if nil == cands[thisTxt] then yield(Candidate("word", cand.start, cand._end, thisTxt, thisComment)) cands[thisTxt] = true end end end end end return Filter
联想词组 滤镜
lua文件夹
phraseExt commonPhrase.txt
# 支持使用   来定义空格,而正常的空格被用于分词 # 常用链接 知乎 https://www.zhihu.com 百度 度娘 www.baidu.com 淘宝 www.taobao.com 谷歌 谷哥 谷姐 www.google.com 画图 几何 画板 https://webgeo-8gn07v0t78c4ca57-1308819187.tcloudbaseapp.com # 常用称呼 运气 华盖 运气 华盖 南冠 囚犯 南冠 囚犯 伉俪 夫妻 伉俪 夫妻 丝竹 音乐 丝竹 音乐 烽烟 战争 狼烟 战争 烽烟 狼烟
phraseExt esAppEmoji.txt
done 完成 搞定 esFs[完成] esDt[Done] get 了解 知道 esFs[了解] esDt[Get] no 不行 esFs[No] esFs[叉号] esDt[打叉] 错 错误 esFs[叉号] esDt[打叉] ok 行 好的 好吧 可以 esFsWxDt[OK] 好 好的 esFs[Yes] esWx[好的] 行 esFs[我看行] esFs[好的] okr 绩效 esFsDt[OKR] ------------------------------- 应用 前缀 微信 Wx 飞书 Fs 钉钉 Dt QQ Qq
phraseExt esUnicode.txt
垃圾 垃圾桶 开水 轮椅 残疾 无障碍 厕所 厕所 男人 男厕 厕所 女人 女厕
phraseExt personal.txt
# 支持使用   来定义空格,而正常的空间被用于分词 # 这个字典用于管理 个人/私人 信息,以便在共享/分享rime配置时,可以方便的将个人信息进行隔离 # 常用联系方式 电话 手机 123456789AB 123456789AC 快递 地址 湖南省长春市快乐区开心社区2栋305室 # 常用办公信息 工号 000000 邮箱 san.zhang@aibaba.com 快递 地址 浙江省杭州市阿里马马集团2号快递收发室 # 其它常用信息 博客 https://www.myblogs.com
phraseExt_Module.lua
-- myPhrase.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> local M={} local dict={} local dictPhraseList={} local dbgFlg = false --引入系统变更处理模块 local ok, sysInfoRes = pcall(require, 'sysInfo') local currentDir = sysInfoRes.currentDir --设置 dbg 开关 local function setDbg(flg) dbgFlg = flg sysInfoRes.setDbg(flg) print('myPhrase dbgFlg is '..tostring(dbgFlg)) end --将这附串拆散成 table local function stringSplit(str,sp,sp1) sp=(type(sp)=="string") and sp or " " if 0==#sp then sp="([%z\1-\127\194-\244][\128-\191]*)" elseif 1==#sp then sp="[^"..(sp=="%" and "%%" or sp).."]*" else sp1=sp1 or "^" str=str:gsub(sp,sp1) sp="[^"..sp1.."]*" end local tab={} for v in str:gmatch(sp) do if ''~=v then table.insert(tab,v) end end return tab end --将文档处理成行数组 local function files_to_lines(...) if dbgFlg then print("--->files_to_lines called here") end local tab=setmetatable({},{__index=table}) local index=1 for i,filename in next,{...} do local fn = io.open(filename) if fn then for line in fn:lines() do if not line or #line > 0 then tab:insert(line) end end fn:close() end end if dbgFlg then print("--->files_to_lines completed here") end return tab end local function dictload(...) -- filename) if dbgFlg then print("-->dictload called here") end local lines=files_to_lines(...) local thisDict={} for i,line in next ,lines do if not line:match("^%s*#") then -- 第一字 # 为注释行 local keys,val = string.match(line,"(.+)\t(%C+)") if nil ~= keys then --尝试对关键字进行空格分割 local keyList = stringSplit(keys,' ') local key='' for idx=1,#keyList do key = keyList[idx] if nil ~= thisDict[key] then --如果该key已经存在,追加在后面,注意加一个空格 thisDict[key] = thisDict[key]..' '..val else thisDict[key] = val end end end end end if dbgFlg then print("-->dictload completed here") end return thisDict end --===========================test======================== local function test(printPrefix) if nil == printPrefix then printPrefix = ' ' end if dbgFlg then print('myPhrase test starting...') end sysInfoRes.test(printPrefix..' ') for k,v in pairs(dict) do if dbgFlg then print(printPrefix..k..'\t'..v) end end end --获取字典中的phraseList local function getPhraseList(k) if nil == k then return {} elseif '' == k then return {} end --尝试获取 dictPhraseList 中 k 的列表 local phraseList = dictPhraseList[k] if nil == phraseList then --phraseList 获取失败,尝试获取 dict 中 k 的字符串 local thisPhrase = dict[k] if nil == thisPhrase then --这个 k 在dict中不存在 phraseList={} elseif thisPhrase == '' then --这个 k 在dict中是空的 phraseList={} else --将获取的 thisPhrase 序列化到 dictPhraseList 中 dictPhraseList[k]=stringSplit(thisPhrase,' ') --再次从 dictPhraseList 中获取 k 的序列 phraseList = dictPhraseList[k] end end return phraseList end function M.init(...) local files={...} --文件名不支持中文,其中 # 开始的行为注释行 table.insert(files,"phraseExt commonPhrase.txt") table.insert(files,"phraseExt esAppEmoji.txt") table.insert(files,"phraseExt esUnicode.txt") table.insert(files,"phraseExt personal.txt") for i,v in next, files do files[i] = currentDir().."/".. v end dict= dictload(table.unpack(files)) --抛出功能函数 M.getPhraseList = getPhraseList M.setDbg = setDbg M.test = test end M.init() return M
phraseExt_Filter.lua
-- myPhrase_Filter.lua -- Copyright (C) 2023 yaoyuan.dou <douyaoyuan@126.com> local dbgFlg = false local ok, res = pcall(require, 'phraseExt_Module') local getPhraseList = res.getPhraseList --最长的comment长度限制 local maxLenOfComment = 250 --设置 dbg 开关 local function setDbg(dbgFlg) res.setDbg(dbgFlg) end --过滤器 local function phraseExt_Filter(input, env) --获取选项增强开关状态 local on = env.engine.context:get_option("phraseExt") --获取应用程序标记状态[由于飞书暂不支持文本转表情的输入,帮使用 and false 将其关闭] local feishuFlg = env.engine.context:get_option("feishuFlg") and false local wechatFlg = env.engine.context:get_option("wechatFlg") local qqFlg = env.engine.context:get_option("qqFlg") local dingdingFlg = env.engine.context:get_option("dingdingFlg") local minttyFlg = env.engine.context:get_option("minttyFlg") local cmdFlg = env.engine.context:get_option("cmdFlg") local pycharmFlg = env.engine.context:get_option("pycharmFlg") local vscodeFlg = env.engine.context:get_option("vscodeFlg") local matchedTxt = '' local esType = '' local esTxt = '' local cands={} local thisTxt for cand in input:iter() do --提交默认选项 if nil == cands[cand.text] then yield(cand) cands[cand.text]=true end if on then local candTxt = cand.text:gsub("%s","") or "" if candTxt ~= "" then --获取增强选项 local phraseList = getPhraseList(candTxt) if #phraseList > 0 then local idx for idx=1,#phraseList do thisTxt=phraseList[idx] if nil == cands[thisTxt] then cands[thisTxt]=true esType,esTxt = string.match(thisTxt,"^es(.+)(%[.+%])$") if nil ~= esType then esType = string.lower(esType) --这是一个表情选项 if feishuFlg and nil ~= string.find(esType,'fs') then --这是一个 feishu 表情,且当前在 feishu 中输入 if nil ~= esTxt then yield(Candidate("word", cand.start, cand._end, esTxt, '')) end elseif wechatFlg and nil ~= string.find(esType,'wx') then --这是一个 wechat 表情,且当前在 wechat 中输入 if nil ~= esTxt then yield(Candidate("word", cand.start, cand._end, esTxt, '')) end elseif qqFlg and nil ~= string.find(esType,'qq') then --这是一个 QQ 表情,且当前在 QQ 中输入 if nil ~= esTxt then yield(Candidate("word", cand.start, cand._end, esTxt, '')) end elseif dingdingFlg and nil ~= string.find(esType,'dt') then --这是一个 dingtalk 表情,且当前在 钉钉 中输入 if nil ~= esTxt then yield(Candidate("word", cand.start, cand._end, esTxt, '')) end end else --这不是一个表情选项 if string.lower(string.sub(thisTxt, 1, 4)) == 'git-' then -- 这是一个以 git 开头的选项,这被认为是一个 git 命令 if minttyFlg or cmdFlg then -- 修剪选项 thisTxt = string.sub(thisTxt, 5) -- git 命令选项只在 cmd 窗口或者是 mitty 窗口才允许输出,以避免造成干扰 yield(Candidate("word", cand.start, cand._end, thisTxt:gsub(" "," "), '')) end elseif string.lower(string.sub(thisTxt, 1, 3)) == 'py-' then -- 这是一个以 py- 开头的选项,这被认为是一个 python 关键字 if pycharmFlg or vscodeFlg then -- 修剪选项 thisTxt = string.sub(thisTxt, 4) -- python 关键字选项只在 pycharm 或者 vscode 中才允许输出, 以避免造成干扰 yield(Candidate("word", cand.start, cand._end, thisTxt:gsub(" "," "), '')) end else yield(Candidate("word", cand.start, cand._end, thisTxt:gsub(" "," "), '')) end end end end end end end end end return phraseExt_Filter
滤镜与字典的区别
作用位置不同
自定义词典
其实是一个 translator 翻译器;或者说 自定义词典 是被 rime 引擎的 translator 翻译器所引用的;或者说 自定义词典 是通过 rime 引擎的 translator 翻译器来起作用的
支持自动调频的
受输入方案的耦合影响,不同的输入方案一般无法直接共享自定义词典
词组滤镜
顾名思义,这是一个rime的Filter滤镜
其起作用的位置在translator之后,其起作用的对象是translator翻译器翻译的词组结果
无法支持自动调频
可以避免输入方案的影响,可以无差异的工作
在lua脚本的加持下,可以对既有词组进行境删改调等操作,功能强大,但相对有一定的编程门槛
汉语拼音输入方案
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
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: [无,空格]
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 -- 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
LaTex输入法配置
latex.schema.yaml
switches: - name: ascii_mode # 默认为中文输出模式 reset: 0 states: [ 中文, 西文 ] - name: full_shape # 字符默认半角输出 reset: 0 states: [ 半角, 全角 ] - name: ascii_punct # 默认使用英文标点 reset: 1 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 translators: - table_translator - punct_translator filters: - uniquifier key_binder: import_preset: default speller: auto_select: true delimiter: " ;'" recognizer: import_preset: default patterns: email: "^[A-Za-z][-_.0-9A-Za-z]*@.*$" url: "^(www[.]|https?:|ftp[.:]|mailto:|file:).*$|^[a-z]+[.].+$" schema: author: - "dyy <douyaoyuan@126.com>" description: "LaTex 公式输入" name: "LaTex" schema_id: latex version: 0.2 speller: alphabet: "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA_|\\/<>-+=^()[]{}<" # 定义输入字符的识别格式 delimiter: " " translator: dictionary: latex spelling_hints: 9
latex.custom.yaml
patch: translator/enable_user_dict: false # false:自动造词及动态词频功能失效;true:启用自动造词和动态词频 style/inline_preedit: false # 是否在输入行内进行预测生成,true 表示不单独显示输入字符 engine/translators/+: # 增加以下翻译器 - lua_translator@latex_translator - lua_translator@latexHelp_translator punctuator: import_preset: symbols half_shape: "-": "-" "|": "|" "^": "^" "]": "]" "[": "[" ")": ")" "(": "(" "<": "<" ">": ">" custom_phrase: encode_commit_history: false disable_user_dict_for_patterns: # - "^z.*$" # 这是原始默认设置 - "^[a-y]{1,3}$" # 三码及以下不使用自动调频、不自动造词
latex.dict.yaml
# Rime dictionary # mim: set ts=8 sw=8 noet: # encoding: utf-8 # # latex - Latex # # dyy <douyaoyuan@126.com> # --- name: latex version: "0.1" sort: by_weight #defaut:使用字典文档顺序;by_weight:使用权重进行排序 use_preset_vocabulary: false ... #关于词表定义及词序权重的说明 #词表定义格式如下: #输出项 编码 权重 #关于权重,数字大者,其在候选框内出现的位置则靠前,如果没有指定权重值,则以词表定时次序排序 #常用组合 $$\textcolor{blue}{解:}$$ qev $$\textcolor{blue}{证:}$$ ygh
lua文件夹
latex_translator.lua
--lua语言中的注释用“--” --声明全局变量 local colorName={"apricot", "aquamarine", "bittersweet", "black", "blue", "bluegreen", "blueviolet", "brickred", "brown", "burntorange", "cadetblue", "carnationpink", "cerulean", "cornflowerblue", "cyan", "dandelion", "darkorchid", "emerald", "forestgreen", "fuchsia", "goldenrod", "gray", "green", "greenyellow", "junglegreen", "lavender", "limegreen", "magenta", "mahogany", "maroon", "melon", "midnightblue", "mulberry", "navyblue", "olivegreen", "orange", "orangered", "orchid", "peach", "periwinkle", "pinegreen", "plum", "processblue", "purple", "rawsienna", "red", "redorange", "redviolet", "rhodamine", "royalblue", "royalpurple", "rubinered", "salmon", "seagreen", "sepia", "skyblue", "springgreen", "tan", "tealblue", "thistle", "turquoise", "violet", "violetred", "white", "wildstrawberry", "yellow", "yellowgreen", "yelloworange" } local xlNamesArry={ {"alph","alpha","Alpha"}, {"beta","beta","Beta"}, {"delt","delta","Delta","varDelta"}, {"epsi","varepsilon ","epsilon ","Epsilon"}, {"gamm","gamma","varGamma","Gamma","digamma"}, {"kapp","kappa","varkappa","Kappa"}, {"iota","iota","Iota"}, {"lamb","lambda","Lambda","varLambda"}, {"omeg","omega","Omega","varOmega"}, {"omic","omicron","Omicron"}, {"upsi","upsilon","Upsilon","varUpsilon"}, {"sigm","sigma","Sigma","varSigma","varsigma"}, {"thet","theta","vartheta","Theta","varTheta"}, {"zeta","zeta","Zeta"}, {"chi","chi","Chi"}, {"eta","eta","Eta"}, {"phi","varphi","phi","Phi","varPhi"}, {"psi","psi","Psi","varPsi"}, {"rho","rho","varrho","Rho"}, {"tau","tau","Tau"}, {"mu","mu","Mu"}, {"nu","nu","Nu"}, {"pi","pi","Pi","varPi","varpi"}, {"xi","xi","Xi","varXi"} } function translator(input, seg) --声名局部变量 local debugFlg=false local returnFlg=false local matchFlg=false local patterns="" local pattern="" local subpattern="" local str="" local subStr_0="" local subStr_1="" local keyW="" local keyW_1="" local keyW_2="" local keyW_3="" local keyW_u="" local keyW_sub="" local varW="" local varW_1="" local varW_2="" local varW_3="" local pos=0 --在候选词中使用 '\r' 或者 '\013' 可以输出换行效果 --在候选词中使用 '\t' 或者 '\009' 可以输出水平制表符 --如果候选词中出现 '\n' 或者 '\010' 输入法程序会卡死退出 if input == "test" and debugFlg then --使用键值的方式,通过单引号表示这是一个字符,而不是 '\0' 转义 yield(Candidate("latex", seg.start, seg._end,"第一行"..'\013'.."第二行"..'\013'.."第三行", " ")) --使用字符的方式,以下两种均可 yield(Candidate("latex", seg.start, seg._end,"第一行"..'\r'.."第二行"..'\r'.."第三行", " ")) yield(Candidate("latex", seg.start, seg._end,"第一行\r第二行\r第三行", " ")) matchFlg=true returnFlg=true elseif input == "help" then --help 作为特殊输入,不做latters翻译 returnFlg=true end if returnFlg then return 0 end --初始化标志位 returnFlg=false matchFlg = false --匹配颜色名称 patterns={"clr[a-z]+"} for idx,pattern in ipairs(patterns) do if string.match(input,pattern)~=nil then str=string.match(input,"("..pattern..")") keyW=string.sub(str,1,3) varW=string.sub(str,4,string.len(str)) if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: ".. pattern..", "..str, " ")) end matchFlg=false for cidx,cname in ipairs(colorName) do if varW==cname then --命名完全相符的 if matchFlg==false then matchFlg=true end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, cname, 1), " ")) end end for cidx,cname in ipairs(colorName) do if varW==string.sub(cname,1,string.len(varW)) then --命名在起始位置的 if matchFlg==false then matchFlg=true end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, cname, 1), " ")) end end for cidx,cname in ipairs(colorName) do if string.find(cname,varW,2)~=nil then --命名在中间位置的 if matchFlg==false then matchFlg=true end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, cname, 1), " ")) end end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end --匹配带颜色的字符片段 patterns={"tc[a-z]+","box[a-z]+"} for idx,pattern in ipairs(patterns) do if string.match(input,pattern)~=nil then str=string.match(input,"("..pattern..")") keyW=string.sub(str,1,2) if keyW=="tc" then varW=string.sub(str,3,string.len(str)) else keyW=string.sub(str,1,3) varW=string.sub(str,4,string.len(str)) end if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: ".. pattern..", "..str, " ")) end matchFlg=false for cidx,cname in ipairs(colorName) do if varW==cname then --命名完全相符的 if matchFlg==false then matchFlg=true end if keyW=="tc" then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\textcolor{"..cname.."}{}", 1), " ")) elseif keyW=="box" then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\fcolorbox{"..cname.."}{white}{}", 1), " ")) end end end for cidx,cname in ipairs(colorName) do if varW==string.sub(cname,1,string.len(varW)) then --命名在起始位置的 if matchFlg==false then matchFlg=true end if keyW=="tc" then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\textcolor{"..cname.."}{}", 1), " ")) elseif keyW=="box" then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\fcolorbox{"..cname.."}{white}{}", 1), " ")) end end end for cidx,cname in ipairs(colorName) do if string.find(cname,varW,2)~=nil then --命名在中间位置的 if matchFlg==false then matchFlg=true end if keyW=="tc" then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\textcolor{"..cname.."}{}", 1), " ")) elseif keyW=="box" then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\fcolorbox{"..cname.."}{white}{}", 1), " ")) end end end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end --4字符关键字匹配 之 反三角函数匹配 patterns={"asin","acos","acos","atan","acot"} for pidx,pattern in ipairs(patterns) do if(string.match(input,pattern)~=nil) then if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: 反三角函数匹配", " ")) end if pattern=="acot" then keyW = "{\\rm arccot}" elseif pattern=="arccot" then keyW = "{\\rm arccot}" else keyW = "\\"..string.sub(pattern,1,1).."rc"..string.sub(pattern,2) end local thisPattern="" --匹配希腊字母参数 for xlidx,xlNames in ipairs(xlNamesArry) do local nameKey=xlNames[1] --生成xl字符名称 local names={} for k,v in ipairs(xlNames) do if k>1 then table.insert(names,v) end end if(string.match(input,pattern..".+_")~=nil) then --匹配希腊字母带下标 thisPattern=pattern..nameKey.."_" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{n}}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{0}}",1), " ")) end --标记过程状态 matchFlg=true end elseif(string.match(input,pattern..".+^")~=nil) then --匹配希腊字母本身带上标 thisPattern=pattern..nameKey.."^" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."^{n}}",1), " ")) end --标记过程状态 matchFlg=true end else --匹配希腊字母本身 thisPattern=pattern..nameKey if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}{\\"..name.."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}{\\"..name.."}",1), " ")) end --标记过程状态 matchFlg=true end end if matchFlg then break end end if matchFlg then break end --匹配正常字母参数 thisPattern=pattern.."[a-zA-Z][_^]?" if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(pattern)+1,string.len(pattern)+1) varW_1=string.sub(str,string.len(str)) if varW_1=='_' then --匹配正常字母参数,带下标 for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{n}}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{0}}",1), " ")) --标记过程状态 matchFlg=true elseif varW_1=='^' then --匹配正常字母参数,带上标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{n}}",1), " ")) --标记过程状态 matchFlg=true else --匹配正常字母参数,无上下标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}{"..varW.."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}{"..varW.."}",1), " ")) --标记过程状态 matchFlg=true end end if matchFlg then break end --匹配无参数 thisPattern=pattern if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."()",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}()",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}()",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end --3字符关键字匹配 之 反双曲函数匹配 patterns={"ash","ach","ath"} for pidx,pattern in ipairs(patterns) do if(string.match(input,pattern)~=nil) then if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: 反双曲函数匹配", " ")) end keyW = "{\\rm "..string.sub(pattern,1,1)..'r'..string.sub(pattern,2).."}" local thisPattern="" --匹配希腊字母参数 for xlidx,xlNames in ipairs(xlNamesArry) do local nameKey=xlNames[1] --生成xl字符名称 local names={} for k,v in ipairs(xlNames) do if k>1 then table.insert(names,v) end end if(string.match(input,pattern..".+_")~=nil) then --匹配希腊字母带下标 thisPattern=pattern..nameKey.."_" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{n}}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{0}}",1), " ")) end --标记过程状态 matchFlg=true end elseif(string.match(input,pattern..".+^")~=nil) then --匹配希腊字母本身带上标 thisPattern=pattern..nameKey.."^" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."^{n}}",1), " ")) end --标记过程状态 matchFlg=true end else --匹配希腊字母本身 thisPattern=pattern..nameKey if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}{\\"..name.."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}{\\"..name.."}",1), " ")) end --标记过程状态 matchFlg=true end end if matchFlg then break end end if matchFlg then break end --匹配正常字母参数 thisPattern=pattern.."[a-zA-Z][_^]?" if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(pattern)+1,string.len(pattern)+1) varW_1=string.sub(str,string.len(str)) if varW_1=='_' then --匹配正常字母参数,带下标 for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{n}}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{0}}",1), " ")) --标记过程状态 matchFlg=true elseif varW_1=='^' then --匹配正常字母参数,带上标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{n}}",1), " ")) --标记过程状态 matchFlg=true else --匹配正常字母参数,不带上下标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}{"..varW.."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}{"..varW.."}",1), " ")) --标记过程状态 matchFlg=true end end if matchFlg then break end --匹配无参数 thisPattern=pattern if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."()",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}()",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}()",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end --5字符关键字匹配 之 双曲函数匹配 patterns={"sech","csch","sh","ch","th","cth"} for pidx,pattern in ipairs(patterns) do if(string.match(input,pattern)~=nil) then if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: 双曲三角函数匹配", " ")) end if pattern=="sech" then keyW = "{\\rm sech}" elseif pattern=="csch" then keyW = "{\\rm csch}" elseif pattern=="sinh" then keyW = "\\sh" elseif pattern=="cosh" then keyW = "\\ch" elseif pattern=="tanh" then keyW = "\\th" elseif pattern=="coth" then keyW = "\\cth" else keyW = "\\"..pattern end local thisPattern="" --匹配希腊字母参数 for xlidx,xlNames in ipairs(xlNamesArry) do local nameKey=xlNames[1] --生成xl字符名称 local names={} for k,v in ipairs(xlNames) do if k>1 then table.insert(names,v) end end if(string.match(input,pattern..".+_")~=nil) then --匹配希腊字母带下标 thisPattern=pattern..nameKey.."_" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{n}}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{0}}",1), " ")) end --标记过程状态 matchFlg=true end elseif(string.match(input,pattern..".+^")~=nil) then --匹配希腊字母本身带上标 thisPattern=pattern..nameKey.."^" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."^{n}}",1), " ")) end --标记过程状态 matchFlg=true end else --匹配希腊字母本身 thisPattern=pattern..nameKey if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}{\\"..name.."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}{\\"..name.."}",1), " ")) end --标记过程状态 matchFlg=true end end if matchFlg then break end end if matchFlg then break end --匹配正常字母参数 thisPattern=pattern.."[a-zA-Z][_^]?" if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(pattern)+1,string.len(pattern)+1) varW_1=string.sub(str,string.len(str)) if varW_1=='_' then --匹配正常字母参数,带下标 for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{n}}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{0}}",1), " ")) --标记过程状态 matchFlg=true elseif varW_1=='^' then --匹配正常字母参数,带上标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{n}}",1), " ")) --标记过程状态 matchFlg=true else --匹配正常字母参数,不带上下标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}{"..varW.."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}{"..varW.."}",1), " ")) --标记过程状态 matchFlg=true end end if matchFlg then break end --匹配无参数 thisPattern=pattern if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."()",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}()",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}()",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end --4+字符关键字匹配 之 微商匹配 patterns={"d[a-zA-Z]+d[a-zA-Z]+_?"} for pidx,pattern in ipairs(patterns) do if(string.match(input,pattern)~=nil) then if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: 微商匹配", " ")) end local thisPattern="" --匹配希腊字母因变量 for bidx,yNames in ipairs(xlNamesArry) do local yNameKey=yNames[1] if(string.match(input,"d"..yNameKey.."d[a-zA-Z]+_?")~=nil) then --生成xl字符名称 local yNameNames={} for k,v in ipairs(yNames) do if k>1 then table.insert(yNameNames,v) end end --匹配希腊字母自变量 for xidx,xNames in ipairs(xlNamesArry) do local xNameKey=xNames[1] --生成xl字符名称 local xNameNames={} for k,v in ipairs(xNames) do if k>1 then table.insert(xNameNames,v) end end --带下标场景 thisPattern="d"..yNameKey.."d"..xNameKey.."_" if(string.match(input,thisPattern)~=nil) then --dpsidphi_类的输入 for fk,fn in ipairs(yNameNames) do for xk,xn in ipairs(xNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d\\"..fn.."}{d\\"..xn.."}\\right|_{\\"..xn.."=0}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d^{"..tostring(i).."}\\"..fn.."}{d\\"..xn.."^{"..tostring(i).."}}\\right|_{\\"..xn.."=0}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d^{n}\\"..fn.."}{d\\"..xn.."^{n}}\\right|_{\\"..xn.."=0}",1), " ")) end end --标记过程状态 matchFlg=true end if matchFlg then break end --不带下标场景 thisPattern="d"..yNameKey.."d"..xNameKey if(string.match(input,thisPattern)~=nil) then --dpsidphi_类的输入 for fk,fn in ipairs(yNameNames) do for xk,xn in ipairs(xNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\frac{d\\"..fn.."}{d\\"..xn.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\frac{d^{"..tostring(i).."}\\"..fn.."}{d\\"..xn.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\frac{d^{n}\\"..fn.."}{d\\"..xn.."^{n}}",1), " ")) end end --标记过程状态 matchFlg=true end if matchFlg then break end end if matchFlg then break end --匹配单字母自变量 --带下标场景 thisPattern="d"..yNameKey.."d[a-zA-Z]_" if(string.match(input,thisPattern)~=nil) then --dpsidx_类的输入 str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(str)-1,string.len(str)-1) for fk,fn in ipairs(yNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d\\"..fn.."}{d"..varW.."}\\right|_{"..varW.."=0}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d^{"..tostring(i).."}\\"..fn.."}{d"..varW.."^{"..tostring(i).."}}\\right|_{"..varW.."=0}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d^{n}\\"..fn.."}{d"..varW.."^{n}}\\right|_{"..varW.."=0}",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end --不带下标场景 thisPattern="d"..yNameKey.."d[a-zA-Z]" if(string.match(input,thisPattern)~=nil) then --dpsidx_类的输入 str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(str)) for fk,fn in ipairs(yNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d\\"..fn.."}{d"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d^{"..tostring(i).."}\\"..fn.."}{d"..varW.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d^{n}\\"..fn.."}{d"..varW.."^{n}}",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end end end if matchFlg then returnFlg=true break end --匹配单字母因变量,匹配希腊字母自变量 for xidx,xNames in ipairs(xlNamesArry) do local xNameKey=xNames[1] --生成xl字符名称 local xNameNames={} for k,v in ipairs(xNames) do if k>1 then table.insert(xNameNames,v) end end --带下标场景 thisPattern="d[a-zA-Z]d"..xNameKey.."_" if(string.match(input,thisPattern)~=nil) then --dpsidx_类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,2,2) for xk,xn in ipairs(xNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d"..varW_1.."}{d\\"..xn.."}\\right|_{\\"..xn.."=0}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d^{"..tostring(i).."}"..varW_1.."}{d\\"..xn.."^{"..tostring(i).."}}\\right|_{\\"..xn.."=0}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d^{n}"..varW_1.."}{d\\"..xn.."^{n}}\\right|_{\\"..xn.."=0}",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end --不带下标场景 thisPattern="d[a-zA-Z]d"..xNameKey if(string.match(input,thisPattern)~=nil) then --dpsidx_类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,2,2) for xk,xn in ipairs(xNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d"..varW_1.."}{d\\"..xn.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d^{"..tostring(i).."}"..varW_1.."}{d\\"..xn.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d^{n}"..varW_1.."}{d\\"..xn.."^{n}}",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end end if matchFlg then returnFlg=true break end --匹配单字母因变量,匹配单字母自变量,带下标场景 thisPattern="d[a-zA-Z]d[a-zA-Z]_" if(string.match(input,thisPattern)~=nil) then --dydx_类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,2,2) varW_2=string.sub(str,4,4) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d"..varW_1.."}{d"..varW_2.."}\\right|_{"..varW_2.."=0}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d^{"..tostring(i).."}"..varW_1.."}{d"..varW_2.."^{"..tostring(i).."}}\\right|_{"..varW_2.."=0}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\left.\\cfrac{d^{n}"..varW_1.."}{d"..varW_2.."^{n}}\\right|_{"..varW_2.."=0}",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end --匹配单字母因变量,匹配单字母自变量,不带下标场景 thisPattern="d[a-zA-Z]d[a-zA-Z]" if(string.match(input,thisPattern)~=nil) then --dydx类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,2,2) varW_2=string.sub(str,4,4) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d"..varW_1.."}{d"..varW_2.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d^{"..tostring(i).."}"..varW_1.."}{d"..varW_2.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\cfrac{d^{n}"..varW_1.."}{d"..varW_2.."^{n}}",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end --4字符关键字,latex专用组合 patterns={"[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]"} for pos=1,string.len(input) do matchFlg=false for idx,pattern in ipairs(patterns) do if string.match(input,pattern,pos)~=nil then str=string.match(input,"("..pattern..")",pos) if pos==1 then subStr_0="" else subStr_0=string.sub(input,1,pos-1) end subStr_1=string.sub(input,pos,string.len(input)) if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: latex专用组合,4字符", " ")) end if str=="alig" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{aligned}\r \\end{aligned}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{equation}\\begin{aligned}\r \\end{aligned}\\end{equation}", 1), " ")) matchFlg=true elseif str=="appr" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\approx ", 1), " ")) matchFlg=true elseif str=="arra" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{array}{rl} ab & c \\\\ b & cd \\end{array}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{array}{cc} ab & c \\\\ b & cd \\end{array}", 1), " ")) matchFlg=true elseif str=="beca" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\because ", 1), " ")) matchFlg=true elseif str=="canc" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\cancel{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\xcancel{}", 1), " ")) matchFlg=true elseif str=="case" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{cases}\r ?&=? \\\\ \r\\end{cases}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "x=\\begin{cases}\r ?=? &\\text{if} ? \\\\ \r\\end{cases}", 1), " ")) matchFlg=true elseif str=="disp" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\displaystyle", 1), " ")) matchFlg=true elseif str=="exis" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\exist ", 1), " ")) matchFlg=true elseif str=="fora" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\forall ", 1), " ")) matchFlg=true elseif str=="frac" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\frac{}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\cfrac{}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\dfrac{}{}", 1), " ")) matchFlg=true elseif str=="grou" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\overgroup{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\undergroup{}", 1), " ")) matchFlg=true elseif str=="idxx" then for i=1,10 do yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "式("..tostring(i)..")", 1), " ")) end matchFlg=true elseif str=="infi" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\infin", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "-\\infin", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "+\\infin", 1), " ")) matchFlg=true elseif str=="line" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\overline{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\underline{}", 1), " ")) matchFlg=true elseif str=="matr" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{matrix}\r a & b \\\\\r c & d \r\\end{matrix}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{bmatrix}\r a & b \\\\\r c & d \r\\end{bmatrix}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{pmatrix}\r a & b \\\\\r c & d \r\\end{pmatrix}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{vmatrix}\r a & b \\\\\r c & d \r\\end{vmatrix}", 1), " ")) matchFlg=true elseif str=="nexi" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\nexists ", 1), " ")) matchFlg=true elseif str=="prod" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\prod_{}^{n}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\displaystyle\\prod_{}^{n}{}", 1), " ")) matchFlg=true elseif str=="suba" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{subarray}{c} ab \\\\ c \\end{subarray}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\begin{subarray}{l} ab \\\\ c \\end{subarray}", 1), " ")) matchFlg=true elseif str=="subs" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\substack{ab\\\\c}", 1), " ")) matchFlg=true elseif str=="sout" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\sout{}", 1), " ")) matchFlg=true elseif str=="tria" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\triangleq ", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\vartriangle ", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\vartriangleleft ", 1), " ")) yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\vartriangleright ", 1), " ")) matchFlg=true elseif str=="ther" then yield(Candidate("latex", seg.start, seg._end, subStr_0..string.gsub (subStr_1, pattern, "\\therefore ", 1), " ")) matchFlg=true end end if matchFlg then break end end if matchFlg then returnFlg=true break end end if returnFlg then return 0 end --3+字符关键字匹配 之 log匹配 patterns={"log[a-zA-Z]*_?"} for pidx,pattern in ipairs(patterns) do if(string.match(input,pattern)~=nil) then if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: log匹配", " ")) end local thisPattern="" --匹配希腊字母底 for bidx,bNames in ipairs(xlNamesArry) do local bNameKey=bNames[1] if(string.match(input,"log"..bNameKey.."[a-zA-Z]*_?")~=nil) then --生成xl字符名称 local bNameNames={} for k,v in ipairs(bNames) do if k>1 then table.insert(bNameNames,v) end end --匹配希腊字母自变量 for xidx,xNames in ipairs(xlNamesArry) do local xNameKey=xNames[1] --生成xl字符名称 local xNameNames={} for k,v in ipairs(xNames) do if k>1 then table.insert(xNameNames,v) end end --带下标场景 thisPattern="log"..bNameKey..xNameKey.."_" if(string.match(input,thisPattern)~=nil) then --logpsiphi_类的输入 for bk,bn in ipairs(bNameNames) do for xk,xn in ipairs(xNameNames) do for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}\\"..xn.."_{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}\\"..xn.."_{n}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}\\"..xn.."_{0}",1), " ")) end end --标记过程状态 matchFlg=true end if matchFlg then break end --带上标场景 thisPattern="log"..bNameKey..xNameKey.."^" if(string.match(input,thisPattern)~=nil) then --logpsiphi^类的输入 for bk,bn in ipairs(bNameNames) do for xk,xn in ipairs(xNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}\\"..xn.." ",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}\\"..xn.."^{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}\\"..xn.."^{n}",1), " ")) end end --标记过程状态 matchFlg=true end if matchFlg then break end --不带上下标场景 thisPattern="log"..bNameKey..xNameKey if(string.match(input,thisPattern)~=nil) then --logpsiphi类的输入 for bk,bn in ipairs(bNameNames) do for xk,xn in ipairs(xNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}\\"..xn.." ",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}^{"..tostring(i).."}\\"..xn.." ",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}^{n}\\"..xn.." ",1), " ")) end end --标记过程状态 matchFlg=true end if matchFlg then break end end if matchFlg then break end --匹配单字母自变量,带下标场景 thisPattern="log"..bNameKey.."[a-zA-Z]_" if(string.match(input,thisPattern)~=nil) then --logpsia_类的输入 str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(str)-1,string.len(str)-1) for bk,bn in ipairs(bNameNames) do for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}"..varW.."_{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}"..varW.."_{n}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}"..varW.."_{0}",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end --匹配单字母自变量,带上标场景 thisPattern="log"..bNameKey.."[a-zA-Z]^" if(string.match(input,thisPattern)~=nil) then --logpsia^类的输入 str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(str)-1,string.len(str)-1) for bk,bn in ipairs(bNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}"..varW.." ",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}"..varW.."^{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}"..varW.."^{n}",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end --匹配单字母自变量,不带上下标场景 thisPattern="log"..bNameKey.."[a-zA-Z]" if(string.match(input,thisPattern)~=nil) then --logpsia类的输入 str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(str),string.len(str)) for bk,bn in ipairs(bNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}"..varW.." ",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}^{"..tostring(i).."}"..varW.." ",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}^{n}"..varW.." ",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end --匹配单字母自变量,不带参数场景 thisPattern="log"..bNameKey if(string.match(input,thisPattern)~=nil) then --logpsi类的输入 for bk,bn in ipairs(bNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}()",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}^{"..tostring(i).."}()",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{\\"..bn.."}^{n}()",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end end end if matchFlg then returnFlg=true break end --匹配单字母底,匹配希腊字母自变量 for xidx,xNames in ipairs(xlNamesArry) do local xNameKey=xNames[1] --生成xl字符名称 local xNameNames={} for k,v in ipairs(xNames) do if k>1 then table.insert(xNameNames,v) end end --带下标场景 thisPattern="log[a-zA-Z]"..xNameKey.."_" if(string.match(input,thisPattern)~=nil) then --logapsi_类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,4,4) for xk,xn in ipairs(xNameNames) do for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}\\"..xn.."_{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}\\"..xn.."_{n}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}\\"..xn.."_{0}",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end --带上标场景 thisPattern="log[a-zA-Z]"..xNameKey.."^" if(string.match(input,thisPattern)~=nil) then --logapsi^类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,4,4) for xk,xn in ipairs(xNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}\\"..xn.." ",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}\\"..xn.."^{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}\\"..xn.."^{n}",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end --不带上下标场景 thisPattern="log[a-zA-Z]"..xNameKey if(string.match(input,thisPattern)~=nil) then --logapsi类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,4,4) for xk,xn in ipairs(xNameNames) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}\\"..xn.." ",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}^{"..tostring(i).."}\\"..xn.." ",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}^{n}\\"..xn.." ",1), " ")) end --标记过程状态 matchFlg=true end if matchFlg then break end end if matchFlg then returnFlg=true break end --匹配单字底,匹配单字母自变量,带下标场景 thisPattern="log[a-zA-Z][a-zA-Z]_" if(string.match(input,thisPattern)~=nil) then --logab_类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,4,4) varW_2=string.sub(str,5,5) for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}"..varW_2.."_{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}"..varW_2.."_{n}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}"..varW_2.."_{0}",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end --匹配单字底,匹配单字母自变量,带上标场景 thisPattern="log[a-zA-Z][a-zA-Z]^" if(string.match(input,thisPattern)~=nil) then --logab_类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,4,4) varW_2=string.sub(str,5,5) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}"..varW_2.." ",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}"..varW_2.."^{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}"..varW_2.."^{n}",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end --匹配单字底,匹配单字母自变量,不带上下标场景 thisPattern="log[a-zA-Z][a-zA-Z]" if(string.match(input,thisPattern)~=nil) then --logab_类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,4,4) varW_2=string.sub(str,5,5) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}"..varW_2.." ",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}^{"..tostring(i).."}"..varW_2.." ",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}^{n}"..varW_2.." ",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end --匹配单字母自变量,不带参数场景 thisPattern="log[a-zA-Z]" if(string.match(input,thisPattern)~=nil) then --loga类的输入 str=string.match(input,"("..thisPattern..")") varW_1=string.sub(str,4,4) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}()",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}^{"..tostring(i).."}()",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{"..varW_1.."}^{n}()",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end --匹配无底无参数场景 thisPattern="log" if(string.match(input,thisPattern)~=nil) then --log类的输入 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{?}()",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{?}^{"..tostring(i).."}()",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\log_{?}^{n}()",1), " ")) --标记过程状态 matchFlg=true end returnFlg = matchFlg if returnFlg then break end end end if returnFlg then return 0 end --3+字符关键字 patterns={"lim[a-zA-Z]+"} for idx,pattern in ipairs(patterns) do if string.match(input,pattern)~=nil then str=string.match(input,"("..pattern..")") keyW=string.sub(str,1,3) varW=string.sub(str,4,4) if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: ".. pattern..", "..str, " ")) end if keyW=="lim" then local thisPattern="" --匹配希腊字母参数 for xlidx,xlNames in ipairs(xlNamesArry) do local nameKey=xlNames[1] --生成xl字符名称 local names={} for k,v in ipairs(xlNames) do if k>1 then table.insert(names,v) end end if(string.match(input,pattern..".+_")~=nil) then --匹配希腊字母带下标 thisPattern=keyW..nameKey.."_" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to0}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."_{"..tostring(i).."}".."\\to0}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."_{n}\\to0}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to\\infin}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."_{"..tostring(i).."}".."\\to\\infin}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."_{n}\\to\\infin}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to-\\infin}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."_{"..tostring(i).."}".."\\to-\\infin}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."_{n}\\to-\\infin}{}", 1), " ")) end --标记过程状态 matchFlg=true end elseif(string.match(input,pattern..".+^")~=nil) then --匹配希腊字母本身带上标 thisPattern=keyW..nameKey.."^" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to0}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."^{"..tostring(i).."}".."\\to0}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."^{n}\\to0}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to\\infin}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."^{"..tostring(i).."}".."\\to\\infin}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."^{n}\\to\\infin}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to-\\infin}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."^{"..tostring(i).."}".."\\to-\\infin}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."^{n}\\to-\\infin}{}", 1), " ")) end --标记过程状态 matchFlg=true end else --匹配希腊字母本身 thisPattern=keyW..nameKey if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to0}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to\\infin}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{\\"..name.."\\to-\\infin}{}", 1), " ")) end --标记过程状态 matchFlg=true end end if matchFlg then break end end if matchFlg then break end --匹配正常字母参数 thisPattern=keyW.."[a-zA-Z][_^]?" if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(keyW)+1,string.len(keyW)+1) varW_1=string.sub(str,string.len(str)) if varW_1=='_' then --匹配正常字母参数,带下标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to0}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."_{"..tostring(i).."}".."\\to0}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."_{n}\\to0}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to\\infin}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."_{"..tostring(i).."}".."\\to\\infin}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."_{n}\\to\\infin}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to-\\infin}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."_{"..tostring(i).."}".."\\to-\\infin}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."_{n}\\to-\\infin}{}", 1), " ")) --标记过程状态 matchFlg=true elseif varW_1=='^' then --匹配正常字母参数,带上标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to0}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."^{"..tostring(i).."}".."\\to0}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."^{n}\\to0}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to\\infin}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."^{"..tostring(i).."}".."\\to\\infin}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."^{n}\\to\\infin}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to-\\infin}{}", 1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."^{"..tostring(i).."}".."\\to-\\infin}{}", 1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."^{n}\\to-\\infin}{}", 1), " ")) --标记过程状态 matchFlg=true else --匹配正常字母参数,不带上下标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to0}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to\\infin}{}", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, "\\displaystyle\\"..keyW.."_{"..varW.."\\to-\\infin}{}", 1), " ")) --标记过程状态 matchFlg=true end end if matchFlg then break end end returnFlg=matchFlg if returnFlg then break end end end if returnFlg then return 0 end --3+字符关键字,匹配点 patterns={"dot[-\\_]?"} for idx,pattern in ipairs(patterns) do if string.match(input,pattern)~=nil then str=string.match(input,"("..pattern..")") if string.len(str)==4 then varW=string.sub(str,4,4) else varW="" end if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: ".. pattern..", "..str, " ")) end matchFlg=false if varW=='-' then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\cdots ", 1), " ")) matchFlg=true elseif varW=='_' then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\ldots ", 1), " ")) matchFlg=true elseif varW=='|' then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\vdots ", 1), " ")) matchFlg=true elseif varW=='\\' then yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\ddots ", 1), " ")) matchFlg=true else yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\sdot ", 1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, pattern, "\\dots ", 1), " ")) matchFlg=true end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end --3+字符关键字匹配 之 三角函数匹配 patterns={"sin","cos","tan","cot","sec","csc"} for pidx,pattern in ipairs(patterns) do if(string.match(input,pattern)~=nil) then if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: 三角函数匹配", " ")) end keyW="\\"..pattern local thisPattern="" --匹配希腊字母参数 for xlidx,xlNames in ipairs(xlNamesArry) do local nameKey=xlNames[1] --生成xl字符名称 local names={} for k,v in ipairs(xlNames) do if k>1 then table.insert(names,v) end end if(string.match(input,pattern..".+_")~=nil) then --匹配希腊字母带下标 thisPattern=pattern..nameKey.."_" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{n}}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{0}}",1), " ")) end --标记过程状态 matchFlg=true end elseif(string.match(input,pattern..".+^")~=nil) then --匹配希腊字母本身带上标 thisPattern=pattern..nameKey.."^" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."^{n}}",1), " ")) end --标记过程状态 matchFlg=true end else --匹配希腊字母本身 thisPattern=pattern..nameKey if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}{\\"..name.."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}{\\"..name.."}",1), " ")) end --标记过程状态 matchFlg=true end end if matchFlg then break end end if matchFlg then break end --匹配正常字母参数 thisPattern=pattern.."[a-zA-Z][_^]?" if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(pattern)+1,string.len(pattern)+1) varW_1=string.sub(str,string.len(str)) if varW_1=='_' then --匹配正常字母参数,带下标 for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{n}}",1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{0}}",1), " ")) --标记过程状态 matchFlg=true elseif varW_1=='^' then --匹配正常字母参数,带上标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{"..tostring(i).."}}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{n}}",1), " ")) --标记过程状态 matchFlg=true else --匹配正常字母参数,不带上下标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}{"..varW.."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}{"..varW.."}",1), " ")) --标记过程状态 matchFlg=true end end if matchFlg then break end --匹配无参数 thisPattern=pattern if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."()",1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{"..tostring(i).."}()",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."^{n}()",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end --3+字符关键字匹配 之 abs操作符匹配 patterns={"abs"} for pidx,pattern in ipairs(patterns) do if(string.match(input,pattern)~=nil) then if debugFlg then yield(Candidate("latex", seg.start, seg._end,"latexLetters: abs 操作符匹配", " ")) end keyW="\\left|" keyWEnd="\\right|" local thisPattern="" --匹配希腊字母参数 for xlidx,xlNames in ipairs(xlNamesArry) do local nameKey=xlNames[1] --生成xl字符名称 local names={} for k,v in ipairs(xlNames) do if k>1 then table.insert(names,v) end end if(string.match(input,pattern..".+_")~=nil) then --匹配希腊字母带下标 thisPattern=pattern..nameKey.."_" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{"..tostring(i).."}}"..keyWEnd,1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{n}}"..keyWEnd,1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."_{0}}"..keyWEnd,1), " ")) end --标记过程状态 matchFlg=true end elseif(string.match(input,pattern..".+^")~=nil) then --匹配希腊字母本身带上标 thisPattern=pattern..nameKey.."^" if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}"..keyWEnd,1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}"..keyWEnd.."^{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}"..keyWEnd.."^{n}",1), " ")) end --标记过程状态 matchFlg=true end else --匹配希腊字母本身 thisPattern=pattern..nameKey if(string.match(input,thisPattern)~=nil) then --生成候选词 for k,name in ipairs(names) do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}"..keyWEnd,1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}"..keyWEnd.."^{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{\\"..name.."}"..keyWEnd.."^{n}",1), " ")) end --标记过程状态 matchFlg=true end end if matchFlg then break end end if matchFlg then break end --匹配正常字母参数 thisPattern=pattern.."[a-zA-Z][_^]?" if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") varW=string.sub(str,string.len(pattern)+1,string.len(pattern)+1) varW_1=string.sub(str,string.len(str)) if varW_1=='_' then --匹配正常字母参数,带下标 for i=1,8 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{"..tostring(i).."}}"..keyWEnd,1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{n}}"..keyWEnd,1), " ")) yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."_{0}}"..keyWEnd,1), " ")) --标记过程状态 matchFlg=true elseif varW_1=='^' then --匹配正常字母参数,带上标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}"..keyWEnd,1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{"..tostring(i).."}}"..keyWEnd,1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."^{n}}"..keyWEnd,1), " ")) --标记过程状态 matchFlg=true else --匹配正常字母参数,不带上下标 yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}"..keyWEnd,1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}"..keyWEnd.."^{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{"..varW.."}"..keyWEnd.."^{n}",1), " ")) --标记过程状态 matchFlg=true end end if matchFlg then break end --匹配无参数 thisPattern=pattern if(string.match(input,thisPattern)~=nil) then str=string.match(input,"("..thisPattern..")") yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{?}"..keyWEnd,1), " ")) for i=2,9 do yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{?}"..keyWEnd.."^{"..tostring(i).."}",1), " ")) end yield(Candidate("latex", seg.start, seg._end, string.gsub (input, thisPattern, keyW.."{?}"..keyWEnd.."^{n}",1), " ")) --标记过程状态 matchFlg=true end if matchFlg then returnFlg=true break end end end if returnFlg then return 0 end ...由于博文限制字符数量,无法粘贴完整代码,请下载脚本文档或者在gitHug中查阅
latexHelp_translator.lua
--lua语言中的注释用“--” function translator(input, seg) if (input == "help") then yield(Candidate("help", seg.start, seg._end, "三角函数-->sin|cos|tan|cot|sec|csc", " ")) yield(Candidate("help", seg.start, seg._end, "反三角函数-->asin|acos|atan|acot", " ")) yield(Candidate("help", seg.start, seg._end, "双曲函数-->sh|ch|th|cth|sech|csch", " ")) yield(Candidate("help", seg.start, seg._end, "反双曲函数-->ash|ach|ath", " ")) yield(Candidate("help", seg.start, seg._end, "微分-->d?d?_", " ")) yield(Candidate("help", seg.start, seg._end, "积分-->intc|int", " ")) yield(Candidate("help", seg.start, seg._end, "对数-->log|lg|ln", " ")) yield(Candidate("help", seg.start, seg._end, "极限-->lim", " ")) yield(Candidate("help", seg.start, seg._end, "开方-->sqr", " ")) yield(Candidate("help", seg.start, seg._end, "上标-->?^", " ")) yield(Candidate("help", seg.start, seg._end, "下标-->?_", " ")) yield(Candidate("help", seg.start, seg._end, "线-->bar", " ")) yield(Candidate("help", seg.start, seg._end, "点-->dot", " ")) yield(Candidate("help", seg.start, seg._end, "临域-->mr", " ")) yield(Candidate("help", seg.start, seg._end, "R-->?n?", " ")) yield(Candidate("help", seg.start, seg._end, "颜色名称-->clr", " ")) yield(Candidate("help", seg.start, seg._end, "颜色文本-->tc|box", " ")) yield(Candidate("help", seg.start, seg._end, "特殊字符4-->alig|appr|arra|beca|canc|case|disp|doll|exis|fora|frac|grou|idxx|infi|line|matr|nexi|prod|suba|subs|sout|tria|ther", " ")) yield(Candidate("help", seg.start, seg._end, "特殊字符3-->big|gox|cap|cup|idx|max|min|neq|not|set|sim|sum|tau", " ")) yield(Candidate("help", seg.start, seg._end, "特殊字符2-->in|mp|ni|to|gt|ge|lt|le|", " ")) yield(Candidate("help", seg.start, seg._end, "希腊字符-->alph|beta|其它名称", " ")) --yield(Candidate("help", seg.start, seg._end, "-->", " ")) end end return translator
终极懒人包 m18