Skip to content

Commit ce03350

Browse files
committed
Remove Directory::Iterator in korapxml2krill
Change-Id: Ia372478fec6dd62e40c90a0f9bdd1a15aa445b9d
1 parent 7d4d2d7 commit ce03350

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

Changes

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.58 2024-09-11
2+
- Remove Directory::Iterator and replace it with Mojo::File.
3+
14
0.57 2024-07-26
25
- Support award notes in i5.
36
- Add support for idno (with @rend) in i5.

Makefile.PL

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ WriteMakefile(
2727
'IO::Uncompress::Gunzip' => 2.102,
2828
'IO::Dir::Recursive' => 0.03,
2929
'File::Temp' => 0.2311,
30-
'Directory::Iterator' => 1,
31-
'Directory::Iterator::XS' => 1,
3230
'Module::Install' => 1.19,
3331
'Dumbbench' => 0.501,
3432
'Benchmark' => 0,

lib/KorAP/XML/ForkPool.pm

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package KorAP::XML::ForkPool;
22
use strict;
33
use warnings;
4+
use Mojo::File;
45
use Parallel::ForkManager;
56
use v5.10;
67

@@ -51,17 +52,17 @@ sub process_directory {
5152

5253
print "Reading data ...\n";
5354

54-
my $it = Directory::Iterator->new($input);
5555
my @dirs;
56-
my $dir;
5756

58-
while (1) {
59-
if (!$it->is_directory && ($dir = $it->get) && $dir =~ s{/data\.xml$}{}) {
60-
push @dirs, $dir;
61-
$it->prune;
62-
};
63-
last unless $it->next;
64-
};
57+
Mojo::File->new($input[0])
58+
->list_tree({hidden => 0, dir => 0})
59+
->grep(qr/\/data\.xml$/)
60+
->each(
61+
sub {
62+
s/\/data\.xml$//;
63+
push @dirs, $_;
64+
}
65+
);
6566

6667
$self->{count} = scalar @dirs;
6768

lib/KorAP/XML/Krill.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Exporter 'import';
1616

1717
our @EXPORT_OK = qw(get_file_name get_file_name_from_glob);
1818

19-
our $VERSION = '0.57';
19+
our $VERSION = '0.58';
2020

2121
has 'path';
2222
has [qw/text_sigle doc_sigle corpus_sigle/];

script/korapxml2krill

+12-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use Log::Any qw($log);
1313
use Log::Any::Adapter;
1414
use Pod::Usage;
1515
use Cache::FastMmap;
16-
use Directory::Iterator;
1716
use KorAP::XML::Krill qw!get_file_name get_file_name_from_glob!;
1817
use KorAP::XML::Archive;
1918
use KorAP::XML::TarBuilder;
@@ -25,6 +24,7 @@ use File::Glob ':bsd_glob';
2524
use File::Temp qw/tempdir/;
2625
use File::Path qw(remove_tree make_path);
2726
use File::Basename;
27+
use Mojo::File;
2828
use Mojo::Collection 'c';
2929
use String::Random qw(random_string);
3030
use IO::File;
@@ -876,20 +876,18 @@ elsif ($cmd eq 'archive') {
876876

877877
# Input is a directory
878878
if (-d $input[0]) {
879-
# TODO:
880-
# Replace with Mojo::File
881-
my $it = Directory::Iterator->new($input[0]);
879+
882880
my @dirs;
883-
my $dir;
884881

885-
# Todo: Make a DO WHILE
886-
while (1) {
887-
if (!$it->is_directory && ($dir = $it->get) && $dir =~ s{/data\.xml$}{}) {
888-
push @dirs, $dir;
889-
$it->prune;
890-
};
891-
last unless $it->next;
892-
};
882+
Mojo::File->new($input[0])
883+
->list_tree({hidden => 0, dir => 0})
884+
->grep(qr/\/data\.xml$/)
885+
->each(
886+
sub {
887+
s/\/data\.xml$//;
888+
push @dirs, $_;
889+
}
890+
);
893891

894892
print "Start processing ...\n" unless $q;
895893
$t = Benchmark->new;
@@ -1170,7 +1168,7 @@ Extracts KorAP-XML documents from a zip file.
11701168
11711169
$ korapxml2krill serial -i <archive1> -i <archive2> -o <directory> -cfg <config-file>
11721170
1173-
Convert archives sequentially. The inputs are not merged but treated
1171+
Convert archives in serial. The inputs are not merged but treated
11741172
as they are (so they may be premerged or globs).
11751173
the C<--out> directory is treated as the base directory where subdirectories
11761174
are created based on the archive name. In case the C<--to-tar> flag is given,
@@ -1481,7 +1479,6 @@ Print version information.
14811479
14821480
=back
14831481
1484-
14851482
=head1 ANNOTATION SUPPORT
14861483
14871484
L<KorAP::XML::Krill> has built-in importer for some annotation foundries and layers

0 commit comments

Comments
 (0)