-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.lisp
54 lines (51 loc) · 1.51 KB
/
5.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;; 40
(ql:quickload :split-sequence)
(use-package :split-sequence)
(defclass Morph ()
((surface :accessor surface
:initform ""
:initarg :surface)
(base :accessor base
:initform ""
:initarg :base)
(pos :accessor pos
:initform ""
:initarg :pos)
(pos1 :accessor pos1
:initform ""
:initarg :pos1)))
(defmethod print-object ((Morph morph) out)
(print-unreadable-object (Morph out :type t :identity t)
(format out
"~S~T~S,~S,~S"
(surface morph)
(pos morph)
(pos1 morph)
(base morph))))
(defun read-mecab (file)
(labels ((parse-morpheme (line)
(let* ((morpheme-analysis (split-sequence #\tab line))
(surface (first morpheme-analysis))
(analysis (split-sequence #\, (second morpheme-analysis))))
(make-instance 'Morph
:surface surface
:base (nth 6 analysis)
:pos (nth 0 analysis)
:pos1 (nth 1 analysis))))
(read-morpheme (line)
(if (string= line "EOS")
nil
(parse-morpheme line))))
(let ((list-sentences nil)
(temp-sentence nil))
(with-open-file (in file)
(do ((line (read-line in nil nil) (read-line in nil nil)))
((null line) (reverse list-sentences))
(let ((morpheme (read-morpheme line)))
(if morpheme
(push morpheme temp-sentence)
(progn (push (reverse temp-sentence) list-sentences)
(setf temp-sentence nil)))))))))
(defparameter *mecab-list* (read-mecab "resource/neko.txt.mecab"))
;; I can't install cabocha! X(
;; 41