Code Monkey home page Code Monkey logo

learnwords2's Introduction

LearnWords2

A vocabulary learning component for flash cards implementing the Leitner system

Aim

The aim of the project is twofold

  1. Provide a JavaScript library called LW.js which maintains and uses a collection of vocabulary questions in a database. "Database" means here JSON data to be kept in the localStorage. A simple demo GUI is provided which illustrates how LW.js is to be set up and used.
  2. Provide data conversion and report functions for lists of words to learn (the JSON files). This includes the conversion to the Anki file format.

What does the library LW.js implement?

The library offers a learning session which means that a certain number of questions is asked. The number is specified by a setting value. There are questions in the database which have never been asked, questions which are to be learned and questions which are to be reviewed.

A vocabulary question for review is picked at random and then depending on the answer a new date is noted for the question to be asked again. The time interval increases if the question has been answered correctly. To do this a step (or level) value is maintained for each question to determine the time period after which the question might be asked again.

This is known as spaced repetition. Leitner system

It is as well possible to do the selection of questions according to tags given to each vocabulary entry.

The library implements the two lower levels as shown in the diagram: learnwords2-layers

Reports

This repository includes CLI programs to generate HTML and LibreOffice Draw reports for flash cards to be printed.

Setup and usage

Installation of the development environment

Installation of LearnWords2 repository

git clone https://github.com/hhzl/LearnWords2.git
cd LearnWords2
npm install
grunt

Note: The grunt command generates the files in the dist directory. These JavaScript files are the debug and minified versions of the LearnWords2 library (dist/LW.js and dist/LW-debug.js). They are copied to the public/js directory so the demo and Jasmine tests are using the "latest version" (i.e. derived from the JavaScript in src) of the library. The directory public/data/json contains the output data to be used by the library.

Note2: The generation of the browser version of the jasmine tests is currently disabled. Just use

    jasmine

to run the tests on the command line.

Draft of more documentation here.

Use of the library LW.js in client program

To use the library you just need to copy LW.js to the code repo of your app and add it as follows.

<script src="pathTo/LW.js"></script>

The file public/demo.html illustrates this.

API 2 of LW.js

learnwords2-layers

  • LWdb is the data access layer.
  • LWBoxOfQuestions contains the logic for "accessing and moving the cards" (e.g. voculary entries) in the Leitner box

Code:

"use strict";
var lw = function(){

	var db = LW.LWdb('learnWords');

	var box = LW.BoxOfQuestions(db);
         
        // configuration

        .......

        box.importFrom(wordlist);

	return box;
}();

The construction above (IIFE) returns the BoxOfQuestions object ready for use.

If there is no configuration of the db you could as well just do

var lw = LW.BoxOfQuestions(LW.LWdb('learnWords'));
    lw.importFrom(wordlist);

Then access to everything goes through lw.method().

lw.importFrom(....);

lw.question();

lw.answer();
lw.answerOptions();

lw.moveQuestionBackwards();

lw.moveQuestionForward();

Note: If lw.moveQuestionBackwards() and lw.moveQuestionForward() are called repeatedly on the same question it has only an effect the first time. The next time lw.question() is called a new question is provided.

TODO: Add more usage examples and link to the full API description.

Input data

Input data are CSV files with words and pictures in the directory data/csv.

Export data

Export data in as HTML report and Anki database are generated and put into public/data. The data to be used by the library is in public/data/json.

Specification and tests with Jasmine

In the browser

  • on the command line do

    grunt
    
  • then a browser window will launch and bring you to a Jasmine test harness page which is usually http://localhost:8000

On the command line with node

 npm test

Credits

Anatol Marezhanyi, for the https://github.com/e1r0nd/LearnWords project which implements data storage, Leitner box mechanism and a GUI. That project is under reconstruction.

This project here is based on ideas and originally on code from LearnWords but has a different aim:

  1. It implements the non-gui part only to allow other projects to use the SRS and datastorage part as a library
  2. It adds data conversion functions to be used through a CLI for word list preparation and production of printed flash cards.
  3. Most of it is rewritten.
  4. It uses Jasmine tests.

Status

  • Jasmine specs are set up and work both in the browser and on the command line.
  • The LWdb (database layer) specification is set up and implemented with an MVP set of specs.
  • release 0.2.2-beta has a MVP implementation for the Leitner box and may be used for development work.
  • Documentation update in progress
  • release 0.3.1 will come soon.

