Thursday, November 1, 2018

Input/Output

Over the summer, I took some courses on CodeAcademy, and one of them was just a command line interface (CLI) course. It didn't feel very useful except that I learned about standard input / output, and the >, >>, and | operators that allow inputs and outputs to be exchanged between commands and put to use. Even if I end up not using this exact technique, I'm really glad I had that lesson - it helped me to understand more of what the system is actually doing with files. Being used to finicky filetypes (like distinguishing between .doc and .docx), there's something very satisfying about working with the raw data and being able to transform and use it in different ways.

Earlier this evening I made a checklist of tasks I thought I would need to finish in order to get a viable working product ready to show for Saturday morning (plus two more that would need to get done at some point but weren't urgent). These were:

  • learn to issue commands to R through the CLI (done)
  • learn to pipe variables (like the user's query term) into those commands (not done yet with variables, but done with text - should be quick)
  • output whatever R outputs into a static document (done via | pipe, but might switch to php)
  • figure out how to automate serving this document (done, just fixed permissions, and now by piping right to the file on the server, the server automatically picks up those changes. Just need to trigger a refresh for the user, see below)
  • direct user to the newly generated page (not done)
  • listen for GET requests to server (not done)
  • extract the search term from the URL (not done, and may not even do it this way anymore
  • figure out the user experience - loading bar? (not done yet, related to how I redirect the user to the new page)

For a few hours' work, I'm pretty excited about what I've done: decided on PHP for pretty much the rest of the minimum viable product, figured out how to take user input and run it through a script in R and output a new page for the user. From there, everything should be mostly a matter of tweaking, and scale, and finally directing my focus toward the actual humanities/historical questions on which this tool can hopefully help offer new perspectives. 

For now, it's very exciting that I was able to input a filename (the "-washington.md" file) and specify an output file (sentiments.txt) with this:
Rscript myscript.R < pathTo/1790-01-08-washington.md > /pathTo/sentiments.txt
and then throw in this fun command, inputting a .jpg of Trump and specifying an append to that same output sentiments.txt:
jp2a /pathTo/trump.jpg >> /pathTo/sentiments.txt
and ended up with this:
who knew I would ever be pumped to see this ascii-art face pop up on my screen!

By the way, here's the original image:


Pretty good for a night's work if I may say. From the command line, I can specify a couple of filenames and get a readout of the sentiment of that text and an ascii-art image from jp2a as a bonus. If the user knew to hit refresh, the readout is even hitting the live server automatically, which is cool. Even though the sentiments from 1790 and the image of Trump have pretty much nothing to do with each other, this was a worthwhile task. I'm excited to try to figure out more PHP and get things hopefully running as a start-to-finish "use case" in the next day or two! I'll leave this image of my updated view of how the project components will fit together below, and call it a night.
a UML diagram showing the data flow from the user's query to the returned static web page
still a bit of a mess and I'm sure nothing close to UML-standard, but closer than before, and finally beginning to feel like it is reflecting reality more than just my ideas!