Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloze Update: Adds Cloze hints, Anki-Like Clozes, Cloze Overlapping and Custom Cloze Patterns #943

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MotaOcimar
Copy link

Hello! This PR addresses the following issues: #581, #556, #451, #426, #387, #284, #93, introducing several new features:

The implementation leverages the Clozecraft package, a Cloze parser and Card formatter developed by me specifically for this purpose. Feel free to explore, ask questions, and contribute. Your feedback is highly appreciated.

I've opened this PR as a draft because there are still a few tasks pending:

  • Fix failing tests
  • Create tests for the other cloze types
  • Decide which Cloze Patterns will be delivered by default with the plugin
  • Play with the new features to ensure they work as expected. Fix any bugs and add tests for them if necessary
  • Gather your feedback

Features

Cloze Types

Simplified Clozes

Simplified Clozes are the Cloze Type we have been using so far. They keep working as before, but now you can add hints to them. That means each card will occlude one deletion, showing its hint if available, while leaving the other deletions visible.

For instance, the following note:

This ==note== doesn't need to have ==number==^[hint] on clozes

Will generate two cards, with the following fronts:

  1. This [...] doesn't need to have number on clozes
  2. This note doesn't need to have [hint] on clozes

And both will have the same back:

This note doesn't need to have number on clozes

Classic Clozes

Classic Clozes are the same as Simplified Clozes, but they also have a sequence number used to sort and group deletions.

For instance, the following note:

This is a ==cloze==^[a hint][^1]. This is ==too, but without hint==[^2]. And this one is asked ==together with the first cloze==[^1].

Will generate three cards, with the following fronts:

  1. This is a [a hint]. This is too, but without hint. And this one is asked [...].
  2. This is a cloze. This [...]. And this one is asked together with the first cloze.

And both will have the same back:

This is a cloze. This is too, but without hint. And this one is asked together with the first cloze.

Generalized Cloze Overlapping

The Cloze Overlapping Generalization allows you to dictate the behavior of each deletion individually. Each deletion has its own set of actions that indicate how it will behave on each card:

  • a for ask (hide the deletion answer in the front of the card while showing it in the back).
  • h for hide (hide the deletion answer both in the front and back of the card).
  • s for show (show the deletion answer both in the front and back of the card).

For instance, the following note:

==Some context for items 2 and 4, but that could spoil items 1 and 3. Note that this doesn't even need to be asked==[^hshs]
.
- ==Item 1==[^ashh]
- ==Item 2==[^hash]
- ==Item 3==[^hhas]
- ==Item 4==[^hhha]

In this example, 4 cards will be generated, where items 1 to 4 will be asked sequentially. When asking Item 1, all other text will be hidden. When asking Item 2, just the Item 1 and the context will be displayed. When asking Item 3, only the Item 2 will be displayed. Finally, when asking Item 4, both the Item 3 and the context text will be displayed.

Custom Cloze Patterns

You can now create your own Cloze Patterns. For instance, to emulate Anki-like clozes (e.g., {{1::text::hint}}), simply add the following pattern to your settings:

{{[123::]answer[::hint]}}

Brackets [] delineate where the sequence number and hint will be placed, along with any additional characters of your choice (e.g., the :: in the example above). Clozecraft automatically generates a regex pattern based on your custom pattern. Sequence numbers are identified by finding numbers between brackets, hints by finding the word hint in brackets, and the deleted text by finding the word answer.

Here are some examples of custom patterns:

Explanation Pattern in the Settings Simplified Cloze Usage Numbered Cloze Usage Generalized Cloze Overlapping Usage
Anki-Like Pattern {{[123::]answer[::hint]}} Brazilians speak {{Portuguese}}

Or, with hint:
Brazilians speak {{Portuguese::language}}
Brazilians speak {{1::Portuguese}}

Or, with hint:
Brazilians speak {{1::Portuguese::language}}
Brazilians speak {{a::Portuguese}}

