-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.lisp
85 lines (70 loc) · 2.6 KB
/
3.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;; 20
(ql:quickload :cl-ppcre)
(defun read-json ()
(with-open-file (in "resource/jawiki-country.json")
(let ((ret nil))
(do ((line (read-line in nil nil) (read-line in nil nil)))
((null line) ret)
(push (list
(cons :title (read-from-string (ppcre:regex-replace "\"title\": " (ppcre:scan-to-strings "\"title\": \".*\"" line) "")))
(cons :text (read-from-string (ppcre:regex-replace-all "\\\\n" (ppcre:regex-replace "\"text\": " (ppcre:scan-to-strings "\"text\": \".*\"," line) "") (format nil "~%")))))
ret)))))
(defun search-text (title)
(let ((json (read-json)))
(cdr (assoc :text (find-if (lambda (x) (string= (cdr (assoc :title x)) title))
json)))))
(defparameter england (search-text "イギリス"))
;; 21
(defun find-category (text)
(ppcre:all-matches-as-strings "\\[\\[Category:.*" text))
;; 22
(defun get-category (text)
(let ((categories (find-category text)))
(mapcar (lambda (x) (subseq x 1 (1- (length x))))
(mapcar (lambda (x) (ppcre:scan-to-strings ":.*?]" x)) categories))))
;; 23
(defun find-section (text)
(let ((sectionts (ppcre:all-matches-as-strings "===*.+?===*" text)))
(mapcar (lambda (x) (cons (1- (length (ppcre:scan-to-strings "=+" x)))
x))
sectionts)))
;; 24
(defun find-ref (text)
(mapcar (lambda (x) (subseq x 1 (1- (length x))))
(mapcar (lambda (x) (ppcre:scan-to-strings ":.*?\\|" x)) (ppcre:all-matches-as-strings "\\[File.*?\\]" text))))
;; 25
(ql:quickload :split-sequence)
(use-package :split-sequence)
(defun get-info (text)
(flet ((strip-field-line (x)
(subseq x 0 (1- (length x))))
(remove-bracket (x)
(subseq x 2 (- (length x) 2))))
(let ((template (ppcre:scan-to-strings "{{基礎情報(.*\\n)*}}" text)))
(mapcar (lambda (x)
(when x
(let* ((field-line (split-sequence #\= (subseq (strip-field-line x) 1)))
(field-name (remove #\space (first field-line)))
(field-val (remove #\space (second field-line))))
(cons field-name field-val))))
(ppcre:all-matches-as-strings "\\|.* = ((?!.*<ref).*\\n|.*<ref[\\s\\S]*?( />|</ref>)\\n)" (remove-bracket template))))))
;; 26
(defun remove-emphasis (text)
(ppcre:regex-replace-all "''{1,2}" text ""))
(defun solve (text)
(mapcar (lambda (x) (cons (car x)
(remove-emphasis (cdr x))))
(get-info text)))
;; 27
(defun remove-inner-link (text)
(ppcre:regex-replace-all "\\]\\]"
(ppcre:regex-replace-all "\\[\\[" text "")
""))
(defun solve (text)
(mapcar (lambda (x) (cons (car x)
(remove-inner-link (remove-emphasis (cdr x)))))
(get-info text)))
;; 28
;; i duno meida wiki
;; 29
;; or api