This project is the flashcard-generator-core
library that uses the GPT API to create basic sentences using provided words in different languages.
It helps in learning languages by generating example sentences. The library supports various languages and can export the generated sentences to different file formats such as CSV and JSON.
- Generate flashcards using a specified word or set of words in various languages.
- Support for different language-specific options, such as choosing grammatical tense or including stress symbols.
- Configuration for language-specific features via a JSON file.
- Export generated flashcards to multiple file formats (CSV, JSON).
- Easily extendable to support more languages.
- Java 22 or higher
- Maven
- An API Key (currently only OpenAI API available)
-
Clone the repository:
git clone https://github.com/yourusername/flashcard-generator-core.git cd flashcard-generator-core
-
Build the project:
mvn clean package
-
Use the generated JAR file in your applications.
After building the project, the JAR file located in the
target/
directory can be included as a dependency in other applications that wish to utilize the flashcard generation capabilities of this library.cd target/
The Flashcard Generator Core requires an API key to access the language processing services that power the flashcard generation functionality.
The application or service using this core library will need to handle API key management.
The library provides a ApiKeyConfig
class that can read and write a provided API key to a api_config.json
file in a .flashcard-generator
directory in the user's home directory.
It is important to keep your API key secure and not share it with others. Usage charges may apply depending on the services you use through the application.
To generate flashcards with the application there is essentially a three-step process.
- Load the words into memory using an implementation of
InputService
. - Generate the flashcards using an implementation of
FlashcardService
. - Export the output using an implementation of
OutputService
.
While the Flashcard Generator Core does not provide a direct user interface, it is designed to be integrated into other applications that offer various modes for inputting data and exporting the generated flashcards. This flexibility allows developers to create applications that fit their specific workflow and preferences.
-
Interactive Mode (
InputServiceInteractiveMode.java
): Applications using this core can implement an interactive mode where users are prompted to enter words or phrases one at a time. The application would then use the core library to generate flashcards for each input. -
Comma Separated String Mode (
InputServiceCommaSeparatedStringMode.java
): Developers can implement batch processing where the core library processes a list of words provided as a single string, where each word is delimited by a comma. -
Plain Text File Mode (
InputServicePlainTextFileMode.java
): Applications can be designed to read input from files (e.g., text files) and pass this data to the core library for flashcard generation.
- GPT Implementation (
FlashcardServiceGPTImpl.java
): Currently the only flashcard service available is using the OpenAI API. The service uses aPromptService
to generate the appropriate prompts to the API,HttpClientService
to generate the HTTP request and handle the HTTP response, and aJsonParseService
to parse the response under the hood.
- CSV Mode (
OutputServiceCsvMode.java
): Flashcards can be exported to a CSV file, where each flashcard is a separate line with fields separated by commas. - JSON Mode (
OutputServiceJsonMode.java
): Flashcards can be exported as a JSON file, which is useful for applications that require structured data.
The Flashcard Generator Core allows for language-specific configurations to tailor the flashcard generation process to the nuances of different languages.
Language-specific features are configured via the language_config.json
file located in the src/main/resources
directory. This file includes options for stress symbols, formality, gender, dialects, politeness levels, and conjugation tenses.
Example language_config.json
:
{
"ru": {
"name": "Russian",
"supports_stress": true,
"tenses": ["PAST", "PRESENT", "FUTURE"],
"genders": ["MASCULINE", "FEMININE", "NEUTER"]
},
"pl": {
"name": "Polish",
"supports_stress": false,
"tenses": ["PAST", "PRESENT", "FUTURE"],
"genders": ["MASCULINE", "FEMININE", "NEUTER"]
},
"es": {
"name": "Spanish",
"supports_stress": false,
"tenses": ["PAST", "PRESENT", "FUTURE"],
"genders": ["MASCULINE", "FEMININE"]
}
}
The choice of languages and the specific features that can be configured are heavily dependent on the capabilities of the underlying language model that the application uses. The language model's ability to accurately generate content in different languages and handle linguistic nuances like stress, gender, and tense is a key factor in determining how well the application can support each language.
As the Flashcard Generator Core continues to evolve, several exciting enhancements and new features are planned to improve its functionality and expand its capabilities.
- Functionality for applying the options to flashcard generation (stress, tenses, genders).
- Output service for directly generating output compatible with the Anki spaced-repetition flashcard application.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or new features.
This project is licensed under the MIT License.