User:DavidBrooks/wikimatch

From Wikipedia, the free encyclopedia

# If using the page source, remove the <pre> tag and the closing tag
# before running through the PERL interpreter.

# Start with the wiki source of an page containing a list of mostly red links.
# add the following changes:
# Drop any ' characters
# If any hyphens, lcase all but first character, then replace - by space
# word1 word2 ... wordn -> word1 wordn and word1 word2
# Uncapitalize all but first word

# Copies stdin to stdout

use POSIX qw(strftime);
$gmt = strftime "%b %d %Y %H:%M", gmtime;
print "Processed $gmt UTC\n\n";

print "'''Note:''' A \"blue link\" in the main column does not guarantee that the WP entry is\n";
print "on the same topic as the EB entry. If there is the slightest ambiguity, please check.\n\n";

while (<>) {
if (/{{/ || /^$/ || /\[\[Category:/) {
        next;
}

if (! /^#/) {
        print;
        next;
}

chop;
s/^.\[\[([^\]]*)\]\].*/\1/;
print "<br>      Article in EB2004: '''[[".$_."]]'''\n";


if (/'/) {
        $noquote = $_;
        ($noquote = $_) =~ s/'//;
        print "<br>[[".$noquote."]]\n";
}

if (/-/) {
        print "<br>[[".ucfirst(lc)."]]\n";
        s/-/ /g;
        print "<br>[[".$_."]]\n";
}

@words = split(/ /);
$nwords = $#words;
$firstword = $words[0];
if ($nwords > 1) {
        $lastword = $words[$nwords];
        printf "<br>[[%s %s]]\n", $firstword, $lastword;
        printf "<br>[[%s %s]]\n", $firstword, $words[1];
}
if ($nwords > 0) {
        print "<br>[[".$firstword;
        for ($i = 1; $i <= $nwords; $i++) {
                print " ".lc($words[$i]);
        }
        print "]]\n";
}
}