• # Re: Probleme avec le detecteur d'url

    Posté par . En réponse au journal Probleme avec le detecteur d'url. Évalué à 2.

    Hors sujet mais un petit peu plus de perl sur DLFP !
    Je l'avais déjà envoyé il y a un an ... et on m'a dit que c'était en cours

    3 parties :
    - un script perl "spellcheck", renvoie une liste des mots faux et les propositions
    - le javascript en html, certain caractères doivent être nettoyés avant d'être transmis à ispell
    - une page html en mod_perl/mason (adaptable en php) qui appelle le script perl et affiche

    ===spellcheck====
    #!/usr/bin/perl -w

    $| = 1;

    use Lingua::Ispell qw( spellcheck );
    use strict;

    my @result;
    my @prop;
    #Lingua::Ispell::use_dictionary("french");

    while ( <> ) {
    chomp;
    my $line = $_;

    for my $r ( spellcheck( $line ) ) {

    if ( $r->{'type'} ne 'ok' ) {
    push (@result,"$r->{'term'}"); };

    if (defined(@{$r->{'misses'}})) {
    foreach my $term (@{$r->{'misses'}}) {
    push (@prop,"$term");
    }
    }

    }
    }

    foreach my $line (@result) {
    print "$line\n";
    }
    print "---\n";

    foreach my $line (@prop) {
    print "$line\n";
    }

    ===javascript==
    <script type="text/javascript">
    function help() {
    var winhelp = window.open('','aide','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=200');
    winhelp.focus();
    }

    function ispell() {
    var str;
    str=document.forms[0].col.value;

    str = str.replace(/\n/g," ^ ");
    str = str.replace(/\&/g,"");
    str = str.replace(/~R/g,"'");
    str = str.replace(/~\/g,"oe");
    str = str.replace(/~Q/g,"'");
    str = str.replace(/~S/g,"\"");
    str = str.replace(/~T/g,"\"");
    var url="ispell.html?text=" + str;
    var winispell = window.open(url,'ispell','height=400,width=400,scrollbars=yes,dependent')
    winispell.focus();
    }

    </script>

    ======ispell.html====
    <table width=100%>
    <TR><TD>
    <% $text %>
    </TD>
    </TR>
    </TABLE>
    <HR noshade>
    <PRE>
    <% @prop %>
    </PRE>

    <%args>
    $text=>""
    </%args>

    <%init>
    my $dir=$m->fetch_comp("ispell.html")->source_dir;

    $text=~s/\*|\\||_|<|>|;|\%|\"//g;

    my @res=`echo "$text" | $dir/spellcheck`;

    my @prop; my $fprop=0;
    foreach my $change (@res) {
    chomp($change);
    $fprop=1 if ($change =~ /^---/);
    if ($change !~ /^---/ && !$fprop) {
    $text=~s/$change/<font color=red>$change<\/font>/gi;
    } else {
    push (@prop,"$change\n"); }
    }

    $text=~s/ \^/<BR>/g;

    </%init>