Fast Anki Cloze Deletion Cards

Ask specific questions about your target languages. Beginner questions welcome!
User avatar
Adrianslont
Blue Belt
Posts: 827
Joined: Sun Aug 16, 2015 10:39 am
Location: Australia
Languages: English (N), Learning Indonesian and French
x 1936

Re: Fast Anki Cloze Deletion Cards

Postby Adrianslont » Wed Jun 19, 2019 7:24 am

rdearman wrote:OK, I've modified it to deal with words which contain ' or - so it can now successfully deal with: l'orange and part-time.

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;

my $filename   = $ARGV[0];
my $outfile = $ARGV[1];


open(my $fh,  '<:encoding(UTF-8)', $filename) ;
open(my $ofh, '>:encoding(UTF-8)', $outfile);

while (my $row = <$fh>)
{
    my $wordcount;
    chomp $row;
    my @words =  $row =~ /\w+[\'\-]\w+|\w+/g ;
    $wordcount = scalar( @words );
    for (my $a=0;$a<$wordcount;$a++)
    {
   print $ofh "{{c" . $a . "::" . $words[$a] . "}} " ;
    }
    print $ofh "\n";
}
print "done\n";



Thanks for that, Rick.

In the process of fixing your code you seem to have accidentally dropped two lines of code.
# my $filename = "input.txt";
# my $outfile = "output.csv";

I have added them back in, renaming the input file input.txt and the output file output.csv

I have remade my 84k cards and the apostrophes and hyphens seem to be in order. I haven't spotted any other issues, though I have only looked at about 50 cards.

Cheers

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;

my $filename   = $ARGV[0];
my $outfile = $ARGV[1];

# my $filename = "input.txt";
# my $outfile = "output.csv";
open(my $fh,  '<:encoding(UTF-8)', $filename) ;
open(my $ofh, '>:encoding(UTF-8)', $outfile);

while (my $row = <$fh>)
{
    my $wordcount;
    chomp $row;
    my @words =  $row =~ /\w+[\'\-]\w+|\w+/g ;
    $wordcount = scalar( @words );
    for (my $a=0;$a<$wordcount;$a++)
    {
   print $ofh "{{c" . $a . "::" . $words[$a] . "}} " ;
    }
    print $ofh "\n";
}
print "done\n";
0 x

User avatar
rdearman
Site Admin
Posts: 7260
Joined: Thu May 14, 2015 4:18 pm
Location: United Kingdom
Languages: English (N)
Language Log: viewtopic.php?f=15&t=1836
x 23316
Contact:

Re: Fast Anki Cloze Deletion Cards

Postby rdearman » Wed Jun 19, 2019 12:37 pm

Adrianslont wrote:In the process of fixing your code you seem to have accidentally dropped two lines of code.
# my $filename = "input.txt";
# my $outfile = "output.csv";

These are actually commented out, the # symbol is used to for comments. They were for testing so I removed them when I posted the second version. The script is actually taking the names from the command line you type in. So my $filename = $ARGV[0]; my $outfile = $ARGV[1]; is where all the action happens. $ARGV[0] is the first file name after the script and $ARGV[1] is the second file name. This is so that you can use it on any file you want and output any file name you want. So you can have.

perl cloze.pl some_really_cool_input.txt some_really_cool_output.csv
The script reads some_really_cool_input.txt as $ARGV[0], and some_really_cool_output.csv as $ARGV[1] and assigns them appropriately.

Or whatever you want. This way you don't even need them to be in the same place, you could use:
perl cloze.pl C:\Textbook\myfiles\saved\processed\italian.txt C:\users\john.doe\Documents\Anki\Imports\Italian.csv
1 x
: 26 / 150 Read 150 books in 2024

My YouTube Channel
The Autodidactic Podcast
My Author's Newsletter

I post on this forum with mobile devices, so excuse short msgs and typos.

User avatar
Adrianslont
Blue Belt
Posts: 827
Joined: Sun Aug 16, 2015 10:39 am
Location: Australia
Languages: English (N), Learning Indonesian and French
x 1936

Re: Fast Anki Cloze Deletion Cards

Postby Adrianslont » Wed Jun 19, 2019 1:10 pm

Rick

Thank you for the continuing education.

I must have done something wrong, then I compared the scripts and noticed the two missing comment lines and mistakenly thought they were important - so I put them in. And then somehow managed to do the correct thing and it worked!

It’s fabulous how you get so many cards - do you have any strategy for easily deleting the ones you don’t want? I’ve just been going through them, burying them one by one as I meet them if I don’t like them but I’m thinking there must be a clever way to go about it.
0 x

User avatar
rdearman
Site Admin
Posts: 7260
Joined: Thu May 14, 2015 4:18 pm
Location: United Kingdom
Languages: English (N)
Language Log: viewtopic.php?f=15&t=1836
x 23316
Contact:

Re: Fast Anki Cloze Deletion Cards

Postby rdearman » Wed Jun 19, 2019 3:54 pm

I found using the Android app that I could turn on gestures and I configured it to suspend the card when I swiped to the right. Because suspension is only one command and accomplished the same objective, where delete made me confirm (two steps).

This I found was the quickest way and I could always unsuspend it if I made a mistake.

Otherwise vetting the input by opening the generated csv file and deleting the line is probably the best way. Then they never get into anki and you can see them all together in excel (or libreoffice calc). You could also do clever stuff in excel like removing long entries by sorting by length and deleting long (or short) ones.
3 x
: 26 / 150 Read 150 books in 2024

My YouTube Channel
The Autodidactic Podcast
My Author's Newsletter

I post on this forum with mobile devices, so excuse short msgs and typos.


Return to “Practical Questions and Advice”

Who is online

Users browsing this forum: No registered users and 2 guests