cooperの日記: 実験
日記 by
cooper
#!/usr/bin/env gosh
(use srfi-1)
(define *entries* '())
(define-class <dic-entry> ()
((reading :init-value "" :init-keyword :reading :accessor reading-of)
(word :init-value "" :init-keyword :word :accessor word-of)
(type :init-value 0 :init-keyword :type :accessor type-of)))
(define-method initialize ((self <dic-entry>) initargs)
(next-method)
(push! *entries* self))
(define-method lookup ((entry <dic-entry>) reading)
(if (string=? (reading-of entry) reading)
entry
#f))
(define-method lookup ((entries <list>) reading)
(find (lambda (entry) (lookup entry reading)) entries))
(define-method toru ((entry <dic-entry>) reading)
(if (eq? (string-scan (reading-of entry) reading) 0)
entry
#f))
(define-method toru ((entries <list>) reading)
(find (lambda (entry) (toru entry reading)) entries))
(define-method torutoru ((entries <list>) reading)
(filter-map (lambda (entry) (toru entry reading)) entries))
(define (load-dictionary path)
(set! *entries* '())
(with-input-from-file (sys-normalize-pathname path :expand #t)
(lambda ()
(port-for-each
(lambda (line)
(rxmatch-let (rxmatch #/\(見出し語 \(([^ ]+) .*\(読み ([^\)]+)/ line)
(#f word reading)
(if word
(make <dic-entry> :reading reading :word word :type 0))))
read-line)))
0)
;;; とりあえず、ipadic を読みこむだけのコード
(use srfi-1)
(define *entries* '())
(define-class <dic-entry> ()
((reading :init-value "" :init-keyword :reading :accessor reading-of)
(word :init-value "" :init-keyword :word :accessor word-of)
(type :init-value 0 :init-keyword :type :accessor type-of)))
(define-method initialize ((self <dic-entry>) initargs)
(next-method)
(push! *entries* self))
(define-method lookup ((entry <dic-entry>) reading)
(if (string=? (reading-of entry) reading)
entry
#f))
(define-method lookup ((entries <list>) reading)
(find (lambda (entry) (lookup entry reading)) entries))
(define-method toru ((entry <dic-entry>) reading)
(if (eq? (string-scan (reading-of entry) reading) 0)
entry
#f))
(define-method toru ((entries <list>) reading)
(find (lambda (entry) (toru entry reading)) entries))
(define-method torutoru ((entries <list>) reading)
(filter-map (lambda (entry) (toru entry reading)) entries))
(define (load-dictionary path)
(set! *entries* '())
(with-input-from-file (sys-normalize-pathname path :expand #t)
(lambda ()
(port-for-each
(lambda (line)
(rxmatch-let (rxmatch #/\(見出し語 \(([^ ]+) .*\(読み ([^\)]+)/ line)
(#f word reading)
(if word
(make <dic-entry> :reading reading :word word :type 0))))
read-line)))
0)
;;; とりあえず、ipadic を読みこむだけのコード
実験 More ログイン