-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage-learn.el
160 lines (129 loc) · 5.46 KB
/
language-learn.el
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
(setq kadir/dilogretio-file "~/.emacs.d/test.org")
(setq kadir/dilogretio-template
'("dilogretio" "Todo" entry (file kadir/dilogretio-file)
"* %?"))
(use-package org-drill
:init
(setq org-drill-save-buffers-after-drill-sessions-p nil)
(setq org-drill-hide-item-headings-p t)
(setq org-drill-add-random-noise-to-intervals-p t)
(setq org-drill-spaced-repetition-algorithm 'simple8)
(setq org-drill-adjust-intervals-for-early-and-late-repetitions-p t))
(defun kadir/dilogretio-google-translate-response(text)
"get `text return full translation of string"
(require 'google-translate)
(with-temp-buffer
(insert text)
(google-translate-buffer)
(let ((buffer-name "*Google Translate*")
(result nil))
(setq result (with-current-buffer (get-buffer buffer-name)
(buffer-substring-no-properties (goto-char (point-min)) (goto-char (point-max)))))
(delete-window (select-window (display-buffer buffer-name)))
(kill-buffer (get-buffer buffer-name))
result)))
(defun kadir/dilogretio-google-translate-basic(text)
(require 'google-translate)
(with-temp-buffer
(google-translate-translate "auto" "tr" text 'current-buffer)
(buffer-string)))
(defun kadir/parse-and-get-direct-translation(full-response)
(with-temp-buffer
(insert full-response)
(goto-char (point-min))
(next-line 4)
(s-trim (thing-at-point 'line))))
(defun kadir/safe-add-org-capture-templates()
(condition-case nil
(unless (member kadir/dilogretio-template org-capture-templates)
(add-to-list 'org-capture-templates kadir/dilogretio-template))
(error
(setq org-capture-templates (list kadir/dilogretio-template)))))
(defun kadir/dilogretio-org-capture-insert-text(text)
(let ((full-response (kadir/dilogretio-google-translate-response text)))
(concat
(concat text " :drill:\n"
":PROPERTIES:\n"
":DRILL_CARD_TYPE: twosided\n"
":END:\n"
"\n"
"** english\n"
text "\n"
"** turkish\n"
(kadir/parse-and-get-direct-translation full-response) "\n"
"** solution\n"
"[[https://dictionary.cambridge.org/tr/s%C3%B6zl%C3%BCk/ingilizce-t%C3%BCrk%C3%A7e/"
text
"][on cambridge link]]\n\n"
"#+begin_src emacs-lisp\n\n")
full-response
"\n" "#+end_src" "\n")))
(defun kadir/dilogretio-org-capture(text)
(interactive)
(kadir/safe-add-org-capture-templates)
(org-capture nil "dilogretio")
(insert (kadir/dilogretio-org-capture-insert-text text)))
(setq posframe-buf-name "*scratch*")
(setq ex-json-data nil)
(defun html-normalize(html-data)
(s-replace
"\\\\" ""
(s-replace
" " " " (org-web-tools--html-to-org-with-pandoc html-data))))
(defun test-on-message (data) ;; TODO rename
"On message callback with DATA."
(let ((json-data (json-parse-string data)))
(when (gethash "score" json-data)
(with-current-buffer (get-buffer-create posframe-buf-name)
(goto-char (point-min))
(insert (format "* SCORE: ~%s~\n\n" (gethash "score" json-data)))))
(when (gethash "title" json-data)
(with-current-buffer (get-buffer-create posframe-buf-name)
(let ((text nil)))
(org-mode)
(setq ex-json-data json-data)
(setq text
(format
"* %s -- \n** %s\n- [%s-%s] %s \n- (replace to ---> ~%s~)"
(gethash "minicardTitle" json-data)
(gethash "title" json-data)
(gethash "highlightBegin" json-data)
(gethash "highlightEnd" json-data)
(gethash "text" json-data)
(gethash "replacements" json-data)))
(when (gethash "explanation" json-data)
(setq text (concat text
(format "\n** explanation\n%s" (html-normalize (gethash "explanation"
json-data))))))
(when (gethash "details" json-data)
(setq text (concat text (format "\n*** details\n%s" (html-normalize (gethash "details"
json-data))))))
(when (gethash "examples" json-data)
(setq text (concat text (format "\n** ex\n%s" (html-normalize (gethash "examples"
json-data))))))
(goto-char (point-max))
(insert text)))))
(defun kadir/gramarly-result-to-buffer(text)
(interactive)
(setq kadir/before-gramarly-selected-frame (selected-frame))
(with-current-buffer (get-buffer-create posframe-buf-name)
(erase-buffer))
(grammarly-check-text text))
(defun kadir/dilogretio()
(interactive)
(let ((text (if (region-active-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(substring-no-properties (car kill-ring)))))
(kadir/dilogretio-org-capture text)))
(defun kadir/gramarly()
(use-package grammarly)
(require 'grammarly)
(require 'json)
(use-package org-web-tools)
(require 'org-web-tools)
(add-to-list 'grammarly-on-message-function-list 'test-on-message)
(interactive)
(let ((text (if (region-active-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(thing-at-point 'sentence t))))
(kadir/gramarly-result-to-buffer text)))