Skip to content

Commit

Permalink
⚡ Use cpp-pinyin to replace pypinyin
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Nov 27, 2024
1 parent 669cf71 commit 8553253
Show file tree
Hide file tree
Showing 135 changed files with 137,011 additions and 90 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@ jobs:
with:
repository: zdharma-continuum/zunit
path: zunit
- uses: actions/setup-python@v4
with:
python-version: ${{env.python-version}}
cache: ${{env.cache}}
cache-dependency-path: |-
requirements.txt
- name: Install dependencies
run: |
sudo apt-get -y update
sudo apt-get -y install zsh
pip install -r requirements.txt
cd zunit
zsh -c -l ./build.zsh && install -D zunit -t ~/.local/bin
cd ../revolver
Expand Down
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
*.zwc
/tests/_output/

.cache/
*.zwc
# cd module/
# Src/mkmakemod.sh Src/zi Makefile
!module/Src/zi/Makefile.in
COMPILED_AT
compile_commands.json
*.mdh
*.mdhs
*.mdhi
*.export
*.epro
*.pro
*.syms
15 changes: 8 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
# - id: check-added-large-files
- id: fix-byte-order-marker
- id: check-case-conflict
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: trailing-whitespace
# - id: trailing-whitespace
- id: mixed-line-ending
- id: end-of-file-fixer
# - id: end-of-file-fixer
- id: detect-private-key
- id: check-symlinks
- id: check-ast
Expand All @@ -30,16 +30,17 @@ repos:
- id: codespell
additional_dependencies:
- tomli
exclude: module/(Test/|patch_cfgac.diff)
- repo: https://github.com/jorisroovers/gitlint
rev: v0.19.1
hooks:
- id: gitlint
args:
- --msg-filename
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 3.0.3
hooks:
- id: editorconfig-checker
# - repo: https://github.com/editorconfig-checker/editorconfig-checker.python
# rev: 3.0.3
# hooks:
# - id: editorconfig-checker
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ expansions
% cd 自然语言处理/
```

## Dependencies

- [pypinyin](https://github.com/mozillazg/python-pinyin) `>= 0.51.0`

## Install

This plugin respects
Expand Down
72 changes: 72 additions & 0 deletions _pinyin_comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# [:ascii:] need
setopt rematchpcre
local -A _punctuation_map=(
[~]=~
[!]=!
[@]=@
[#]='#'
[$]=$
[%]=%
[&]='&'
[*]=*
[(]='('
[)]=')'
[_]=_
[-]=-
[+]=+
[[]='['
[]]=']'
[「]='['
[」]=']'
[【]='['
[】]=']'
[〔]='['
[〕]=']'
[<]='<'
[>]='>'
[《]='<'
[》]='>'
[«]='<'
[»]='>'
[‹]='<'
[›]='>'
[?]=?
[,]=,
[。]=.
[/]=/
[\]=\\
[、]=\\
[…]=...
)

# unix file names can contain '\n', so use '\0' to separate them
local IFS=$'\0' suffix='' file result k v
local -a files results
if [ "$words[1]" = cd ] ; then
suffix=/
fi
# print -N use '\0' to separate outputs
for file in $(print -nN ${1:h}/*"$suffix"); do
file="${file#./}"
result="$file"
if [[ $result =~ [^[:ascii:]] ]]; then
for k v in ${(kv)FUZZY} ${(kv)_punctuation_map}; do
result="${result//$k/$v}"
done
zpinyin hanziToPinyin $result result
results=(${(s. .)result})
result=
for v in $results; do
k=${v[-1]}
if [[ $k == 1 || $k == 2 || $k == 3 || $k == 4 ]]; then
v="${v[1]}"
fi
result="$result$v"
done
fi
if [[ $result == $1* ]]; then
reply+=(${(q)file})
fi
done

# ex: filetype=zsh
28 changes: 28 additions & 0 deletions _zpinyin
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#compdef zpinyin
local subcommands=(
setDictionaryPath
hanziToPinyin
)

_arguments -s -S \
": :(($subcommands))" \
'*:: :->option-or-argument'

if [[ $state != option-or-argument ]]; then
return
fi
local curcontext=${curcontext%:*:*}:zpinyin-$words[1]:
case $words[1] in
setDictionaryPath)
_dirs
;;
hanziToPinyin)
_arguments -s -S \
{-t,--man_tone_style}"[Pinyin::ManTone::Style]:(0 1 2 8)" \
{-e,--error}"[Pinyin::Error]:(default ignore)" \
{-c,--candidates}"[display candidates]" \
{-v,--v_to_u}"[convert v to u]" \
":hanzi" \
":\$pinyin"
;;
esac
16 changes: 16 additions & 0 deletions module/.cvsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Makefile
META-FAQ
config.cache
config.h
config.h.in
config.log
config.modules
config.modules.sh
config.status
configure
cscope.out
stamp-h
stamp-h.in
autom4te.cache
*.swp
.git
4 changes: 4 additions & 0 deletions module/.distfiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DISTFILES_SRC='
META-FAQ
configure config.h.in stamp-h.in
'
60 changes: 60 additions & 0 deletions module/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Space or Tabs?
# https://stackoverflow.com/questions/35649847/objective-reasons-for-using-spaces-instead-of-tabs-for-indentation
# https://stackoverflow.com/questions/12093748/how-to-use-tabs-instead-of-spaces-in-a-shell-script
# https://github.com/editorconfig/editorconfig-defaults/blob/master/editorconfig-defaults.json
#
# 1. What happens when I press the Tab key in my text editor?
# 2. What happens when I request my editor to indent one or more lines?
# 3. What happens when I view a file containing U+0009 HORIZONTAL TAB characters?
#
# Answers:
#
# 1. Pressing the Tab key should indent the current line (or selected lines) one additional level.
# 2. As a secondary alternative, I can also tolerate an editor that,
# like Emacs, uses this key for a context-sensitive fix-my-indentation command.
# 3. Indenting one or more lines should follow the reigning convention, if consensus is sufficiently strong; otherwise,
# I greatly prefer 2-space indentation at each level. U+0009 characters should shift subsequent characters to the next tab stop.
#
# Note: VIM users should use alternate marks [[[ and ]]] as the original ones can confuse nested substitutions, e.g.: ${${${VAR}}}
#
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.sln]
indent_style = tab

[*.{md,mdx,rst}]
trim_trailing_whitespace = false

[*.{cmd,bat}]
end_of_line = crlf

[*za-*]
end_of_line = lf

[*.{sh,bash,zsh,fish}]
end_of_line = lf

[Makefile]
indent_style = tab
indent_size = 4

[*.{py,rb}]
indent_size = 4

[*.{go,java,scala,groovy,kotlin}]
indent_style = tab
indent_size = 4

[*.{cs,csx,cake,vb,vbx}]
# Default Severity for all .NET Code Style rules below
dotnet_analyzer_diagnostic.severity = warning
Loading

0 comments on commit 8553253

Please sign in to comment.