Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Monday, September 21, 2009

A Pilingual Month for Me

Blogging has taken a backseat this month to computer programming. Most of the words I've written over the past month have been in Ruby, PHP or SQL, with English way back in 4th place. I've therefore appropriated Douglas Hofstadter's neologism "pilingual" to title this post.

Besides my usual penchant for screwing around with cool technology, my latest programming has been aimed at several potential papers for the 2010 ARRS and AUR meetings, whose abstract deadlines loom next week.

Blogging here will thus continue to be lean until all abstracts have been safely excreted.

Thursday, March 5, 2009

I've Been Programming

I haven't posted much lately, mostly because I've been tightly focused on a computer programming project. Let's just say that programming is easily as jealous a consort of one's time as blogging.

I've programmed personal computers ever since my first Radio Shack TRS-80 Model I back in 1976. I got my first Apple II a year later, and have stayed in the Apple fold ever since. Since 1976, I've programmed in Basic, Fortran, assembly language, several machine languages, Pascal, Python, S, R, C, Perl and a few others.

For the past few years, I've been closely eyeing Ruby, a relatively new language, but haven't had the right incentive to dive into it. However, there's nothing like building a cool, new project to learn a new language.

I've spent much of my academic time in the past two weeks writing a web-based text-to-speech application in Ruby. My goal: type in the volume, issue and page number of some article in a major radiology journal and get back an .mp3 version of that article, read by a fairly decent computerized voice.

It turned out to be a lot easier than I thought it would be, even with a few years of web-apps under my belt. Ruby is a fine language, with a fine library of built-in tools, making it easy to scrape a whole web page with just a few lines of Ruby code. For example, the following code is all that's necessary to grab a whole article from the American Journal of Roentgenology and assign it to the variable ajr_html:
urlRaw = "http://www.ajronline.org/cgi/content/full/"
+ ajrVolume +"/" + ajrIssue + "/" + ajrPage
ajr_url = open(urlRaw)
ajr_html = ajr_url.read
I have recently become a big fan of text-to-speech conversion. In December, I discovered a new Mac program called Textcast. Since then, I've used Textcast to make one or two hundred podcasts for my iPhone from NY Times articles and various blogs I follow. These have been a major defense against boredom during my work commutes -- sort of like having an NPR station where all the stories are interesting.

The only issue I have with Textcast is that it is optimized only for pages from Safari or NetNewsWire. If I want to use it to grab and convert an article from AJR or Radiology, I need to first do some serious hand-scrubbing of the text from their websites before I can feed it into Textcast. I got pretty tired of this after laundering a few articles by hand. My new Ruby script takes virtually all of the drudgery out of this process.

Now that I've refined my program into a reasonably stable version, I've asked several of my residents, fellows and fellow faculty to do some alpha testing. Once I get their feedback, I'll write it up for one of our radiology journals. Might as well get some academic mileage out of it.