Skip to main content

Spaced Spatial Repetition software with AI-generated sentence variations for language learning

Project description

MorphCards

Spaced Spatial Repetition (SSR) software with AI-generated sentence variations for language learning.

Python 3.8+ License: MIT PyPI version

For developer documentation (including containerization and contributing), see DEVELOPERS.md.

🎯 Overview

Traditional SSR software often repeats the exact same sentence cards, leading users to memorize the front of cards rather than truly learning the language. MorphCards solves this by generating new, contextually appropriate sentences each time a card is reviewed, ensuring learners can identify and understand words in different contexts.

✨ Features

  • FSRS-based Spaced Repetition: Uses the Free Spaced Repetition Scheduler for optimal learning intervals
  • AI-Generated Sentence Variations: Creates new sentences using OpenAI or Google Gemini APIs
  • Vocabulary-Aware Generation: Ensures new sentences only use previously learned vocabulary
  • In-Memory Database: Fast DuckDB-based storage for cards and review history
  • Parameter Optimization: Automatically optimizes FSRS parameters based on your learning patterns
  • Multiple AI Services: Support for both OpenAI and Google Gemini APIs
  • CLI Interface: Command-line tool for daily use
  • Web Demo: Interactive Gradio interface for testing and demonstration

🚀 Quick Start

Installation

# Install from PyPI
pip install morphcards

# Install with demo dependencies
pip install morphcards[demo]

Environment Variables

This documentation assumes Gemini is being used by default. All examples assume you have a .env file with your API keys.

Create a .env file in your project root:

# .env file
GEMINI_API_KEY=your-gemini-api-key-here
GEMINI_MODEL_NAME=gemini-2.5-flash # Example: gemini-2.5-flash, gemini-1.5-pro, gemini-1.5-flash

#OPENAI_API_KEY=your-openai-api-key-here  # Uncomment for OpenAI
#OPENAI_MODEL_NAME=gpt-3.5-turbo # Example: gpt-4, gpt-3.5-turbo

Basic Usage

from morphcards import Card, Scheduler, VocabularyDatabase
from morphcards.ai import AIServiceFactory
from datetime import datetime

# Initialize components
db = VocabularyDatabase()
scheduler = Scheduler()
ai_service = AIServiceFactory.create_service("gemini", model_name="gemini-2.5-flash") # Example with model_name

# Create a card
card = Card(
    id="hello_1",
    word="hello",
    sentence="Hello, how are you?",
    original_sentence="Hello, how are you?",
    due_date=datetime.now()
)

# Add to database
db.add_card(card)

# Review the card
updated_card, review_log = scheduler.review_card(
    card=card,
    rating=3,  # Good
    now=datetime.now(),
    ai_api_key="your-api-key",
    vocabulary_database=db,
    ai_service=ai_service
)

print(f"New sentence: {updated_card.sentence}")

Command Line Interface

# Add a new card
morphcards add "bonjour" "Bonjour, comment allez-vous?" --language French

# Review due cards (uses .env file)
morphcards review --ai-service gemini --model-name gemini-2.5-flash

# Show statistics
morphcards stats

# Optimize parameters
morphcards optimize

📊 Demo Interface

Start the interactive demo:

# Run demo locally (after installing with [demo] extras)
morphcards demo

The demo provides:

  • Add Cards: Create new learning cards
  • Review Cards: Interactive review process with AI sentence generation
  • Statistics: View learning progress and vocabulary stats
  • Optimization: Optimize FSRS parameters

🏗️ Architecture

For detailed architecture diagrams and system design, see Architecture Documentation.

Core Components

  • Card: Represents a flashcard with word, sentence, and FSRS parameters
  • Scheduler: Manages spaced repetition scheduling using FSRS algorithm
  • Optimizer: Optimizes FSRS parameters based on review history
  • VocabularyDatabase: Stores cards, reviews, and vocabulary using DuckDB
  • AIService: Abstract interface for AI sentence generation
  • OpenAIService: OpenAI API integration
  • GeminiService: Google Gemini API integration

🔍 API Reference

Core Classes

Card

  • id: Unique identifier
  • word: Word to learn
  • sentence: Current sentence
  • original_sentence: Original sentence when created
  • stability: FSRS stability parameter (nullable)
  • difficulty: FSRS difficulty parameter (nullable)
  • due_date: Next review date
  • state: FSRS state (New, Learning, Review, Relearning)

Scheduler

  • review_card(): Process card review and generate new sentence
  • _fsrs: Internal FSRS scheduler instance (manages parameters internally)

VocabularyDatabase

  • add_card(): Add new card
  • get_due_cards(): Get cards ready for review
  • get_learned_vocabulary(): Get all learned words
  • add_review_log(): Record review completion (now stores UUID for review logs)

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morphcards-0.1.1.tar.gz (39.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

morphcards-0.1.1-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file morphcards-0.1.1.tar.gz.

File metadata

  • Download URL: morphcards-0.1.1.tar.gz
  • Upload date:
  • Size: 39.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for morphcards-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f7e4ee91a32a729324c22c557ae291c23ce3f39ca417f452e2e26038a5eb2fb4
MD5 90c3bf65dd38a2df13f08712df65c3fb
BLAKE2b-256 28ddf6b8fe98eb82db6fd44639968d3d39151e47b40a09cd6b296a110809bb33

See more details on using hashes here.

Provenance

The following attestation bundles were made for morphcards-0.1.1.tar.gz:

Publisher: publish-to-pypi.yml on felipepenha/morphcards

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file morphcards-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: morphcards-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for morphcards-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 500667dcbef07c59b825d80a3a32767a26ab5b93bc82c04dd986f4bf8d837629
MD5 bf320d0674a358bbd5af34b4204a3069
BLAKE2b-256 e624678b3ecbdb677bc3715f375c8b6fc1356d5aa8e1989b85fa7cedccb4b5b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for morphcards-0.1.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on felipepenha/morphcards

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page