WiktionaryDumps to words: Difference between revisions

Content added Content deleted
(removed the one-year-old warning note)
Line 587: Line 587:


=={{header|Raku}}==
=={{header|Raku}}==
I misunderstood the data format and now just copy verbatim from Julia entry the processing logics ..
<lang perl6># 20211209 Raku programming solution
<lang perl6># 20211209 Raku programming solution


Line 601: Line 602:
method CustomRequest {
method CustomRequest {


my %needles;
my Blob $resp = Buf.new;
my Blob $resp = Buf.new;
my $bzip = Compress::Bzip2::Stream.new;
my $bzip = Compress::Bzip2::Stream.new;
my ( $tail, %needles ) = '';


my ($host, $port, $path) = self.parse_url($.URL)[1..3];
my ($host, $port, $path) = self.parse_url($.URL)[1..3];
Line 620: Line 621:
emit self.parse_response($resp)[2]; # $resp_content @ parent class
emit self.parse_response($resp)[2]; # $resp_content @ parent class
loop {
loop {
done if %needles.elems > $Target ;
done if %needles.elems >= $Target ;
( my $chunk = $sock.read(4096) ) ?? emit $chunk !! done
( my $chunk = $sock.read(4096) ) ?? emit $chunk !! done
}
}
Line 627: Line 628:
react {
react {
whenever $bzip-stream -> $crypt {
whenever $bzip-stream -> $crypt {
my $plain = ( [~] $bzip.decompress: $crypt ).decode('utf8-c8');
my $plain = ( [~] $bzip.decompress: $crypt ).decode('utf8-c8');
my @haystacks = $plain.split: $LanguageMark;
my @haystacks = $plain.split: "\n";
race for @haystacks[ 1..*-1 ] { # avoid incomplete fragments
@haystacks[0] = $tail ~ @haystacks[0];
%needles{$0}++ if / .* '<title>' (\w+?) '</title>' /
$tail = @haystacks[*-1];

my ($title,$got_text_last) = '', False ;

for @haystacks[0..*-2] {
if / '<title>' (\w+?) '</title>' / {
($title,$got_text_last) = $0, False;
} elsif / '<text' / {
$got_text_last = True
} elsif / $LanguageMark / {
%needles{$title}++ if ( $got_text_last and $title.Bool );
last if ( %needles.elems >= $Target ) ;
$got_text_last = False;
} elsif / '</text>' / { $got_text_last = False }
}
}
}
}
}
}

return %needles.keys[^$Target]
return %needles.keys[^$Target]
}
}
Line 642: Line 655:


$ua.CustomRequest>>.say</lang>
$ua.CustomRequest>>.say</lang>
{{out}}
<pre>
chien
gratuit
gratis
pond
livre
</pre>