Move .so file to devel package
[platform/core/uifw/anthy.git] / src-util / anthy-dic.el
1 ;; anthy-dic.el -- Anthy
2
3 ;; Copyright (C) 2001 - 2005
4 ;; Author: Yusuke Tabata<yusuke@w5.dion.ne.jp>
5 ;;       : Tomoharu Ugawa
6
7 ;; This file is part of Anthy
8
9 ;;; Commentary:
10 ;;
11 ;; tooo experimental
12 ;;
13 ;;
14 ;; Funded by IPA\e$BL$F'%=%U%H%&%'%"AOB$;v6H\e(B 2001 11/10
15
16 ;;; Code
17 (defvar anthy-dic-util-command "anthy-dic-tool")
18 (defvar anthy-dic-buffer-name " *anthy-dic*")
19
20 (defun anthy-add-word-compose-paramlist (param)
21   (let ((str ""))
22     (while param
23       (let* ((cur (car param))
24              (var (car cur))
25              (val (if (stringp (car (cdr cur)))
26                       (car (cdr cur))
27                     (if (car (cdr cur)) "y" "n"))))
28         (setq str (concat str
29                           var "\t=\t" val "\n")))
30       (setq param (cdr param)))
31     str))
32
33 (defun anthy-add-word (yomi freq word paramlist)
34   (let ((proc))
35     (setq proc (start-process "anthy-dic" anthy-dic-buffer-name
36                               anthy-dic-util-command "--append"))
37     (if proc
38         (progn
39           (if anthy-xemacs
40               (if (coding-system-p (find-coding-system 'euc-japan))
41                   (set-process-coding-system proc 'euc-japan 'euc-japan))
42             (cond ((coding-system-p 'euc-japan)
43                    (set-process-coding-system proc 'euc-japan 'euc-japan))
44                   ((coding-system-p '*euc-japan*)
45                    (set-process-coding-system proc '*euc-japan* '*euc-japan*))))
46           (process-send-string proc
47                                (concat yomi " " (int-to-string freq) " " word "\n"))
48           (process-send-string proc
49                                (anthy-add-word-compose-paramlist paramlist))
50           (process-send-string proc "\n")
51           (process-send-eof proc)
52           t)
53       nil)))
54
55 (defun anthy-dic-get-noun-category (word)
56   (let
57       ((res '(("\e$BIJ;l\e(B" "\e$BL>;l\e(B")))
58        (na (y-or-n-p (concat "\e$B!V\e(B" word "\e$B$J!W$H8@$$$^$9$+\e(B? ")))
59        (sa (y-or-n-p (concat "\e$B!V\e(B" word "\e$B$5!W$H8@$$$^$9$+\e(B? ")))
60        (suru (y-or-n-p (concat "\e$B!V\e(B" word "\e$B$9$k!W$H8@$$$^$9$+\e(B? ")))
61        (ind (y-or-n-p (concat "\e$B!V\e(B" word "\e$B!W$OC1FH$GJ8@a$K$J$j$^$9$+\e(B? ")))
62        (kaku (y-or-n-p (concat "\e$B!V\e(B" word "\e$B$H!W$H8@$$$^$9$+\e(B? "))))
63     (setq res (cons `("\e$B$J@\B3\e(B" ,na) res))
64     (setq res (cons `("\e$B$5@\B3\e(B" ,sa) res))
65     (setq res (cons `("\e$B$9$k@\B3\e(B" ,suru) res))
66     (setq res (cons `("\e$B8l44$N$_$GJ8@a\e(B" ,ind) res))
67     (setq res (cons `("\e$B3J=u;l@\B3\e(B" ,kaku) res))
68     res))
69
70 (defun anthy-dic-get-special-noun-category (word)
71   (let 
72       ((res '())
73        (cat (string-to-int
74              (read-from-minibuffer "1:\e$B?ML>\e(B 2:\e$BCOL>\e(B: "))))
75     (cond ((= cat 1)
76            (setq res '(("\e$BIJ;l\e(B" "\e$B?ML>\e(B"))))
77           ((= cat 2)
78            (setq res '(("\e$BIJ;l\e(B" "\e$BCOL>\e(B")))))
79     res))
80
81 (defun anthy-dic-get-adjective-category (word)
82   '(("\e$BIJ;l\e(B" "\e$B7AMF;l\e(B")))
83
84 (defun anthy-dic-get-av-category (word)
85   (let
86       ((res '(("\e$BIJ;l\e(B" "\e$BI{;l\e(B")))
87        (to (y-or-n-p (concat "\e$B!V\e(B" word "\e$B$H!W$H8@$$$^$9$+\e(B?")))
88        (taru (y-or-n-p (concat "\e$B!V\e(B" word "\e$B$?$k!W$H8@$$$^$9$+\e(B?")))
89        (suru (y-or-n-p (concat "\e$B!V\e(B" word "\e$B$9$k!W$H8@$$$^$9$+\e(B?")))
90        (ind (y-or-n-p (concat "\e$B!V\e(B" word "\e$B!W$OC1FH$GJ8@a$K$J$j$^$9$+\e(B?"))))
91     (setq res (cons `("\e$B$H@\B3\e(B" ,to) res))
92     (setq res (cons `("\e$B$?$k@\B3\e(B" ,taru) res))
93     (setq res (cons `("\e$B$9$k@\B3\e(B" ,suru) res))
94     (setq res (cons `("\e$B8l44$N$_$GJ8@a\e(B" ,ind) res))
95     res))
96
97 ;; taken from tooltip.el
98 (defmacro anthy-region-active-p ()
99   "Value is non-nil if the region is currently active."
100   (if (string-match "^GNU" (emacs-version))
101       `(and transient-mark-mode mark-active)
102     `(region-active-p)))
103
104 (defun anthy-add-word-interactive ()
105   ""
106   (interactive)
107   (let
108       ((param '()) (res '())
109        (word (if (anthy-region-active-p)
110                  (buffer-substring (region-beginning) (region-end))
111                ""))
112        yomi cat)
113     (and (string= word "")
114          (setq word (read-from-minibuffer "\e$BC18l\e(B(\e$B8l44$N$_\e(B): ")))
115     (setq yomi (read-from-minibuffer (concat "\e$BFI$_\e(B (" word "): ")))
116     (setq cat (string-to-int
117                (read-from-minibuffer
118                 "\e$B%+%F%4%j!<\e(B 1:\e$B0lHLL>;l\e(B 2:\e$B$=$NB>$NL>;l\e(B 3:\e$B7AMF;l\e(B 4:\e$BI{;l\e(B: ")))
119     (cond ((= cat 1)
120            (setq param (anthy-dic-get-noun-category word)))
121           ((= cat 2)
122            (setq param (anthy-dic-get-special-noun-category word)))
123           ((= cat 3)
124            (setq param (anthy-dic-get-adjective-category word)))
125           ((= cat 4)
126            (setq param (anthy-dic-get-av-category word))))
127     (if param
128         (setq res (anthy-add-word yomi 1 word param)))
129     (if res
130         (message (concat word "(" yomi ")\e$B$rEPO?$7$^$7$?\e(B")))))
131
132 (provide 'anthy-dic)