learnwords2's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

learnwords2's Issues

Create a repository LearnWords2-app-jq

Create a repository LearnWords2-app-jq.
And do a simple LearnWords app which uses jQuery.

This is similar to #19 but instead of just using getElementById in the code jQuery is used.

file jasmine-app-bundle.js too long

The file jasmine-app-bundle.js is so long that the failure messages you get in SpecRunner.html are difficult to interpret. The file has more than 1400 lines because other stuff is added.

Create data directory in root directory

The data directory should probably have subdirectories

  • csv
  • json
  • js
  • xml
  • markdown

which then would host the same data in different formats.

Or alternatively there are subfolders labeled with the nature of the data as for example German-English and that would contain the data in different formats

  • ge-en.csv
  • ge-en.json
  • ge-en.xml
  • ge-en.js
  • ge-en.md

Move method ``invalidateIndex`` to constructor function (becomes priviledged method)

Currently the method is public

LWdb.prototype.invalidateIndex = function() {
   this.recalculateIndex = true;
}

It should go to the constructor function together with the property recalculateIndex which should become a private member of the constructor function.

Make

 indexNeedsRecalculation()

a privileged function and use as private property

indexIsDirty

Thus in the constructor function

 this._invalidateIndex = function() {
      this.indexIsDirty = true;
 }

 this._indexNeedsRecalculation = function() {
      return this.indexIsDirty
 }


 this._indexHasBeenUpdated = function() {
      this.indexIsDirty = false;
 }

Marking the functions with an underscore tells the application programmer that they do not belong to the public API. It is though still possible to call them. The effect this achieves is that the variable indexIsDirty is private and can is cannot be set to something other than a boolean.

Update the functions which have an effect on the index.

npm test: TypeError: object is not a function

Failures:
1) LearnWords2 - App model BoxOfQuestions should be able to create a BoxOfQuestions object
  Message:
    TypeError: object is not a function
  Stack:
    TypeError: object is not a function
        at Object.<anonymous> (/home/user8/Documents/LearnWords2/spec/learnwords2/LWdbSpec.js:70:18)
  Message:
    ReferenceError: questions is not defined
  Stack:
    ReferenceError: questions is not defined
        at Object.<anonymous> (/home/user8/Documents/LearnWords2/spec/learnwords2/LWdbSpec.js:76:12)

In LWdbSpec.js we have

var LWdb = require('../../src/LWdb');
var BoxOfQuestions = require('../../src/BoxOfQuestions');
....

