Skip to content
Snippets Groups Projects
Commit cef58865 authored by Peter Vennemann's avatar Peter Vennemann
Browse files

Sorting saved buffer.

parent daabc94b
No related branches found
No related tags found
No related merge requests found
......@@ -2,13 +2,17 @@
;; class for single phrase
(defclass vocab-entry ()
((native :initarg :native :initform "" :type string :documentation "phrase in native lang")
(foreign :initarg :foreign :initform "" :type string :documentation "phrase in foreign lang")
(score :initarg :score :initform 0 :type integer :documentation "score")))
((native :initarg :native :initform "" :type string
:documentation "phrase in native lang")
(foreign :initarg :foreign :initform "" :type string
:documentation "phrase in foreign lang")
(score :initarg :score :initform 0 :type integer
:documentation "score")))
;; class for trainer
(defclass vocab-trainer ()
((entries :initarg :entries :initform nil :type list :documentation "list of phrases")))
((entries :initarg :entries :initform nil :type list
:documentation "list of phrases")))
(defmethod load-vocab ((trainer vocab-trainer))
"Reading phrases from current buffer and saving as objecst."
......@@ -21,24 +25,28 @@
(native (nth 0 parts))
(foreign (nth 1 parts))
(score (string-to-number (nth 2 parts))))
(push (vocab-entry :native native :foreign foreign :score score) (oref trainer entries)))
(push (vocab-entry :native native :foreign foreign :score score)
(oref trainer entries)))
(forward-line 1))))
(defmethod save-vocab ((trainer vocab-trainer))
"Saving phrases with actual scores back to current buffer."
(with-current-buffer (current-buffer)
(erase-buffer)
(dolist (entry (oref trainer entries))
(insert (format "%s | %s | %d\n"
(oref entry native)
(oref entry foreign)
(oref entry score))))
(let ((sorted_entries (cl-sort (copy-sequence (oref trainer entries)) '<
:key (lambda (e) (oref e score)))))
(dolist (entry sorted_entries)
(insert (format "%s | %s | %d\n"
(oref entry native)
(oref entry foreign)
(oref entry score)))))
(save-buffer)))
(defmethod select-weakest ((trainer vocab-trainer))
"Selecting phrases with lowest score."
(cl-subseq (cl-sort (copy-sequence (oref trainer entries)) #'< :key (lambda (e) (oref e score)))
0 12))
(cl-subseq (cl-sort (copy-sequence (oref trainer entries)) '<
:key (lambda (e) (oref e score)))
0 12))
(defmethod train ((trainer vocab-trainer))
"Start training."
......@@ -53,7 +61,8 @@
(oset entry score (1+ (oref entry score)))
(setq words (cdr words)))
(progn
(message "Wrong! Correct answer: %s (press key...)" (oref entry foreign))
(message "Wrong! Correct answer: %s (press key...)"
(oref entry foreign))
(read-char)
(oset entry score (1- (oref entry score))))))))
(save-vocab trainer))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment