Join 3,552 readers in helping fund MetaFilter (Hide)


Generating Hyperlinks Automatically?
May 4, 2007 7:09 AM   Subscribe

I would like to automatically generate hypertext links from a list of text. Ideally this would mean pasting a series of comma separated words into some online tool and having the system turn each word into a relevant google/wikipedia link... Does anyone know any sites/tools that will do this?

Just for anyone who is interested, here's the text I want to auto-link:

Zeus, Zam, Zababa, Yu-Huang-Shang-Ti, Yeng-Wang-Yeh, Yara Ma Yha Who, Yahweh, Ya Mughnee, Ya `Aallah, Xochiquetzal, Xipe Totec, Xbalanque, Winabozho, Warohunugamwanehaora, Waramurungundi, Wakahiru-Me, Wadjet, Voltumna, Vishnu, Venus, Uttu, Urcaguary, Ulaulekeahi, Uke-Mochi-No-Kami, Ukapirmas, Turiacus, Tsukuyomi, Torngasoak, Tonatiuh, Tlahuizcalpantecuhtli, Thoth, Thor, Tharapita, Tekkeitserktock, Tāwhiri-matea, Take-Mikazuchi, Swāikstiks, Spandarmet, Sobek, Skadi, Shiva, Shina-Tsu-Hiko, Shamash, Shai'-ha-Qawm, Seaxnéat, Saraswati, Saosyant, Runesocesius, Roonikka, Rimmon, rDo-rje-rnal-hbyor-ma, Raluvhimba, Quirinus, Qaynan, Ptah, Prajnaparamita, Potrimpos, Poshaiyankayo, Persephone, Pellon Pekko, P'an-Chin-Lien, Osiris, Odin, Occupirn, Nzambi, Ninhursag, Nevinbimbaau, Nephthys, Nanghaithya, Nana Buluku, Nai-No-Kami, Mudungkala, Morrigan, Morpheus, Morgan, LeFay, Moaalii, Mar'rallang, Marduk, Mao, Mantis, Manisilat, Mama Pacha, Maahes, Lonomakua, Leviathan, Lemminkainen, Lakshmi, Laima, Kunapipi, Kukalikimoku, Ku, Krishna, Koko, Kiskil-lilla, Kishar, Khnum, Khahdoma, Kapohoikahiola, Kaluannuunohonionio, Joukahainen, Jengu, Jehovah, Jahwe, Izanami, Isis, Inanna, Igaluk, Huruing Wuhti, Huitzilopochtli, Horus, Hine Raumati, Hiiakawawahilani, Hendursanga, Heimdall, Hecate, Hastshehogan, Hanuman, Hades, Gudratrigakwitl, Gebeleizis, Garuda, Ganesha, Gandarewa, Frigga, Estasanatlehi, Ereshkigal, Epona, Dolichenus, Dionysos, Dhakhan, Demeter, Dēiwas, Dattatreya, Coyolxauhqui, Chimata-No-Kami, Ch'eng-Huang, Cernunnos, Carmenta, Caillech, Bunbulama, Branwyn, Birrahgnooloo, Bikeh Hozho, Berekyndai, Balac, Bahá'u'lláh, Baal-Qarnain, Athena, Asha Vahishta, Arnarquagsag, Archons, Aramurungundju, Apollo, Apocatequil, Aphrodite, Antero Vipunen, Anitun Tabu, Angwusnasomtaka, Amaunet, Amaterasu, Amaethon, Aji-Suki-Taka-Hi-Kone, Ahmeto Lela Okya, Agadjimbiri, Adnoartina
posted by 0bvious to Computers & Internet (8 answers total) 1 user marked this as a favorite
 
I wrote this, which yielded this, as an example of how you might do it in perl. This is a very rough, 2-minute script. But something like that could work.

I'm not in the mood to make this print on metafilter, so you'll have to click the links.
posted by popechunk at 7:43 AM on May 4, 2007


Open up your CSV in Excel. (Or Google spreadsheets, if you don't have Excel.)

Insert the following formula:
= "http://www.google.com/search?q=" & A1

Which produces:
http://www.google.com/search?q=zeus
posted by desjardins at 7:46 AM on May 4, 2007


A couple of lines of Perl would do the trick. Just split the list (on comma-space) into an array, then loop through the array and construct a new output string based on the simple URL format of both Wikipedia and Google. E.g.:


// Replace this with your full list.
my $sInput = "Zeus, Zam, Zababa";
my $sOutputGoogle = ';
my $sOutputWikipedia = ';

my @input = split (', ', $sInput);
foreach my $s (@input)
{
if ($sOutputGoogle ne ')
{
$sOutputGoogle .= ', ';
$sOutputWikipedia .= ', ';
}
// Wikipedia URL is http://en.wikipedia.org/wiki/foo
// Google URL is http://www.google.com/search?source=ig&q=foo
$sOutputGoogle .= "<a href='http://www.google.com/search?source=ig&q=$s'>$s";
$sOutputWikipedia .= "<A HREF='http://en.wikipedia.org/wiki/$s'>$s";
}


// Replace these filenames.
open GOOGLEOUT, '>C:\google.htm';
print GOOGLEOUT $sOutputGoogle . "\n";
close GOOGLEOUT;

open WIKIOUT, '>C:\wikipedia.htm';
print WIKIOUT $sOutputWikipedia . "\n";
close WIKIOUT;

Note that the Wikipedia versions link in many cases to the "foo can not be found; would you like to create it?" page.
posted by Doofus Magoo at 7:46 AM on May 4, 2007


Oh, and on unix-alike machines, you run it like this:

/path/to/example.pl < input_file > output.html

posted by popechunk at 7:47 AM on May 4, 2007


I did it in two lines with sed and got this (for Wikipedia, of course). I accidentally deleted the script, but could regenerate it in a minute if you want it.
posted by cerebus19 at 7:50 AM on May 4, 2007


Are those names of gods? Because "Ya `Aallah" could just be Allah.
posted by divabat at 7:56 AM on May 4, 2007


It would take some time, but I'd highly recommend learning the basics of regular expressions for this kind of thing. You don't have to learn a full blown programming language like Perl; just find a text editor or HTML editor with support for regular expressions. Two freeware editors to consider are NoteTab Light and PSPad.

For any kind of repetitive text editing or complex search and replace, regular expressions can't be beat.
posted by xulu at 11:48 PM on May 4, 2007


thanks for the help!
posted by 0bvious at 5:44 AM on May 5, 2007


« Older I was at work the other day an...   |  Help me find the name and a co... Newer »
This thread is closed to new comments.