describe("LearnWords2 - App model", function() {

describe("BoxOfQuestions", function() {
  var db;


  beforeEach(function() {
    questions  = new BoxOfQuestions("LWquestions");
  });


  it("should be able to create a BoxOfQuestions object", function() {

    expect(questions).not.toBe(null);
    expect(questions).not.toBe(undefined);

      });

Plan for release 0.1 -- beta2 version released

  • Jasmine set up for browser and node command line.
  • Constructor function for BoxOfQuestions() and some more specs.
  • Have a build process for a release file for use in the browser.
  • Documentation updated so that context information is given.

Plan for release 0.3

Plan for release 0.1 of the component

What needs to be implemented

  • For the math questions no selection from a set of answer options is needed. The answer is just given by a number the user types on the command line.
  • Load the math questions straight once into the db with importFrom command which does a force load. This will use 'putWord'.
  • Have a run command to practice.

How is this developed?

  • Develop this in a separate branch.
  • Tag the issues needed for this release.

See also * #18

GUI with 4 options

Demo GUI

Implement what is given by #19.

Which is something like

<div id="learnWords2-area">
   <div id=question>...</div>
   <div id="optionsForAnswers">
       <div id="option1">...</div>
       <div id="option2">...</div>
       <div id="option3">...</div>
       <div id="option4">...</div>
   </div>
   <div id=feedback>...</div>
</div>

The demo should show what is implemented in release 0.3

npm test error

Branch master

npm test

> [email protected] test /home/user8/Documents/LearnWords2
> node scripts/test.js


module.js:340
    throw err;
          ^
Error: Cannot find module '../../src/BoxOfQuestions'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/user8/Documents/LearnWords2/spec/learnwords2/LWdbSpec.js:2:22)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
npm ERR! weird error 8
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
 
npm ERR! not ok code 0

Docs: developer journal

Create a file 'developer_journal' in a docs directory which states

  • the relationship to LearnWords1
  • the layers of LearnWords2
  • that LearnWords2 focuses on the Non-GUI part (the component)
  • context information
  • misc note
  • plans for extension

npm test - second run fails

npm test

> [email protected] test /home/user8/Documents/LearnWords2
> node scripts/test.js


fs.js:647
  return binding.mkdir(pathModule._makeLong(path),
                 ^
Error: EEXIST, file already exists 'build'
    at Object.fs.mkdirSync (fs.js:647:18)
    at f (/home/user8/Documents/LearnWords2/scripts/test.js:20:12)
    at mkDirs (/home/user8/Documents/LearnWords2/scripts/test.js:26:3)
    at Object.<anonymous> (/home/user8/Documents/LearnWords2/scripts/test.js:37:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
npm ERR! weird error 8
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
 
npm ERR! not ok code 0

Plan for release 0.3.1

This more or less the same as release 0.1 (issue #27 ) but this time with words
where the user has to type in the word on the command line.

Needs #8

SPEC: box.getAnswerOptions(numberOfOptions)

Implement what is given by the following spec

  beforeEach(function() {
    questions  = new BoxOfQuestions("LWquestions");
  });

it("should be able to give a question, give options for answers and check the answer", function() {
    var q, a, opt, aChoice;

    q = questions.currQuestion();
    a = questions.currAnswer();
    opt = questions.currAnswerOptions(); // includes the correct answer
   
    questions.processAnswer(aChoice); 
    // add expect code here
    });

README.md: Add paragraph about 'Usage'

Open a paragraph 'usage' in the main readme stateing how the component is to be used.

  var LW = new BoxWithQuestions('learnwords', {"loadWordsFrom" : "aRelativePathToJSONfile"});

or

var LW = new BoxWithQuestions('learnwords', {"loadWordsFrom" : "aRelativePathToJSONfile", 
                                            "reinitializeDB" : "true"});

or

var LW = new BoxWithQuestions({"dbName": "John-learnwords", 
                              "loadWordsFrom" : "aRelativePathToJSONfile", 
                              "reinitializeDB" : "true"});

Give usage instructions.

Create repository LearnWords2-node-cli

Add to developer journal a note how to create a cli node project which uses the component as a node command line application.

Do this in a new repository LearnWords2-node-cli.

SPEC: box.moveQuestionForward()

Specify and implement a Leitnerbox method box.moveForward(aWordId) or box.moveForward(aWord)

The method will rely on the existing step (level) information and the settings information for that level.

User level testing with command line interface

Tests of the specs are done with node / jasmine.

For user level tests of the component a command line interface is needed.

It should print out a word and

  • either expect the user to type in the answer or
  • give a list of numbered answer options. The user then enters the number of the answer and the system comes with the next question.

Task

Set up such a simple command line interface.

How should private methods be marked?

We have as private methods in the LWdb API (see developer notes)

LWdb.prototype.incNumberOfWords = function() {
LWdb.prototype.invalidateIndex = function() {
LWdb.prototype.setNumberOfWords = function(n) {

How should they be marked?

Cannot find module '_process'

Running grunt on Mac 10.11.6 using Node.js v6.7.0 results in the following error:

Fatal error: Cannot find module '_process' from '/LearnWords2/node_modules/node-localstorage'

Add element for a multiple choice area - optionsForAnswers

Do an example in the browser with getElementById.
Use a HTML code snippet such as

<div id="learnWords2-area">
   <div id=question>...</div>
   <div id="optionsForAnswers">
       <div id="option1">...</div>
       <div id="option2">...</div>
       <div id="option3">...</div>
       <div id="option4">...</div>
   </div>
   <div id=feedback>...</div>
</div>

Hint: link to tutorial

Maybe do this in a new repository LearnWords2-test

Choose a node command line module

Choose a node command line module.

A node command line LearnWords app is done in #18.

Reasons for doing this

  1. The user interface is minimal, thus there should be a quick result
  2. A quick result will provide feedback for the development process
  3. A node cli app is the proof that we actually have a component which does not use a GUI.
  4. A component like this will be illustrative to learn about the project for other developers who might join the effort in the future.

Which node one should we choose?

https://www.npmjs.com/search?q=command+line+interface

Set up npm build

Have grunt build a library file as well.

  dist/......

for the use in a browser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.