Dots never felt like such an accomplishment

Behold:

The Travels of Widsith (through line 30)

The Travels of Widsith (through line 30)

This may not seem like much (trust me, I know), but this image above represents a real albatross to me, one that I look forward to removing from my neck so I can get back to the serious business of trying to make my website not suck (along with all the rest of the stuff I’m supposed to be doing).

There are a number of problems with this image that I could list, but the fact that I have dots on the map, and indeed that there is a map at all, kind of overshadows my disappointment in my own abilities here.  I know I’ve mentioned it before, but I’m not really geographically inclined.  I also have varying levels of patience with software that is designed for a very narrow user base, especially when that user base does not include me or anyone with whom I converse on a semi-regular basis.  Add in the fact that the software in question is open source, meaning that it is designed by people who donate their time to make it work, but don’t necessarily donate their time to make it usable, and we have  a perfect storm, or at least the prime conditions for me to go remove the software suite tout suite.

Nonetheless, I seem to have found a way to make Quantum GIS (QGIS) put the things I want in a place I can live with, which is satisfactory.  Just don’t expect me to invite it over for dinner.

Ultimately, the process of getting those dots up there would have been a lot easier had I been smart and selected a map project that didn’t require me to delve as deeply into the research as mine did.  Indeed, the fact that there are so few dots on that map is indicative of the fact that I was only able to process the tribes from the first thirty or so lines of Widsith.  There are, in all seriousness, about one hundred more dots to place if I were to be completionist about this, which I might be as I have a bit more time.  It might even be fun to use some Javascript to make the thing interactive at some point, placing a copy of the poem next to the map and highlighting the location when the tribe’s name receives mouse focus or something.

Still, since we’re supposed to be showing our steps, I’ll start with this:

You’ll notice that I’ve got a decent amount of information in there.  I collated what I could glean out of Kemp Malone’s study of the poem along with additional scholarship on the Web and then did my best to put dots in locations that seemed like they were reasonable.  Let me reiterate: there is so much up in the air about all of this that any sort of attempt to locate the majority of these tribes is an act of speculation at best.  The points on the map are there only to designate the most general places possible because I have neither the time nor the patience to learn how to work with areas and polygons.  The purpose was to give a general idea of how widely traveled Widsith claims to be; the dots do well enough to get that point across.

From there, it was easy enough to import the Google sheet into Google’s Maps Engine.

Well, sort of, anyway.  The data went in just fine, but certain parts, like the hyperlinks, didn’t convert for some reason.  I had to go in and manually add each of the hyperlinks to the data table of each group, being careful to put the right link in the right spot.  The fact that the data in the Maps Engine software had been moved around made it far more difficult than it needed to be, but I got it in there eventually, anyway.  To its credit, however, the software automatically created a hyperlink out of the URL I posted in each cell.

Afterwards, I had to get it overt to QGIS.  I followed Jessica Troy’s advice and installed Google Earth before doing much else.  I then went back into Maps Engine Lite and exported the map as KML.  I then opened the new KML file as a layer in Google Earth.  Voilá!  More dots!

My spreadsheet data as rendered by Google Earth

My spreadsheet data as rendered by Google Earth

I then cast about, looking for a way to save the data I had imported as something other than it was to begin with.  I found nothing.  Curious about what would happen if I just entered the KML file into QGIS directly, I plugged the file in, and then followed Jessica’s directions for getting a base map working.  I’m not sure if just having Google Earth installed made some sort of difference, but I was able to get the information inside of QGIS without a problem.  The results are what you see at the top of this article.

I’m not really all that interested in making a map that does fun, dynamic things online.  As much as it would be cool to be able to switch the different locations on and off by fit or thula, I think I’d rather concentrate on getting the data entered in as completely as possible.  Still, there must be projects for the future, as well, which merely reminds me to remain philosophical about GIS and its role in visualizing history and literature.

Scraping Web Pages (But Not Off of the Kitchen Floor)*

Baby Steps by marisag on Flickr

Baby Steps by marisag on Flickr. Creative Commons license

Okay, so this is going to be a middle-of-the-process post as I attempt to make something useful using Python.  Specifically, I’m working on learning how to scrape web pages for content without going crazy or devoting more time to such a project than I would already use simply by going to each of these web pages and manually copying and pasting the text.  I say that it’s the middle of the process because I’ve already done some of the work (success!), although there’s still a lot to do and several technological problems to overcome first (not-yet-failures).

First, though, it’s probably a good idea for me to clarify the project so that I can talk lucidly about what I have not yet done.

