gaboolic / rime-frost

白霜词库:蒹葭苍苍,白露为霜。基于雾凇拼音重制的,更纯净、词频准确、智能的词库。使用745396750字的高质量语料,进行分词,重新统计字频、词频,归一化。白霜词库是目前rime方案下最好的词库,在不使用智能模型的情况下可以超越使用智能模型的词库方案。目前使用白霜词库的方案有:墨奇音形(双拼辅)https://github.com/gaboolic/rime-shuangpin-fuzhuma 、墨奇五笔整句https://github.com/gaboolic/rime-wubi-sentence
GNU General Public License v3.0
575 stars 34 forks source link

打包rime-frost到Arch User Repository中 #69

Open WCX1024979076 opened 4 days ago

WCX1024979076 commented 4 days ago

作者您好,我是rime-frost的新用户+rime的新用户+archlinux用户,这两天我用了一下rime-frost感觉体验良好,所以就想把rime-frost打包到Arch User Repository(AUR)上,之前的雾凇拼音在AUR上有人维护,链接在https://aur.archlinux.org/packages/rime-ice-git,目前我已经写好了AUR打包文件PKGBUILD想征求一下大佬的意见,另附PKGBUILD代码。

# Maintainer: TimWcx

_pkgbase=rime-frost
pkgname=${_pkgbase}-git
pkgver=r210.1daf5e1
pkgrel=1
pkgdesc="Rime 配置:白霜词库 | 蒹葭苍苍,白露为霜。基于雾凇拼音重制的,更纯净、词频准确、智能的词库。"
arch=("any")
url="https://github.com/gaboolic/rime-frost"
license=("GPL-3.0-or-later")
depends=("lua" "librime")
makedepends=("git" "rime-prelude" "sed")
conflicts=(
  rime-emoji
  rime-ice-git
  rime-ice-pinyin-git
  rime-ice-double-pinyin-git
  rime-ice-double-pinyin-abc-git
  rime-ice-double-pinyin-mspy-git
  rime-ice-double-pinyin-sogou-git
  rime-ice-double-pinyin-flypy-git
  rime-ice-double-pinyin-ziguang-git
)
source=("${_pkgbase}::git+${url}.git" "package.patch")
sha512sums=("SKIP" 
be94577ee610847ecb17aa1a22d4341bb124dd1b50a89a06b512e9b16370340e16284268985bebec7472482a9ee8e3b24a84a066829877d8e9e8307d69b6eb0e)

_schemas=(
  rime_frost
  double_pinyin
  double_pinyin_abc
  double_pinyin_mspy
  double_pinyin_sogou
  double_pinyin_flypy
  double_pinyin_ziguang
)

