Giter Site home page Giter Site logo

pingshuiyun's Introduction

基于python的平水韵查询工具

本工具基于原始的平水韵文档,生成json格式的韵文表,并通过服务器提供查询接口。

一、使用方法

支持两种方式查询

  • 使用终端命令查询
  • 使用浏览器查询

平仄查询涉及的2个脚本:

  • yunServer.py 用于启动查询服务端口
  • load.sh 启动脚本,操纵yunServer.py

1.1 启停服务

# git clone https://github.com/jkak/pingShuiYun.git
# cd pingShuiYun

# ./load.sh
usage ./load.sh [start|stop|status]

# ./load.sh start
started...

# ./load.sh status
python yunServer.py data/baseCharDict.json

started...

# ./load.sh stop

stoped...

1.2 查询操作

终端查询

# search
curl "http://localhost:5000/char?q=明月松间照,清泉石上流": 平 八庚; <br>: 入 六月; <br>: 平 二冬; <br>: 去 十六谏(间开); 平 十五删(中间); <br>: 去 十八啸; <br>: <br>: 平 八庚; <br>: 平 一先; <br>: 入 十一陌; <br>: 上 二十二养; 去 二十三漾; <br>: 平 十一尤; <br>

浏览器查询:

search

二、生成操作

2.1 原始文件

2.2 转换操作

对原文件做如下操作:

  • 将原文件copy出复本。
  • 复本:删除开头的说明
  • 复本:用word替换每个韵部开头**‘声 ’**(声及后面的空白符)换为'=+'。方便python处理。
  • 拷贝复本:
    • 方法一:ctrl-C内容,在vi data/origin.txt文件中ctrl-V。
    • 方法二:word中另存为方式:
      • 存储文件选择:纯文本.txt文件,并存储
      • 文本编码:其他编码,再选择:Unicode(Utf-8)
    • 两种方式仅少量生僻字有差异。

部分过程参考下图:

替换

replace

保存

save

2.3 脚本生成json

# python ./yunGenJson.py data/origin.txt 1>gen.out 2>gen.err

# ls -trl data
total 7816
-rw-r--r--@ 1 song  staff   421376 Oct  8 21:46 平水韵20170714.doc
-rw-r--r--@ 1 song  staff    89967 Oct  8 22:11 origin.txt
-rw-r--r--  1 song  staff    88673 Oct  8 22:13 oriYunDict.json
-rw-r--r--  1 song  staff   843019 Oct  8 22:13 baseCharDict.json
-rw-r--r--  1 song  staff  2552608 Oct  8 22:14 baseIndent.json

# baseCharDict.json 是用于查询的字典。baseIndent.json方便人工查看
python ./readJson.py data/baseCharDict.json > data/baseIndent.json

# 检查一些常用字的平仄是否正常
# python checkChar.py

# python checkChar.py data/baseCharDict.json  看 元
看
   去 十五翰
   平 十四寒
元
   平 十三元

每个字作为key,value是一个列表,因为一个字可能有多个读音,每个读音是一个列表的项。

"临": [["", "二十七沁", ""],   ["", "十二侵", ""]],
"观": [["", "十四寒", "观看"], ["",  "15翰",  "楼观"]]

pingshuiyun's People

Contributors

jkak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.