Or, with hint:
Brazilians speak {{a::Portuguese::language}}
Highlighted pattern with hint and sequencer in footnotes. Note that you can use brackets as part of your pattern, but you need to escape them. ==answer==[^\[hint\]][\[^123\]] Brazilians speak ==Portuguese==

Or, with hint:
Brazilians speak ==Portuguese==^[language]
Brazilians speak ==Portuguese==[^1]

Or, with hint:
Brazilians speak ==Portuguese==^[language][^1]
Brazilians speak ==Portuguese==[^a]

Or, with hint:
Brazilians speak ==Portuguese==^[language][^a]

In your settings, you can add multiple patterns at once, separating them with a new line:

{{[123::]answer[::hint]}}
==answer==[^\[hint\]][\[^123\]]

Then, you can use them in your notes:

This note has both ==highlighted clozes==[^1] and {{2::anki like clozes}}

And this note has both ==highlighted clozes==^[footnote hint][^1] and {{2::anki like clozes::anki like hint}}

Remember, deletions must be of the same Cloze Type. You can't mix, for instance, a Classic Cloze with a Simplified Cloze in the same note, as they employ different ways to sort and identify the cards.

@MotaOcimar MotaOcimar mentioned this pull request Apr 25, 2024
@MotaOcimar
Copy link
Author

Hello @st3v3nmw and @Stefanuk12,

I hope you're both doing well! First and foremost, I'd like to express my appreciation for the work you've both been doing on the project so far. It's inspiring to see your dedication to this incredible Obsidian plugin.

Yesterday, I had the opportunity to open this PR addressing several issues related to the use of Clozes. Upon submitting it, I noticed that @Stefanuk12 had already opened PR #769 addressing issue #93 five months ago, which unfortunately went unnoticed. Additionally, @st3v3nmw, I noticed that you updated the status of issue #93 to "In progress," which made me wonder if you were already working on it.

I'd like to sync our efforts to ensure that all contributions are considered in the best possible way. My goal is not only to offer my solution but also to recognize your previous work and ensure that the project progresses collaboratively and efficiently. Please let me know what you think about all of this, what stage you're at, your thoughts on the current PR, and if I can assist you in any way.

Thank you once again for your hard work. I'm looking forward to the evolution of Clozes in the project.

Best regards, Ocimar Santos (MotaOcimar)

@Stefanuk12
Copy link

Lovely PR btw, a lot better and expansive than mine! I have pretty much abandoned Obsidian so I won't be much help unfortunately. Really sad how my PR was overlooked :( , but I hope yours gets reviewed since this is a KEY thing this plugin is missing.

@MotaOcimar
Copy link
Author

Hello again!

Firstly, @polyipseity, my apologies for the oversight in my previous message. I realized after sending it that I forgot to include you, who opened PR #607 addressing issues #556 and #387. I appreciate your work and would like to hear your thoughts on this PR too.

@Stefanuk12, thank you for your kind words regarding the PR. I'm sorry to hear that you've pretty much abandoned Obsidian; your opinion remains valuable to me, though. If any insights or suggestions arise, I'd be grateful to hear them.

@ronzulu
Copy link
Collaborator

ronzulu commented Apr 28, 2024

Hi @MotaOcimar I've only had a chance for a brief look, but looks great!

I'm working on [FEAT] Refactor code to support diff methods of storing the scheduling info, and diff SR algorithms #878 , so after that I should have time to review in detail.

Great work!

Cheers
Ronny

@MotaOcimar
Copy link
Author

Hey @ronzulu!

It's awesome to have you here! I just wanted to take a moment to express my gratitude not only for your willingness to review this PR but also for all the hard work you've been putting into the project. Your immense participation, both in code and in discussions, hasn't gone unnoticed. Rest assured that the time and effort you've invested here have made a significant impact. I'm particularly excited about feature #878 too. Keep up the fantastic work!

