Skip to content

Commit

Permalink
Fix cache command line parameter handling
Browse files Browse the repository at this point in the history
Change-Id: I72fcaa6f2d25f79282b141daf50b1d3a4caf0188
  • Loading branch information
Akron committed Apr 16, 2024
1 parent 9cb8c98 commit c0ac4ff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.54 2023-04-15
- Fix 'cache' parameter. (reported by kupietz)
- Fix cache deletion for certain scenarios.

0.53 2023-03-20
- Added Spacy support. (kupietz)
- Support 'pos' as an alternative to 'ctag'
Expand Down
2 changes: 1 addition & 1 deletion lib/KorAP/XML/Krill.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use Exporter 'import';

our @EXPORT_OK = qw(get_file_name get_file_name_from_glob);

our $VERSION = '0.53';
our $VERSION = '0.54';

has 'path';
has [qw/text_sigle doc_sigle corpus_sigle/];
Expand Down
21 changes: 8 additions & 13 deletions script/korapxml2krill
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ use Fcntl qw(:flock SEEK_END);
#
# ----------------------------------------------------------

our $LAST_CHANGE = '2024/03/20';
our $LAST_CHANGE = '2024/04/15';
our $LOCAL = $FindBin::Bin;
our $KORAL_VERSION = 0.03;
our $VERSION_MSG = <<"VERSION";
Expand Down Expand Up @@ -211,7 +211,7 @@ GetOptions(
'temporary-extract|te=s' => \($cfg{temporary_extract}),
'skip|s=s' => \@skip,
'sigle|sg=s' => \@sigle,
'cache|c=s' => \($cfg{cache_file}),
'cache|c=s' => \($cfg{cache}),
'config|cfg=s' => \(my $cfg_file),
'lang=s' => \($cfg{lang}),
'log|l=s' => \($cfg{log}),
Expand Down Expand Up @@ -269,7 +269,7 @@ if ($cfg_file && -e $cfg_file) {
meta base-sentences base-paragraphs base-pagebreaks
gzip to-tar log lang cache non-word-tokens
non-verbal-tokens sequential-extraction
temporary-extract cache-init
temporary-extract cache-init cache-delete
koral extract-dir jobs quiet!) {
my $underlined = $_ =~ tr/-/_/r;
if (!defined($cfg{$underlined}) && defined $config{$_}) {
Expand Down Expand Up @@ -568,7 +568,8 @@ else {
my $cache = Cache::FastMmap->new(
share_file => $cache_file,
cache_size => ($cfg{cache_size} // '50m'),
init_file => ($cfg{cache_init} // 1)
init_file => ($cfg{cache_init} // 1),
unlink_on_exit => $cache_delete
);

# Create batch object
Expand Down Expand Up @@ -601,7 +602,6 @@ if ($jobs eq '-1') {
$log->info("Run using $jobs jobs on $cores cores");
};


# Glob and prefix files
if (@input > 0) {

Expand All @@ -622,7 +622,6 @@ if (@input > 0) {
print 'Input is ' . join(', ', @input)."\n" unless $q;
};


# Process a single file
unless ($cmd) {
my $input = $input[0];
Expand All @@ -648,10 +647,8 @@ unless ($cmd) {
# Process file
$batch_file->process($input, $output);

# Delete cache file
unlink($cache_file) if $cache_delete;

stop_time;

exit;
};

Expand Down Expand Up @@ -983,9 +980,6 @@ elsif ($cmd eq 'archive') {

$pool->wait_all_children;

# Delete cache file
unlink($cache_file) if $cache_delete;

# Close tar filehandle
if ($to_tar && $tar_fh) {
$tar_archive->finish;
Expand Down Expand Up @@ -1377,7 +1371,8 @@ of key-value pairs with whitespace separator
Supported parameters are:
C<overwrite>, C<gzip>, C<jobs>, C<input-base>,
C<token>, C<log>, C<cache>, C<cache-size>, C<cache-delete>, C<meta>,
C<token>, C<log>,
C<cache>, C<cache-size>, C<cache-init>, C<cache-delete>, C<meta>,
C<output>, C<koral>,
C<temporary-extract>, C<sequential-extraction>,
C<base-sentences>, C<base-paragraphs>,
Expand Down
4 changes: 3 additions & 1 deletion t/script/single.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ ok(-d $input, 'Input directory found');
my $output = tmpnam();
my $cache = tmpnam();


ok(!-f $output, 'Output does not exist');

my $call = join(
Expand All @@ -34,6 +33,7 @@ my $call = join(
'--input' => $input,
'--output' => $output,
'--cache' => $cache,
'--no-cache-delete',
'-k' => 0.03,
'-t' => 'OpenNLP#Tokens',
'-l' => 'INFO'
Expand All @@ -48,6 +48,7 @@ stderr_like(
$call
);

ok(-f $cache, 'Cache does exist');
ok(-f $output, 'Output does exist');
ok((my $file = Mojo::File->new($output)->slurp), 'Slurp data');
ok((my $json = decode_json $file), 'decode json');
Expand All @@ -61,6 +62,7 @@ is($json->{data}->{tokenSource}, 'opennlp#tokens', 'TokenSource');

# Delete output
unlink $output;
unlink $cache;
ok(!-f $output, 'Output does not exist');

$call .= ' -z';
Expand Down

0 comments on commit c0ac4ff

Please sign in to comment.