emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* table --> org-drill
@ 2019-04-22 13:18 Matt Price
  2019-04-24 13:54 ` Damon Permezel
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Price @ 2019-04-22 13:18 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1382 bytes --]

Hello everyone,

I'm taking an informal but intensive Nepali language class. There's no
textbook, and vocabulary comes rapidly from the teacher during lcass.  I
end up with notes that look like this:

**** yo & tyo-based constructions

*yo*
| yatti  | this much  |
| katti  | how much   |
| yaha   | this place |
| kaahaa | where      |
| yasto  |            |
| kasto  | how        |
| yasari |            |
| kasari |            |

*tyo* and *u*

similar, but over there.  nearly synonymous is "u", which in principle is
reserved for persons, but is used for both. "u" can also be in between yo
and two, between this and that.

- u kosto manche ho? ::  what kind of person is he?
- u kosto manche ho? :: u asal manche ho

---------
So there are two types of notes here --
- vocabulary in a 2-column table (sometimes there is a third or fourth
table, with devenagri and a note of some kind, ubt thosse have been rare)
- example sentences in definition lists -- sometimes they are nepali -->
english, and osmetimes question --> answer

I would like ot convert both these types of construction to flashcards
using org-drill, but doing so by hand would be prohibitively
time-consuming.  Has anyone already written some code to doe these kinds of
ocnversions? My head is so scrambled fro mthis ocurse that it's hard for me
to think in lisp...

THank you!

Matt
I would like to convert

[-- Attachment #2: Type: text/html, Size: 1816 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: table --> org-drill
  2019-04-22 13:18 table --> org-drill Matt Price
@ 2019-04-24 13:54 ` Damon Permezel
  2019-04-24 13:57   ` Damon Permezel
  0 siblings, 1 reply; 4+ messages in thread
From: Damon Permezel @ 2019-04-24 13:54 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 3500 bytes --]

Hi.
I am trying to learn Japanese and I am creating word lists as:

Kanji/Katakana <TAB> Katakana <TAB> meaning

理由	りゆう	reason
地理	ちり	geography
無理な	むりな	impossible
特に	とくに	especially
安い	やすい	cheap

I just now scraped together the following to turn it into org-drill format.
I have not written any elisp for probably at least 40 years so, as they say, よろしくお願いします。
You should be able to munge it for your purposes.

(defun txt-to-TSV ()
  "turn a tab-separated text line into TSV"
  (interactive)
  (save-mark-and-excursion
    (save-restriction
      (let ((beg (progn (beginning-of-line) (point)))
	    (end (progn (forward-line)
			(if (looking-at "\n")
			    (- (point) 1)
			  (point))))
	    (tabs nil)
	    (tsv (vector))
	    (prev nil))

	(narrow-to-region beg end)
	(goto-char beg)
	(setq tabs (vector beg))
	(setq prev beg)
	(while (< (point) end)
	  (if (looking-at "\t")
	      (progn
		(setq tabs (vconcat tabs (vector (point))))
		(setq tsv  (vconcat tsv (vector (buffer-substring prev (point)))))
		(setq prev (+ 1 (point)))))
	  (forward-word))
	(setq tabs (vconcat tabs (vector end)))
	(setq tsv  (vconcat tsv (vector (buffer-substring prev (point)))))
	))
    ))

(defun txt-to-drill (arg)
  "convert TSV to drill"
  (interactive "p")

  (while (> arg 0)
    (setq arg (- arg 1))
    (let ((tsv (txt-to-TSV))
	  (query (concat
		  "*** Query	:drill:\n"
		  "    :PROPERTIES:\n"
		  "    :END:\n"))
	  (answer (concat
		   "**** Answer\n")))
      (if (> (length tsv) 2)
	  (progn
	    (beginning-of-line)
	    (insert "\n" query (aref tsv 0))
	    (insert "\n" answer (aref tsv 1))
	    (let ((i 2))
	      (while (< i (length tsv))
		(insert "\n" (aref tsv i))
		(setq i (+ 1 i))))
	    (insert "\n")
	    (insert "# ")
	    (beginning-of-line)
	    (forward-line)))
      )))



> On 2019-Apr-22, at 23:18, Matt Price <moptop99@gmail.com> wrote:
> 
> Hello everyone,
> 
> I'm taking an informal but intensive Nepali language class. There's no textbook, and vocabulary comes rapidly from the teacher during lcass.  I end up with notes that look like this:
> 
> **** yo & tyo-based constructions
> 
> *yo*
> | yatti  | this much  |
> | katti  | how much   |
> | yaha   | this place |
> | kaahaa | where      |
> | yasto  |            |
> | kasto  | how        |
> | yasari |            |
> | kasari |            |
> 
> *tyo* and *u*
> 
> similar, but over there.  nearly synonymous is "u", which in principle is reserved for persons, but is used for both. "u" can also be in between yo and two, between this and that.
> 
> - u kosto manche ho? ::  what kind of person is he?
> - u kosto manche ho? :: u asal manche ho
> 
> ---------
> So there are two types of notes here --
> - vocabulary in a 2-column table (sometimes there is a third or fourth table, with devenagri and a note of some kind, ubt thosse have been rare)
> - example sentences in definition lists -- sometimes they are nepali --> english, and osmetimes question --> answer
> 
> I would like ot convert both these types of construction to flashcards using org-drill, but doing so by hand would be prohibitively time-consuming.  Has anyone already written some code to doe these kinds of ocnversions? My head is so scrambled fro mthis ocurse that it's hard for me to think in lisp...
> 
> THank you!
> 
> Matt
> I would like to convert


[-- Attachment #1.2: Type: text/html, Size: 14937 bytes --]

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: table --> org-drill
  2019-04-24 13:54 ` Damon Permezel
