Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
whitewatercn committed Jun 15, 2024
1 parent 3339f00 commit 2fed37b
Show file tree
Hide file tree
Showing 7 changed files with 947,427 additions and 54 deletions.
8 changes: 4 additions & 4 deletions rimetool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def main():
parser = get_args_parser()
args = parser.parse_args()

if not os.path.exists('./rimetool_cache'):
os.makedirs('./rimetool_cache')
if not os.path.exists('./rimetool_output'):
os.makedirs('./rimetool_output')
# if not os.path.exists('./rimetool_cache'):
# os.makedirs('./rimetool_cache')
# if not os.path.exists('./rimetool_output'):
# os.makedirs('./rimetool_output')

if args.tool == 'vcf':
vcf.main(args.input_path)
Expand Down
8 changes: 5 additions & 3 deletions rimetool/utils/singleword.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

from datetime import datetime

import re

def main(singleword_file):
current_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
with open(singleword_file, 'r') as infile, open(f'./rimetool_output/singleword.dict.yaml', 'w+') as outfile:
with open(singleword_file, 'r') as infile, open(f'./singleword.dict.yaml', 'w+') as outfile:
outfile.write(
"# 生成工具 https://github.com/whitewatercn/rimetools\n" +
"# 生成时间 " + current_time + "\n" +
"---\n"
)
for line in infile:
line_without_space = line.replace(' ','').strip()
# 删除原单词的标点符号、空格
line_without_space = re.sub(r'[^\w\s]', '', line).replace(' ','').strip()
# 原单词+ tab + 去掉符合、空格的单词 + tab + 1
new_line = str(line.strip() + '\t' + line_without_space + '\t'+str(1) +'\n' )
outfile.write(new_line)

Expand Down
56 changes: 17 additions & 39 deletions rimetool/utils/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,33 @@
from pypinyin import lazy_pinyin
from datetime import datetime



def main(vcf_file):
current_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')

open(f'./rimetool_cache/vcf_cache_contacts_extracted_{current_time}.txt', 'w').close()
open(f'./rimetool_cache/vcf_cache_contacts_without_blank_{current_time}.txt', 'w').close()

# 从vcf文件中提取联系人姓名
with open(vcf_file, 'r') as infile, open(f'./rimetool_cache/vcf_cache_contacts_extracted_{current_time}.txt', 'w') as outfile:
with open(vcf_file, 'r') as infile, open(f'./vcf_mycontacts.dict.yaml.txt', 'w') as outfile:
outfile.write(
"# 生成工具 https://github.com/whitewatercn/rimetools\n" +
"# 生成时间 " + current_time + "\n" +
"---\n"
)
# 遍历输入文件的每一行

for line in infile:
# 检查行是否以'FN:'开头
if line.startswith('FN:'):
# 获取'FN:'后面的内容
content = line[3:]
# 将内容写入输出文件
outfile.write(content)


# 去掉联系人姓名中的空格

with open(f'./rimetool_cache/vcf_cache_contacts_extracted_{current_time}.txt', 'r') as infile, open(f'./rimetool_cache/vcf_cache_contacts_without_blank_{current_time}.txt', 'w') as outfile:
# 遍历输入文件的每一行
for line in infile:
# 删除行尾的换行符
line = line.rstrip('\n')
# 分割行中的单词
words = line.rsplit(' ', 1)
# 如果行中有空格
if len(words) > 1:
# 将倒数第一个空格后面的内容移动到最前面,并删除这个空格
new_line = words[1] + words[0] + '\n'
# 将新的行写入输出文件
outfile.write(new_line)
else:
# 如果行中没有空格,直接将行写入输出文件
outfile.write(line + '\n')

# 转化为rime词典格式
with open(f'./rimetool_cache/vcf_cache_contacts_without_blank_{current_time}.txt', 'r') as infile, open(f'./rimetool_output/vcf_mycontacts.dict.yaml', 'w+') as outfile:
# 遍历输入文件的每一行
outfile.write(
"# 生成工具 https://github.com/whitewatercn/rimetools\n" +
"# 生成时间 " + current_time + "\n" +
"---\n"
)
for line in infile:
# 删除行尾的换行符
# 删除行尾的换行符
words = content.rstrip('\n').rsplit(' ', 1)
# 如果行中有空格z
if len(words) > 1:
# 将倒数第一个空格后面的内容移动到最前面,并删除这个空格
new_line = words[1] + words[0] + '\n'
else:
# 如果行中没有空格,直接将行写入输出文件
line = line+ '\n'
return line
line = line.rstrip('\n')
# 获取行的拼音
pinyin = ''.join(lazy_pinyin(line))
Expand All @@ -62,5 +39,6 @@ def main(vcf_file):
outfile.seek(0)



if __name__ == "__main__":
main()
6 changes: 0 additions & 6 deletions rimetool_output/vcf_mycontacts.dict.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from setuptools import setup, find_packages
from pathlib import Path

setup(
# 以下为必需参数
name='rimetool', # 模块名
version='0.1.2', # 当前版本
version='0.1.3', # 当前版本
description='rime输入法相关工具', # 简短描述
packages=find_packages(include=['rimetool', 'rimetool.*']), # 包含rimetool和rimetool下的所有子包

Expand Down
Loading

0 comments on commit 2fed37b

Please sign in to comment.