Two stories on how ANKI can help you learn a foreign language and prepare for an interview

    I always thought that a lazy programmer is a good programmer. Why? Because ask the hardworking to do something, he will go and do it. A lazy programmer will spend 2-3 times more time, but write a script that will - do it for him. Maybe for the first time it will be unreasonably spent a lot of time, but subject to repetitive tasks, this approach pays off very quickly. I consider myself a lazy programmer. It was a preamble, and now let's get down to business.


    First story


    A few years ago I wondered how I could improve my English. Nothing better than reading literature came to mind. An electronic reader was purchased, books were downloaded, and I began to read. In the process of reading unfamiliar words constantly came across. I immediately translated them using the built-in dictionaries, but I noticed one feature: the words did not want to be remembered. When I came across this word again after a few pages, then with 90% probability I again needed a translation, and so every time. The conclusion was that it was not enough just to translate unfamiliar words in the reading process, you need to do something else. An ideal option would be to introduce it into everyday life and start using it, but I do not live in an English-speaking country and this is not possible. Then I remembered that I had once read about Interval repetitions .


    What is it and what does it eat with? In short, there is such a curve of forgetting , then a quote from Wikipedia:


    Already within the first hour, up to 60% of all information received is forgotten, 10 hours after memorization, 35% of the information studied remains in memory. Further, the process of forgetting is slow, and after 6 days about 20% of the total number of syllables that were originally learned remains in memory, the same amount remains in memory after a month.

    And the conclusion is from here


    The conclusions that can be drawn on the basis of this curve are that for effective memorization, it is necessary to repeat the learned material.

    So we came to the idea of interval repetition .


    ANKI is an absolute free open source program that implements the idea of ​​interval repetition. Simply put, computerized flash cards are on one side a question, on the other the answer. Since you can do questions / answers using the usual html / css / javascript , you can say that it has truly unlimited possibilities. In addition, it is extensible with special plugins , and one of them will be very useful to us in the future.


    Manually creating cards is a long, tedious task, and it is very likely that after a while you will kill this business and therefore at some point I asked myself if this business could be automated. The answer is yes, you can. And I did it. I will say right away that this is more POC (Proof of concept) , but which can be used. If there is interest on the part of users and other developers catch up, then it can be brought to a finished product that even technically illiterate users can use. Now, using my utility implies some programming knowledge.


    I read books using AIReader . She has the ability to connect external dictionaries, and when translating a word, she saves the word you called the translation into a text file. The only thing left is to translate these words and create ANKI cards.


    At first I tried to use Google Translate , Lingvo API , etc. to translate . But it didn’t work with free services. I used up the free limit during the development process, in addition, under the terms of the license, I did not have the right to cache words. At some point, I realized that I need to translate the words myself. As a result, the dsl2html module was written to which DSL dictionaries can be connected and which can convert them to HTML format.


    This is how the dictionary entry in * .html looks like , my version in comparison with the GoldenDict variant


    dsl2html vs GoldenDict


    Before searching for a word in connected dictionaries, I bring it to a dictionary form (lemma) using the Stanford CoreNLP library . Actually, because of this library, I started writing in Java and the initial plan was to write everything in Java, but in the process I found the node-java library with which you can relatively easily execute Java code from nodejs and some of the code is written in JavaScript. If I had found this library before, then not a single line would have been written in Java. Another side project that was born in the process is the creation of a repository with DSL documentation that was found on the network in * .chm format , converted and brought into a divine form. If the author of the original file is a user by nicknameyozhic sees this article, thank you very much for the work done, without his documentation I would most likely not succeed.


    So, I have a word in English, its dictionary entry in * .html format , it remains to bring everything together, create ANKI articles from the list of words and add them to the ANKI database. The following data2anki project was created for this purpose . He knows how to take a list of words, translate, create ANKI * .html articles and write them to the ANKI database. At the end of the article, there is an instruction on how to use it. In the meantime, the second story where interval repetition can be useful.


    The second story.


    All people in search of a more / less qualified profession, including programmers, are faced with the need to prepare for an interview. You do not use many concepts that are asked in an interview in everyday practice and they are forgotten. In the next preparation for the interview, scrolling through the compendium, book, reference book, I was faced with the fact that it takes a lot of time and attention to filter out the information that you already know because it is not always obvious and you have to read it in order to understand what it is irrelevant. When you come to a topic that really needs to be repeated, it often happens that you are already tired and the quality of preparation suffers. At some point, I thought, why not use ANKI cards for this? For example, when taking notes on a topic, immediately create a summary in the form of a question - an answer,


    The problem arose only in that it was very long and tedious to fill questions. To facilitate the process, in the data2anki project I added functionality to convert markdown text to ANKI cards. All you need to do is write one large file in which questions and answers will be marked with a predetermined sequence of characters, by which the parser will understand where the question is and where the answer is.


    After this file is created, you start data2anki and it creates ANKI cards. The original file is easy to edit and share, you just need to erase the corresponding card (s) and run the program again, and a new version will be created.


    Installation and use


    1. Install ANKI + AnkiConnect


      1. Download ANKI from here: https://apps.ankiweb.net/
      2. Install AnkiConnect plugin: https://ankiweb.net/shared/info/2055492159

    2. Install data2anki


      1. Download data2anki from github repository
        git clone https://github.com/anatoly314/data2anki
      2. Install dependencies
        cd data2anki && npm install
      3. Download java dependencies https://github.com/anatoly314/data2anki/releases/download/0.1.0/jar-dependencies.zip
      4. Unpack jar-dependencies.zip and put its contents in data2anki / java / jars

    3. Use for translating words:


      1. In file data2anki / config.json :


        • in the mode key, write the value dsl2anki


        • In the key modules.dsl.anki.deckName and modules.dsl.anki.modelName , respectively, register Deck Name and Model Name (should already be created before creating the cards). Now only a model of type Basic is supported :


          Has Front and Back fields, and will create one card. Text you enter in Front will appear on the front of the card, and text you enter in Back will appear on the back of the card.

          where the source word is Front field and the translation will be in Back field .


          There is no problem adding support for Basic (and reversed card) , where a reverse card will be created for the word and translation, where the translation will need to recall the original word. Only the presence of time and desire is needed.


        • in the modules.dsl.dictionariesPath key, you register an array with * .dsl dictionaries connected . Each connected dictionary is a directory in which the dictionary files are located in accordance with the format: DSL dictionary structure


        • In the key modules.dsl.wordToTranslatePath, specify the path to the list of words that you want to translate.



      2. Run when working ANKI application
        node data2anki\index.js
      3. PROFIT !!!

    4. Uses for creating cards from markdown


      1. In file data2anki / config.json :


        • in the mode key, write the value markdown2anki
        • in the key modules.markdown.anki.deckName and modules.dsl.anki.modelName you write, respectively, Deck Name and Model Name (should already be created before creating cards). For markdown2anki mode, only a Basic type model is supported .
        • in the key modules.markdown.selectors.startQuestionSelectors and modules.markdown.selectors.startAnswerSelectors register the selectors with which you mark the beginning of the question and answer, respectively. The line with the selector itself will not be parsed and will not get into the card, the parser will start working from the next line.


          For example, this question / answer card:

          Anki card example


          It will look in markdown as follows:



          # QUESTION #
          ## Question 5. Write a mul function which will work properly when invoked with the following syntax.
          `` `javascript
          console.log (mul (2) (3) (4)); // output: 24
          console.log (mul (4) (3) (4)); // output: 48
          `` ``
          # ANSWER #
          Below is the code followed by the explanation of how it works:
          `` `javascript
          function mul (x) {
            return function (y) {// anonymous function
              return function (z) {// anonymous function
                return x * y * z;
              };
            };
          }
          `` ``
          Here the `mul` function accepts the first argument and returns the anonymous function which takes the second parameter and returns the anonymous function which takes the third parameter and returns the multiplication of arguments which is being passed in successive
          In Javascript function defined inside has access to outer function variable and function is the first class object so it can be returned by the function as well and passed as an argument in another function.
          - A function is an instance of the Object type
          - A function can have properties and has a link back to its constructor method
          - A function can be stored as variable
          - A function can be pass as a parameter to another function
          - A function can be returned from another function
          



          An example is taken from here: 123-JavaScript-Interview-Questions

          There is still a file with examples in the project folder examples/markdown2anki-example.md


        • In the key modules.markdown.pathToFile
          prescribe, the path to the file where the * .md file with questions / answers lies

      2. Run when working ANKI application
        node data2anki\index.js
      3. PROFIT !!!


    This is how it looks on a mobile phone:



    Result


    Полученные на desktop версии ANKI карточки без проблем синхронизируются с ANKI облаком (бесплатно до 100mb), а дальше вы можете пользоваться ими уже везде. Есть клиенты под Android и iPhone, также можно пользоваться и в браузере. В результате, если у вас есть время, которое не на что потратить, то вместо того, чтобы бесцельно пролистывать фейсбук или котиков в инстаграм, можно учить что-то новое.


    Эпилог


    Как я уже упоминал, это скорее рабочий POC, которым можно пользоваться, чем законченный продукт. Где-то процентов 30% стандарта DSL парсера не имплементировано, и поэтому, например не все словарные статьи которые есть в словарях могут быть найдены, также есть идея переписать его на JavaScript, так как хочется "consistency", а кроме того, сейчас он написан не очень оптимально. Сейчас парсер строит дерево, а это помоему лишнее и не нужно усложняет код. В markdown2ankipicture mode is not parsed. I will try to slowly saw, but, as long as I am writing for myself, I will first of all solve the rake that I myself will attack, but if someone wants to help, then we are welcome. If you have questions about the program, I will be happy to help through open issues in the relevant projects. Write the rest of the criticism and suggestions here. I hope someone will find this project useful.


    PS If you notice errors (and they, unfortunately, are), write in a personal, I’ll fix everything.


    Also popular now: