~mwshinn/+junk/notes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl

# This script queries the NCBI eSpell feature as a spell-check
# dictionary.  It takes one argument: a word that may or may not be
# misspelled.  This will exit with exit code 0 if the word is correct,
# or print a list of possible corrections and exit 1 if it is not.
# Exits 255 on an HTTP error, or 2 on an unknown error.

if ($#ARGV != 0) {
    die "\nUsage: ./ncbi-espell-lookup.pl [WORD]\nWORD is the word to check in the NCBI dictionary.";
}

$url = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/espell.fcgi?db=pubmed&term=$ARGV[0]";
$command = "curl -sL \"$url\"";
$_ = `$command`;
if ($? == 0) { # Success
    if (m/<CorrectedQuery\/>/ || m/<CorrectedQuery>$ARGV[0]<\/CorrectedQuery>/) {
        exit(0);
    }
    elsif (m/<CorrectedQuery>(.*)<\/CorrectedQuery>/) {
        print $1;
        exit(1);
    }
    else {
        exit(2);
    }
}
else {
    print "___ERROR___";
    exit(255);
}