Wednesday, June 1, 2016

Writing/Code

Today in the #lafdh workshop we had folks working together to write original functions in Python. Ryan introduced six basic methods that are built into Python that are very useful for text processing:
  • print - print a text string or the value of a variable
  • lower - return a string in all lower case
  • len - get the length of a string
  • split - turn a string into a list, broken (by default) on white spaces
  • join - turn a list into a string
  • type - get the data type of the selected object (usually the value of a variable)
and with these, plus what we learned about variables yesterday, folks wrote functions to do cool things like
  • find out how many sentences are in the novel Moby Dick (or any other text)
  • turn a plain text passage into a list of comma separated values (.csv) so it can be opened in Excel
  • randomly switch words in a passage around, making "word salad"
The goal was to build on our work yesterday, gain confidence and experience working with a programming language, and to use computational thinking to understand how we Humanists and computers, though we see texts differently, might do some cool things together.

There were high-fives and cheers before lunch as code snippets executed without errors. And after lunch, there was a triumphant show-and-tell in which our merry band became real programmers by showing off their code and hearing from other programmers how they would have done it differently. :)

We also did some work in the afternoon building a topic model using gensim. Using libraries, moving into an IDE (from iPython notebooks) and working out i/o workflow were the real objectives in that introduction, but we did get to see and discuss the results of an LDA topic model. Real DH stuff after just two days!

No comments:

Post a Comment