@ 2019-04-24 13:57   ` Damon Permezel
  2019-04-25  8:14     ` Damon Permezel
  0 siblings, 1 reply; 4+ messages in thread
From: Damon Permezel @ 2019-04-24 13:57 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 3990 bytes --]

Just noticed a bug as I was reading my post.  Just if argument-prefix is applied, it will keep trying a line with no tabs (or less than 2) and not advance the line.  I’m sure there are more….

> On 2019-Apr-24, at 23:54, Damon Permezel <permezel@me.com> wrote:
> 
> Hi.
> I am trying to learn Japanese and I am creating word lists as:
> 
> Kanji/Katakana <TAB> Katakana <TAB> meaning
> 
> 理由	りゆう	reason
> 地理	ちり	geography
> 無理な	むりな	impossible
> 特に	とくに	especially
> 安い	やすい	cheap
> 
> I just now scraped together the following to turn it into org-drill format.
> I have not written any elisp for probably at least 40 years so, as they say, よろしくお願いします。
> You should be able to munge it for your purposes.
> 
> (defun txt-to-TSV ()
>   "turn a tab-separated text line into TSV"
>   (interactive)
>   (save-mark-and-excursion
>     (save-restriction
>       (let ((beg (progn (beginning-of-line) (point)))
> 	    (end (progn (forward-line)
> 			(if (looking-at "\n")
> 			    (- (point) 1)
> 			  (point))))
> 	    (tabs nil)
> 	    (tsv (vector))
> 	    (prev nil))
> 
> 	(narrow-to-region beg end)
> 	(goto-char beg)
> 	(setq tabs (vector beg))
> 	(setq prev beg)
> 	(while (< (point) end)
> 	  (if (looking-at "\t")
> 	      (progn
> 		(setq tabs (vconcat tabs (vector (point))))
> 		(setq tsv  (vconcat tsv (vector (buffer-substring prev (point)))))
> 		(setq prev (+ 1 (point)))))
> 	  (forward-word))
> 	(setq tabs (vconcat tabs (vector end)))
> 	(setq tsv  (vconcat tsv (vector (buffer-substring prev (point)))))
> 	))
>     ))
> 
> (defun txt-to-drill (arg)
>   "convert TSV to drill"
>   (interactive "p")
> 
>   (while (> arg 0)
>     (setq arg (- arg 1))
>     (let ((tsv (txt-to-TSV))
> 	  (query (concat
> 		  "*** Query	:drill:\n"
> 		  "    :PROPERTIES:\n"
> 		  "    :END:\n"))
> 	  (answer (concat
> 		   "**** Answer\n")))
>       (if (> (length tsv) 2)
> 	  (progn
> 	    (beginning-of-line)
> 	    (insert "\n" query (aref tsv 0))
> 	    (insert "\n" answer (aref tsv 1))
> 	    (let ((i 2))
> 	      (while (< i (length tsv))
> 		(insert "\n" (aref tsv i))
> 		(setq i (+ 1 i))))
> 	    (insert "\n")
> 	    (insert "# ")
> 	    (beginning-of-line)
> 	    (forward-line)))
>       )))
> 
> 
> 
>> On 2019-Apr-22, at 23:18, Matt Price <moptop99@gmail.com <mailto:moptop99@gmail.com>> wrote:
>> 
>> Hello everyone,
>> 
>> I'm taking an informal but intensive Nepali language class. There's no textbook, and vocabulary comes rapidly from the teacher during lcass.  I end up with notes that look like this:
>> 
>> **** yo & tyo-based constructions
>> 
>> *yo*
>> | yatti  | this much  |
>> | katti  | how much   |
>> | yaha   | this place |
>> | kaahaa | where      |
>> | yasto  |            |
>> | kasto  | how        |
>> | yasari |            |
>> | kasari |            |
>> 
>> *tyo* and *u*
>> 
>> similar, but over there.  nearly synonymous is "u", which in principle is reserved for persons, but is used for both. "u" can also be in between yo and two, between this and that.
>> 
>> - u kosto manche ho? ::  what kind of person is he?
>> - u kosto manche ho? :: u asal manche ho
>> 
>> ---------
>> So there are two types of notes here --
>> - vocabulary in a 2-column table (sometimes there is a third or fourth table, with devenagri and a note of some kind, ubt thosse have been rare)
>> - example sentences in definition lists -- sometimes they are nepali --> english, and osmetimes question --> answer
>> 
>> I would like ot convert both these types of construction to flashcards using org-drill, but doing so by hand would be prohibitively time-consuming.  Has anyone already written some code to doe these kinds of ocnversions? My head is so scrambled fro mthis ocurse that it's hard for me to think in lisp...
>> 
>> THank you!
>> 
>> Matt
>> I would like to convert
> 