Best,
Ocimar Santos (MotaOcimar)

@SeLiEnisyst
Copy link

Hi,
@ronzulu pointed me to this place here.

I am very interested in using spaced repetition in combination with clozes for language and especially vocabulary training.
As I described here: #955
I would like to use your feature for:

  • 1st side of the flashcard: exchange one or more word/s in a given sentence by the word/s of my mother language
  • 2nd side of the flashcard: the original sentence

Would it be possible to integrate that feature?

Thank you very much in advance,
kind regards,

Silias

@MotaOcimar
Copy link
Author

Hi Silias (@SeLiEnisyst)!

Let me see if I understood well.

You want to write something like this on the note:

;;;;picking a new painting, would be {{to succumb}};;;;{{unterliegen}} to the very impatience;;;;

Have this as card front/question:

picking a new painting, would be to succumb to the very impatience

And this as card back/answer:

unterliegen

If that's correct, although I don't think it's possible to create cards exactly like this yet, I think it will be possible to do something very similar after this PR is completed:

Assuming we are using the Anki-like pattern for Simplified Clozes (e.g., {{text::hint}}), you can write:

picking a new painting, would be {{unterliegen::to succumb}} to the very impatience

This will display the front of the card as:

picking a new painting, would be [to succumb] to the very impatience

And the back of the card as:

picking a new painting, would be unterliegen to the very impatience

I understand that the front and back formatting may not be exactly as desired. But I hope that it will still allow you to review and practice your vocabulary.

Additionally, I saw you expressed interest in having a delimiter for the beginning and end of the note (the ;;;; in your example). Currently, the plugin uses newlines to delimit notes. Adding a way to change this is probably a new feature that impacts other parts of the plugin, not just Clozes. I wonder if there's already an issue addressing this. Can you say @ronzulu?

Silias, let me know if I understood everything correctly and if, despite the limitations, this way can meet your request.

Best,
Ocimar

@ronzulu
Copy link
Collaborator

ronzulu commented Jun 2, 2024

Hi @MotaOcimar sorry I haven't managed to look at your PR yet. I'm still working on #878. I'm hoping to put in my PR for it hopefully this week, then will have a chance. Would also be great if @st3v3nmw would look at this PR as well :-)

@MotaOcimar
Copy link
Author

Additionally, I saw you expressed interest in having a delimiter for the beginning and end of the note (the ;;;; in your example). Currently, the plugin uses newlines to delimit notes. Adding a way to change this is probably a new feature that impacts other parts of the plugin, not just Clozes. I wonder if there's already an issue addressing this. Can you say @ ronzulu?

I found! It's issue #450 [BUG] Cloze Cards require blank lines before and after to create atomic card

@SeLiEnisyst
Copy link

SeLiEnisyst commented Jun 3, 2024

Hi @MotaOcimar,

Thank you very much for your detailed answer!!! :)
I think I didn't express myself clearly enough, therefore I will try it another way:

Have this as the card front/question:

picking a new painting, would be to succumb to the very impatience

Additionally to the original sentence, there should be some kind of hint for which part of that sentence a translation is asked for. Therefore, I suggested indicating that part with the ==bold syntax==. My suggestion for the front card would be: picking a new painting, would be ==to succumb== to the very impatience.

The back of the card would just have the translation, in my case: "unterliegen".

...
The rest of my original feature request, you already answered sufficiently. To indicate the start and stop of the phrase for the front card (delimiter), I just would have to set new lines - that's absolutely fine! :)

@polyipseity
Copy link
Contributor

MotaOcimar commented on Apr 26

Hello again!

Firstly, @polyipseity, my apologies for the oversight in my previous message. I realized after sending it that I forgot to include you, who opened PR #607 addressing issues #556 and #387. I appreciate your work and would like to hear your thoughts on this PR too.

Nice. It is definitely better than hardcoding the cloze token delimiters. This would supersede my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants