WiktionaryDumps to words: Difference between revisions

m
syntax highlighting fixup automation
(Added Wren)
m (syntax highlighting fixup automation)
Line 9:
=={{header|C}}==
 
<langsyntaxhighlight Clang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
Line 205:
 
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 229:
=={{header|Java}}==
 
<langsyntaxhighlight lang="java">import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
Line 288:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 311:
=={{header|Julia}}==
Uses Regex and a state variable instead of XML parsing. Default setting prints the first 80 French words found.
<langsyntaxhighlight lang="julia">using CodecBzip2
 
function getwords(io::IO, output::IO; languagemark = "==French==", maxwords = 80)
Line 341:
getwords(stream, stdout) # or open a file to write to and use its IO handle instead of stdout
 
</langsyntaxhighlight>{{out}}
<pre>
gratis
Line 430:
Using the library [http://erratique.ch/software/xmlm xmlm]:
 
<langsyntaxhighlight lang="ocaml">let () =
let i = Xmlm.make_input ~strip:true (`Channel stdin) in
let title = ref "" in
Line 463:
then print_endline !title
end
done</langsyntaxhighlight>
 
{{out}}
Line 485:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl"># 20211214 Perl programming solution
 
use strict;
Line 529:
}
}
)</langsyntaxhighlight>
{{out}}
<pre>
Line 542:
Does not rely on wget/bzcat etc. Downloads in 16K or so blocks, unpacks one block at a time in memory, terminates properly when 5 or more words are found.<br>
Tested on Windows, should be fine on Linux as long as you can provide a suitable bz2.so
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">url</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"https://dumps.wikimedia.org/enwiktionary/latest/enwiktionary-latest-pages-articles.xml.bz2"</span>
Line 631:
<span style="color: #7060A8;">curl_easy_cleanup</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Total downloaded: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">file_size_k</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tbr</span><span style="color: #0000FF;">)})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 644:
=={{header|Raku}}==
I misunderstood the data format and now just copy verbatim from Julia entry the processing logics ..
<syntaxhighlight lang="raku" perl6line># 20211209 Raku programming solution
 
use LWP::Simple;
Line 710:
my $ua = CustomLWP.new: URL => $URL ;
 
$ua.CustomRequest>>.say</langsyntaxhighlight>
{{out}}
<pre>
Line 728:
 
Rather than downloading the full 800MB .bz2 file and then decompressing it, we abort the download after receiving no more than the first 512 KB and then decompress that ignoring the resultant BZ_UNEXPECTED_EOF error. This turns out to be enough to find the first 26 French words.
<langsyntaxhighlight lang="ecmascript">/* wiktionary_dumps_to_words.wren */
 
import "./pattern" for Pattern
Line 789:
gotTextLast = false
}
}</langsyntaxhighlight>
<br>
We now embed this script in the following C program, build and run.
<langsyntaxhighlight lang="c">/* gcc wiktionary_dumps_to_words.c -o wiktionary_dumps_to_words -lcurl -lbz2 -lwren -lm */
 
#include <stdio.h>
Line 1,004:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
10,327

edits