Ultimately, this scraping project is about getting some texts together so that I can create some useful topic models for my own research on the Exeter Book. I’ve mentioned before that the corpus of surviving Anglo-Saxon poetry is fairly limited; we have a mere 30,000 lines or so, and those lines exist, for the most part, in four collections: the Junius Manuscript, the Vercelli Book, the Nowell Codex, and the Exeter Book.  Each of these books has been published several times, both as complete collections and as editions of individual poems.  This presents a problem insofar as the creation of topic models are dependent on great numbers of texts which, in this case at least, are not extant.

Well, the best thing I can do is work with what I have.  Jessica came across a pretty good source for the texts online, too: http://www.sacred-texts.org/neu/ascp/ seems to be pretty okay, and the fact is that I’m not at a point in the semester where I can go through and check their editing job, anyway.  This site certainly meets one criterion, though: the text isn’t bogged down with a lot of other material.  With relatively straightforward HTML, then, I should be able to scrape away with no issues!

With that in mind, I needed to develop a plan with definable goals so I could start getting done what needs to get done.  I came up with the following list of steps:

  1. Scrape the URLs of the child pages from the landing/parent page
  2. Remove the small number of unwanted URLs from the results
  3. Scrape the child pages
  4. Write the “scrapings” to a text file
  5. Profit!

So far, this is what I’ve done:

  1. Toss my current Python environment and start running Linux
  2. Install BeautifulSoup and a few other modules into Python
  3. Scrape the URLs of the child paes from the landing/parent page
  4. Write the scraped URLs to a text file

The first step was a little more work than I really wanted it to be; I’ve been running Python inside a Linux-like environment on Windows called Cygwin, but that has started to be more trouble than it’s worth.  For example, every tutorial I read on BeautifulSoup told me to start the script with the line

from bs4 import BeautifulSoup

The problem there is that Cygwin’s version of Python needed something different, specifically:

from BeautifulSoup import BeautifulSoup

I arrived at this information through extensive trial and error, not through any documentation, which is a real problem in Cygwin, it seems, because there are other differences in Python, as well, such as the use of module names written in camel-caps (capitalizing the first letter of the second word instead of using a space or underscore) instead of the otherwise-universally used underscore method of calling modules.  There needed to be a better way.

Indeed there was; rather than give up on Linux and its advantages for doing things in Python, and rather than continuing to suffer through the Cygwin problem, I decided to install Ubuntu on a flash drive and run from that.  This solution is great because it doesn’t wipe my hard drive at all, it doesn’t cause any problems as far as compatibility is concerned (as Windows or Cygwin do), and this way I get to play with Linux while scraping away.

Once in my new environment, I was happy to see that I could install and run the various necessary modules with the same common commands listed in much of the documentation we’ve seen linked in class.  The next problem would be to use the modules to scrape the code from the parent page.  Cobbling together code from two or three tutorials, I ended up with a script that looks like this:

from bs4 import BeautifulSoup
import requests

url = "http://www.sacred-texts.org/neu/ascp"
r  = requests.get(url)
data = r.text
soup = BeautifulSoup(data)

for link in soup.find_all('a'):
	address_text = link.get('href')
	target = open("target\targetURLs.txt", 'a')
	target.write(address_text)
	target.write("\n")
	target.close()

This worked straight off the bat.  It also provided me with a text file of the results, which means that I can go through and manually clean up the two or three additional links that I don’t need to follow when building my catalog of Old English poetry.

There you have it.  My next goal is to learn how to read through the text file and load each line into a loop so that it can function as a full URL.  Then it’s off to scraping to another file and ultimately to cleaning up the text, although I may have a lead on the latter that will make things a lot easier, even it it is a little bit like cheating.  More later!

*In case you’re wondering, the title is a reference to one of the recent cartoons that marks the triumphant return of Homestar Runner, or in this case, the triumphant return of Strong Bad and the Cheat making music videos.

A Minor Victory: OE, OCR, and Frequency Clouds Through Voyant

I thought it only right to post a counterpoint to my last little rant because “text mining” is one of the biggest reasons I decided to enroll in Digital Methods in the first place.  Although visualizing word frequencies and other elements is not necessarily what I would have put down as my most important priority, it is certainly satisfying to be able to share with you the very quick and interesting, if completely unscientific, results of dumping the entire plain text scan of Gollancz’s 1895 edition of the Exeter Book into Voyant.

As this edition has both Old English and 19th century Modern English in play, we see an interesting mix here.  It seems that the most common OE words are, as one would expect, pronouns: seic, etc., although the negator “ne” is also “popular.”  As I continue to play around with this text, I’ll post anything new I discover.

Word cloud

Generated at voyant-tools.org from the Gollancz 1895 edition of the Exeter Book