sobjornstad / AnkiLPCG

Addon for dae/anki for studying lyrics and poetry

Home Page:https://ankilpcg.readthedocs.io/en/latest/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A suggestion for a possible method of using this addon

UrKr opened this issue · comments

First, thank you for this addon, I needed something to organise my revision process.

I'd like to offer an idea.
When memorising something like T.S.Eliot I find that the lines in the poem aren't such a useful unit for dividing the poem.

Instead I like to set all the LPCG values to 1 and then run the poem through this script, which breaks it into sentences and puts each sentence into a separate line. I'm a bit torn as to whether I should count a semicolon as the end of a sentence.

You need to put the poem in poem.txt

Also, I brought in nltk for this, which is a bit overkill, but I already had it installed.

from nltk.tokenize.punkt import PunktSentenceTokenizer, PunktLanguageVars

class MyPunktLanguageVars(PunktLanguageVars):
  sent_end_chars = ('.', '?', '!')

tokenizer = PunktSentenceTokenizer(lang_vars = MyPunktLanguageVars())


# take a poem and split it into sentences and make each sentence a line
def poem_to_sentence_lines(text):
  text = text.strip()
  # remove all single newlines, leave double newlines
  text = text.replace('\n\n', 'placeholder')
  text = text.replace('\n', ' ')
  text = text.replace('placeholder', '\n\n')  
  sentences = tokenizer.tokenize(text)
  return '\n'.join(sentences)

# read the text from a file called poem.txt
def read_poem():
  with open('poem.txt', 'r') as f:
    return f.read()

poem = read_poem()
poem = poem_to_sentence_lines(poem)

with open('poem_out.txt', 'w') as f:
  f.write(poem)

You are then left with something like this for the dry-salvages

I do not know much about gods; but I think that the river Is a strong brown god—sullen, untamed and intractable, Patient to
some degree, at first recognised as a frontier; Useful, untrustworthy, as a conveyor of commerce; Then only a problem confronting the builder of bridges.

The problem once solved, the brown god is almost forgotten By the dwellers in cities—ever, however, implacable.

Keeping his seasons and rages, destroyer, reminder Of what men choose to forget.

Of course the sentences can be quite long if you don't count a semicolon as an ending, but I think it makes sense to learn AND REVISE the whole sentence together.