[-- Attachment #1.2: Type: text/html, Size: 15633 bytes --]

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: table --> org-drill
  2019-04-24 13:57   ` Damon Permezel
@ 2019-04-25  8:14     ` Damon Permezel
  0 siblings, 0 replies; 4+ messages in thread
From: Damon Permezel @ 2019-04-25  8:14 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 1789 bytes --]



> On 2019-Apr-24, at 23:57, Damon Permezel <permezel@me.com> wrote:
> 
> Just noticed a bug as I was reading my post.  Just if argument-prefix is applied, it will keep trying a line with no tabs (or less than 2) and not advance the line.  I’m sure there are more….
> 

This version is somewhat better.  It skips comment lines and org headers lines, plus fixes a few bugs, while introducing an equal measure of new ones + 1.

(defun txt-to-TSV ()
  "turn a tab-separated text line into TSV"
  (interactive)
  (save-mark-and-excursion
    (save-restriction
      (let ((beg (progn (beginning-of-line) (point)))
	    (end (progn (end-of-line) (point)))
	    (tsv (vector))
	    (prev nil))

	(narrow-to-region beg end)
	(goto-char beg)
	(when (and (not (= (following-char) ?#))
		   (not (= (following-char) ?*)))
	  (setq prev beg)
	  (while (< (point) end)
	    (when (looking-at "\t")
	      (setq tsv  (vconcat tsv (vector (buffer-substring prev (point)))))
	      (setq prev (+ 1 (point))))
	    (forward-word))

	  (setq tsv (vconcat tsv (vector (buffer-substring prev (point))))))
	tsv
    ))))

(defun txt-to-drill (arg)
  "convert TSV to drill"
  (interactive "p")

  (let ((query (concat
		"*** Query	:drill:\n"
		"    :PROPERTIES:\n"
		"    :END:\n"))
	(answer (concat
		 "**** Answer\n")))
    (while (> arg 0)
      (setq arg (- arg 1))
      (let ((tsv (txt-to-TSV)))
	(if (> (length tsv) 1)
	    (progn
	      (beginning-of-line)
	      (insert "\n" query (aref tsv 0))
	      (insert "\n" answer (aref tsv 1))
	      (let ((i 2))
		(while (< i (length tsv))
		  (insert "\n" (aref tsv i))
		  (setq i (+ 1 i))))
	      (insert "\n")
	      (insert "# ")
	      (beginning-of-line))))
      (forward-line))))


[-- Attachment #1.2: Type: text/html, Size: 7521 bytes --]

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-04-25  8:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-22 13:18 table --> org-drill Matt Price
2019-04-24 13:54 ` Damon Permezel
2019-04-24 13:57   ` Damon Permezel
2019-04-25  8:14     ` Damon Permezel

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).