pkgver() {
  cd "${_pkgbase}" &&
    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

_suggestion=${_pkgbase//-/_}_suggestion.yaml

prepare() {
  cd "${_pkgbase}" &&
    mv ./default.yaml "./${_suggestion}" &&
    # Link essentials.
    for _f in $(pacman -Qql rime-prelude | grep -v "/$"); do ln -sf "$_f" .; done &&
    patch --forward --strip=1 --input="../package.patch"
}

build() {
  cd "${_pkgbase}" || return

  _schemas_deps=()
  for _s in "${_schemas[@]}"; do
    _deps=()
    mapfile -t _deps <<< "$(sed -n '/dependencies:/,/^$/ {/dependencies:/d; /^$/d; s/.*- *//g; s/ *#.*//g; p }' "$_s.schema.yaml")"
    _schemas_deps=("${_schemas_deps[@]}" "${_deps[@]}")
  done

  mapfile -t _schemas_deps <<< "$(printf "%s\n" "${_schemas_deps[@]}" | sort -u)"
  # build current schema and it's depends only, sort by length
  _compile_schemas=("${_schemas_deps[@]}" "${_schemas[@]}")

  for _s in "${_compile_schemas[@]}"; do rime_deployer --compile "$_s.schema.yaml"; done

  # comment ignore schemas
  _suggestion_schemas=$(sed -n '/^schema_list:/,/^$/ {/^schema_list:/d; /^\s*#.*$/d; /^$/d; s/.*schema:\s*//g; s/\s*#.*//g; p }' "$_suggestion")

  for _s in $_suggestion_schemas; do
    if [[ ! ${_schemas[*]} =~ (^|[[:space:]])"$_s"($|[[:space:]]) ]]; then
      sed -i "s/^\s*- schema: $_s .*\$/#&/" "$_suggestion";
    fi
  done

  find . -type l -delete
}

package() {
  cd "${_pkgbase}" || return

  _install_base="$pkgdir/usr/share/rime-data"

  install -Dm644 "$_suggestion"       -t "$_install_base/"
  install -Dm644 ./build/*.{bin,yaml} -t "$_install_base/build"

  [ -f "./rime.lua" ] && install -Dm644 ./rime.lua -t "$_install_base/"
  find lua -type f -exec sh -c 'install -Dm644 "$1" -t '"$_install_base"'/$(dirname $1)' shell {} \;

  for _f in *.schema.yaml; do
    if [ -f "build/$_f" ]; then
      install -Dm644 "$_f" -t "$_install_base/"

      grep -q "opencc_config: emoji.json" "$_f" &&
        install -Dm644 ./opencc/* -t "$_install_base/opencc/"
    fi
  done

  for _f in *.dict.yaml; do
    if [ -f "build/${_f/.dict.yaml/}.table.bin" ]; then
      install -Dm644 "$_f" -t "$_install_base/"
    fi
  done

  for _f in */*.dict.yaml; do
    if grep -q "\- ${_f/.dict.yaml/}" "$_install_base/"*.dict.yaml; then
      install -Dm644 "$_f" -t "$_install_base/$(dirname "$_f")"
    fi
  done

  for _f in *.yaml; do
    if grep -q "${_f/.yaml/:}" build/*.schema.yaml; then
      install -Dm644 "$_f" -t "$_install_base/"
    fi
  done
}
gaboolic commented 3 days ago

很好很强大,我不懂AUR 你可以维护在AUR上

Freed-Wu commented 3 days ago

release it to AUR to let us take a try :smile:

Freed-Wu commented 3 days ago

Where is package.patch?

Freed-Wu commented 3 days ago

rime-frost should have a conflicts=(rime-luna-pinyin) and provides=(rime-luna-pinyin). Because it provides same files as rime-luna-pinyin such as double_pinyin_mspy, the only difference is it use rime-frost as dictionary, not rime-luna-pinyin.

WCX1024979076 commented 3 days ago

The patch is to fix a bug (maybe not a bug, only appears in AUR packages). The package installed by AUR needs to be installed under /usr/share/rime-data, which causes lua/aux_code.lua:76 to not find the lua/aux_code/moqi_aux_code.txt file.

package.patch

diff --color --unified --recursive --text rime-frost/lua/aux_code.lua rime-frost-new/lua/aux_code.lua
--- rime-frost/lua/aux_code.lua 2024-10-17 15:06:34.987178552 +0800
+++ rime-frost-new/lua/aux_code.lua 2024-10-17 15:21:06.655348549 +0800
@@ -70,8 +70,9 @@
     local defaultFile = 'moqi_aux_code.txt'
     local userPath = rime_api.get_user_data_dir() .. "/lua/aux_code/"
     local fileAbsolutePath = userPath .. txtpath .. ".txt"
+    local fileRelativePath = '/usr/share/rime-data/'

-    local file = io.open(fileAbsolutePath, "r") or io.open(userPath .. defaultFile, "r")
+    local file = io.open(fileAbsolutePath, "r") or io.open(userPath .. defaultFile, "r")  or io.open(fileRelativePath .. "/lua/aux_code/moqi_aux_code.txt")
     if not file then
         error("Unable to open auxiliary code file.")
         return {}

aux_code.lua (after patch)

function AuxFilter.readAuxTxt(txtpath)
    -- log.info("** AuxCode filter", 'read Aux code txt:', txtpath)

    local defaultFile = 'moqi_aux_code.txt'
    local userPath = rime_api.get_user_data_dir() .. "/lua/aux_code/"
    local fileAbsolutePath = userPath .. txtpath .. ".txt"
    local fileRelativePath = '/usr/share/rime-data/'

    local file = io.open(fileAbsolutePath, "r") or io.open(userPath .. defaultFile, "r")  or io.open(fileRelativePath .. "/lua/aux_code/moqi_aux_code.txt")
    if not file then
        error("Unable to open auxiliary code file.")
        return {}
    end

aux_code.lua (before patch) https://github.com/gaboolic/rime-frost/blob/1daf5e1e8ee087ab6ecf73ac9cbfcfaaf50d59ee/lua/aux_code.lua#L67

WCX1024979076 commented 3 days ago

rime-frost should have a conflicts=(rime-luna-pinyin) and provides=(rime-luna-pinyin). Because it provides same files as rime-luna-pinyin such as double_pinyin_mspy, the only difference is it use rime-frost as dictionary, not rime-luna-pinyin.

OK, I'll change it.

PKGBUILD

# Maintainer: TimWcx <timwcx#qq.com>

_pkgbase=rime-frost
pkgname=${_pkgbase}-git
pkgver=r210.1daf5e1
pkgrel=1
pkgdesc="Rime 配置:白霜词库 | 蒹葭苍苍,白露为霜。基于雾凇拼音重制的,更纯净、词频准确、智能的词库。"
arch=("any")
url="https://github.com/gaboolic/rime-frost"
license=("GPL-3.0-or-later")
depends=("lua" "librime")
makedepends=("git" "rime-prelude" "sed")
conflicts=(
  rime-luna-pinyin
  rime-emoji
  rime-ice-git
  rime-ice-pinyin-git
  rime-ice-double-pinyin-git
  rime-ice-double-pinyin-abc-git
  rime-ice-double-pinyin-mspy-git
  rime-ice-double-pinyin-sogou-git
  rime-ice-double-pinyin-flypy-git
  rime-ice-double-pinyin-ziguang-git
)
provides=(rime-luna-pinyin)
source=("${_pkgbase}::git+${url}.git" "package.patch")
sha512sums=("SKIP" 
be94577ee610847ecb17aa1a22d4341bb124dd1b50a89a06b512e9b16370340e16284268985bebec7472482a9ee8e3b24a84a066829877d8e9e8307d69b6eb0e)

_schemas=(
  rime_frost
  double_pinyin
  double_pinyin_abc
  double_pinyin_mspy
  double_pinyin_sogou
  double_pinyin_flypy
  double_pinyin_ziguang
)

pkgver() {
  cd "${_pkgbase}" &&
    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

_suggestion=${_pkgbase//-/_}_suggestion.yaml

prepare() {
  cd "${_pkgbase}" &&
    mv ./default.yaml "./${_suggestion}" &&
    # Link essentials.
    for _f in $(pacman -Qql rime-prelude | grep -v "/$"); do ln -sf "$_f" .; done &&
    patch --forward --strip=1 --input="../package.patch"
}

build() {
  cd "${_pkgbase}" || return

  _schemas_deps=()
  for _s in "${_schemas[@]}"; do
    _deps=()
    mapfile -t _deps <<< "$(sed -n '/dependencies:/,/^$/ {/dependencies:/d; /^$/d; s/.*- *//g; s/ *#.*//g; p }' "$_s.schema.yaml")"
    _schemas_deps=("${_schemas_deps[@]}" "${_deps[@]}")
  done

  mapfile -t _schemas_deps <<< "$(printf "%s\n" "${_schemas_deps[@]}" | sort -u)"
  # build current schema and it's depends only, sort by length
  _compile_schemas=("${_schemas_deps[@]}" "${_schemas[@]}")

  for _s in "${_compile_schemas[@]}"; do rime_deployer --compile "$_s.schema.yaml"; done

  # comment ignore schemas
  _suggestion_schemas=$(sed -n '/^schema_list:/,/^$/ {/^schema_list:/d; /^\s*#.*$/d; /^$/d; s/.*schema:\s*//g; s/\s*#.*//g; p }' "$_suggestion")

  for _s in $_suggestion_schemas; do
    if [[ ! ${_schemas[*]} =~ (^|[[:space:]])"$_s"($|[[:space:]]) ]]; then
      sed -i "s/^\s*- schema: $_s .*\$/#&/" "$_suggestion";
    fi
  done

  find . -type l -delete
}

package() {
  cd "${_pkgbase}" || return

  _install_base="$pkgdir/usr/share/rime-data"

  install -Dm644 "$_suggestion"       -t "$_install_base/"
  install -Dm644 ./build/*.{bin,yaml} -t "$_install_base/build"

  [ -f "./rime.lua" ] && install -Dm644 ./rime.lua -t "$_install_base/"
  find lua -type f -exec sh -c 'install -Dm644 "$1" -t '"$_install_base"'/$(dirname $1)' shell {} \;

  for _f in *.schema.yaml; do
    if [ -f "build/$_f" ]; then
      install -Dm644 "$_f" -t "$_install_base/"

      grep -q "opencc_config: emoji.json" "$_f" &&
        install -Dm644 ./opencc/* -t "$_install_base/opencc/"
    fi
  done

  for _f in *.dict.yaml; do
    if [ -f "build/${_f/.dict.yaml/}.table.bin" ]; then
      install -Dm644 "$_f" -t "$_install_base/"
    fi
  done

  for _f in */*.dict.yaml; do
    if grep -q "\- ${_f/.dict.yaml/}" "$_install_base/"*.dict.yaml; then
      install -Dm644 "$_f" -t "$_install_base/$(dirname "$_f")"
    fi
  done

  for _f in *.yaml; do
    if grep -q "${_f/.yaml/:}" build/*.schema.yaml; then
      install -Dm644 "$_f" -t "$_install_base/"
    fi
  done
}
WCX1024979076 commented 3 days ago

AUR 已提交 https://aur.archlinux.org/packages/rime-frost-git

gaboolic commented 3 days ago

感谢大家