klieret / anki-merge-notes

Anki plugin to merge notes.
GNU Affero General Public License v3.0
6 stars 0 forks source link

Merging multiple notes into one #5

Open klieret opened 5 years ago

klieret commented 5 years ago

As suggested in #4 by @4SoG

klieret commented 5 years ago

This is possible in principle, perhaps I get around to do this some time this week. Unfortunately I'm a bit short on time....

4SoG commented 5 years ago

Thank you so much for wanting to work on it despite being so busy! Wish I were a coder, I could be of more use then, but still, if you need a tester, I will be happy to help.

klieret commented 5 years ago

I rewrote most parts of the addon in the complete-refactor branch https://github.com/klieret/anki-merge-notes/tree/complete-refactor . I think this should merge multiple notes into one, but several things have changed. I tested this on a tiny setup today and it seemed to work, but I didn't test this extensively.

Also I'll probably work on making this run with anki 2.1, but if you want you can already try this out for anki2.0 (but I might revisit this some time this week to finish this).

4SoG commented 5 years ago

Oh, that's fantastic news, thanks for finding time for this so quickly! I am unable to test it at the moment but will definitely give it a try later today or tomorrow and will let you know how it works.

Thanks a lot!

klieret commented 5 years ago

No hurry ;)

4SoG commented 5 years ago

Hi again!

I have just played a little with the new version. Thanks sooo much, multiple notes do get merged fine now! You are a ⭐️! :) Just one thing I noticed, after merging e.g. three notes with the same answer óg, I get a note with answer field óg óg óg and question field young young young... I really miss the option to fine-tune the results and keep only the content of the note from or the note to field instead of merging them.

Would you be able to implement merge options (to, from, merge) for note fields, like you've done with the tags? Pretty please :)

4SoG commented 5 years ago

I missed something: I tested with two MERGE_FROM notes and one MERGE_TO note and for some reason I got two WAS_MERGED_TO notes.

Here's the log:


SyncFields:DEBUG:Setting up menu. SyncFields:DEBUG:Found 2 notes with tag_from MERGE_FROM SyncFields:DEBUG:Found 1 notes with tag_to MERGE_TO SyncFields:DEBUG:looping to build db


klieret commented 5 years ago

Thanks for testing ;)

I have just played a little with the new version. Thanks sooo much, multiple notes do get merged fine now! You are a ! :) Just one thing I noticed, after merging e.g. three notes with the same answer óg, I get a note with answer field óg óg óg and question field young young young... I really miss the option to fine-tune the results and keep only the content of the note from or the note to field instead of merging them.

So the reason I removed the options is because I think they don't make that much sense/don't generalize:

Does that make any sense? So in your case, why don't you simply leave out answer and question if it is the same thing everywhere?

But what I could do in general is, that I add an option to remove duplicate field values (i.e. we collect them from the different from notes and from the to note, then throw out all duplicates, then write to the to note).

klieret commented 5 years ago

I missed something: I tested with two MERGE_FROM notes and one MERGE_TO note and for some reason I got two WAS_MERGED_TO notes.

Ah you mean the WAS_MERGED_TO and WAS_MERGED_FROM tags don't work properly? I think I might see the problem, I did something stupid ;) I'll fix that today or tomorrow.

Thanks again for looking into this ;)

4SoG commented 5 years ago

So the reason I removed the options is because I think they don't make that much sense/don't generalize:

  • to, i.e. keep the field value of the to_note: This is the same as simply not merging the field, i.e. leaving it out from the list of fields to be merged
  • from: This doesn't make sense if you have multiple notes that get merged into another one. However, if you have only one from_note that gets merged into one to_note, then this is already the default behavior
  • merge: Is the default behavior

Does that make any sense? So in your case, why don't you simply leave out answer and question if it is the same thing everywhere?

You are absolutely right, I've no idea why but I was convinced that all note fields had to be listed in the configuration file. Silly me :( Thanks for clearing this up!

But what I could do in general is, that I add an option to remove duplicate field values (i.e. we collect them from the different from notes and from the to note, then throw out all duplicates, then write to the to note).

Oooh, this would be neat, indeed! If you have enough time, that is :)

I missed something: I tested with two MERGE_FROM notes and one MERGE_TO note and for some reason I got two WAS_MERGED_TO notes.

Ah you mean the WAS_MERGED_TO and WAS_MERGED_FROM tags don't work properly? I think I might see the problem, I did something stupid ;) I'll fix that today or tomorrow.

No, I meant I got a doubled note as a result, but that was my fault, sorry. When configuring the addon I changed self.remove_html_ghost_field_content to False (not sure why, to be honest!). My notes have an optional second card depending on the content of the AudioTest field and as the merged note had <br /> <br /> in that field, the second card got created. That's what I was seeing in the browser: the second card and not a duplicated note. I didn't realise at first because I didn't have the "Card" column enabled in the browser.

I'm very sorry for the confusion.

However, I have enabled that setting now and got an error:


Traceback (most recent call last): File "C:\Users\4SoG\AppData\Roaming\Anki2\addons\merge_notes_files\merge_notes.py", line 165, in loop self.merge_notes(notes_from, note_to) File "C:\Users\4SoG\AppData\Roaming\Anki2\addons\merge_notes_files\merge_notes.py", line 176, in merge_notes self.merge_fields(notes_from, note_to) File "C:\Users\4SoG\AppData\Roaming\Anki2\addons\merge_notes_files\merge_notes.py", line 181, in merge_fields self.merge_field(notes_from, note_to, field) File "C:\Users\4SoG\AppData\Roaming\Anki2\addons\merge_notes_files\merge_notes.py", line 200, in merge_field note_to[field] = self.merge_field_contents([field_to] + fields_from) File "C:\Users\4SoG\AppData\Roaming\Anki2\addons\merge_notes_files\merge_notes.py", line 206, in merge_field_contents if not stripHTML(field_contents[i]).strip(): IndexError: list index out of range


Thanks again for looking into this ;)

My pleasure!

klieret commented 5 years ago

Oh the indexerror was stupid, I should have fixed it now (but didn't try it yet).

I'll look at the rest once I'm back from vacation :)

4SoG commented 5 years ago

Thanks, I'll give it a try :) Enjoy your vacation!