Last active
January 7, 2024 19:00
-
-
Save zonuexe/bd4d183fe641677b2dfcbd250aad389d to your computer and use it in GitHub Desktop.
Emacsから全俳句データベースをブラウザで開く
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; haiku.el --- Access to All Haiku database -*- lexical-binding: t; -*- | |
;; Copyright (C) 2024 USAMI Kenta | |
;; Author: USAMI Kenta <[email protected]> | |
;; Keywords: multimedia | |
;; License: GPL-3.0-or-later | |
;; This program is free software; you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation, either version 3 of the License, or | |
;; (at your option) any later version. | |
;; This program is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; You should have received a copy of the GNU General Public License | |
;; along with this program. If not, see <https://www.gnu.org/licenses/>. | |
;;; Commentary: | |
;; 全俳句データベース https://horicun.moo.jp/contents/haiku/ | |
;;; Code: | |
(require 'cl-lib) | |
(defvar haiku-hiragana | |
'("あ" "い" "う" "え" "お" "か" "き" "く" "け" "こ" "さ" "し" "す" "せ" "そ" "た" "ち" | |
"つ" "て" "と" "な" "に" "ぬ" "ね" "の" "は" "ひ" "ふ" "へ" "ほ" "ま" "み" "む" "め" | |
"も" "や" "ゆ" "よ" "ら" "り" "る" "れ" "ろ" "わ" "を" "が" "ぎ" "ぐ" "げ" "ご" "ざ" | |
"じ" "ず" "ぜ" "ぞ" "だ" "ぢ" "づ" "で" "ど" "ば" "び" "ぶ" "べ" "ぼ" "ぱ" "ぴ" "ぷ" | |
"ぺ" "ぽ" "ぁ" "ぃ" "ぅ" "ぇ" "ぉ" "ゃ" "ゅ" "ょ" "ゎ" "っ" "ゐ" "ゑ" "ー" "ゔ" "ん")) | |
(defun haiku-search-by-number (number) | |
"Convert NUMBER to hiragana." | |
(let ((result-str "") | |
(temp-num (1- number))) | |
(while (> temp-num -1) | |
(setq result-str (concat (nth (mod temp-num 85) haiku-hiragana) result-str)) | |
(setq temp-num (/ temp-num 85)) | |
(when (< temp-num 85) | |
(setq result-str (concat (nth temp-num haiku-hiragana) result-str)) | |
(setq temp-num -1))) | |
(setq result-str (concat (make-string 17 ?あ) result-str)) | |
(setq result-str (substring result-str (- (length result-str) 17))) | |
(format "%s %s %s" | |
(substring result-str 0 5) (substring result-str 5 12) (substring result-str 12)))) | |
(defun haiku-search-exact-match (haiku) | |
"Convert HAIKU to number." | |
(let ((chars (split-string (replace-regexp-in-string (rx (or " " (syntax whitespace))) "" haiku) "" t)) | |
(num 0)) | |
(unless (eq 17 (length chars)) | |
(user-error "Your input in invalid haiku (not matching 5-7-5 characters): %s" haiku)) | |
(cl-loop for char in chars | |
for index = (cl-position char haiku-hiragana :test #'string=) | |
do (setq num (+ (* num 85) index))) | |
(1+ num))) | |
(defun haiku-visit-database (haiku) | |
"Open HAIKU in All Hailu Database." | |
(interactive "sSay Haiku: ") | |
(browse-url (format "https://horicun.moo.jp/contents/haiku/index.html?n=%d" | |
(haiku-search-exact-match haiku))) | |
(message "%s" haiku)) | |
(unless t | |
(haiku-search-by-number 3502664492064230665531090168112) | |
(haiku-search-by-number 3502664492064230665531090168112) | |
(haiku-visit-database "なつくさやつわものどもがゆめのあと") | |
(haiku-visit-database "しんこうをあつめてはやしうしろあし")) | |
(provide 'haiku) | |
;;; haiku.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment