Difference between revisions of "Computational Poetry"

From Wikicliki
Jump to: navigation, search
(Mac)
Line 46: Line 46:
 
=== Mac ===
 
=== Mac ===
  
All new Macs have python installed. First open Terminal (Which can be found inside Applications > Utilities). Check which version of python you have by typing "python" into Terminal. Then navigate to the folder with your files inside it.
+
'''Python SimpleHTTPServer'''
 +
 
 +
All new Macs have Python installed. First open Terminal (Which can be found inside Applications > Utilities). Check which version of python you have by typing "python" into Terminal. Then navigate to the folder with your files inside it.
  
 
<pre>cd /path/to/project/folder </pre>
 
<pre>cd /path/to/project/folder </pre>
Line 57: Line 59:
 
# Python 3.x
 
# Python 3.x
 
python -m http.server</pre>
 
python -m http.server</pre>
 +
 +
Files from that directory will be served up at localhost under port 8000, so you can view the files from that directory if you type this into the browser:
 +
 +
<pre>http://localhost:8000/</pre>
 +
 +
 +
Apache
 +
 +
First, open the Terminal app and switch to the root user so you can run the commands in this post without any permission issues:
 +
 +
sudo su -
 +
Enable Apache on Mac OS X
 +
apachectl start
 +
Verify It works! by accessing http://localhost or http://localhost:8080/
 +
 +
Enable PHP for Apache
 +
Make a backup of the default Apache configuration. This is good practice and serves as a comparison against future versions of Mac OS X.
 +
 +
<pre>cd /etc/apache2/
 +
cp httpd.conf httpd.conf.bak</pre>
 +
 +
Now edit the Apache configuration. Feel free to use TextEdit if you are not familiar with vi.
 +
 +
<pre>vi httpd.conf</pre>
 +
 +
Uncomment the following line (remove #) - press X over the letter and save with :wq
 +
 +
<pre>LoadModule php5_module libexec/apache2/libphp5.so</pre>
 +
 +
Restart Apache:
 +
 +
<pre>apachectl restart</pre>
 +
 +
Verify PHP is enabled by creating a page in your DocumentRoot.
 +
 +
The default DocumentRoot for Mac OS X El Capitan is /Library/WebServer/Documents. You can verify this from your Apache configuration.
 +
 +
<pre>grep DocumentRoot httpd.conf</pre>
 +
 +
 +
Other alternatives:
 +
* http://stackoverflow.com/questions/12905426/what-is-a-faster-alternative-to-pythons-simplehttpserver
  
 
=== Win ===
 
=== Win ===

Revision as of 06:29, 2 November 2016

Welcome to the notes for a Computational Poetry Class by Debbie Ding, held at The Substation on 3 November 2016!

Introduction

This class is designed for people who do not have any programming background but who have an interest in generative poetry and have an open mind to learning some simple methods for non-coders to create their own textual mashups. In this 2 hour class we will try to cover:

  • A Very Very Brief History of Bots, AI, and Spam
  • Introduction to RiTa + p5.js
  • Setting up a local web server on your computer (Mac/Win)
  • Generating a simple 'Singlish Haiku'
  • Generating a duologue between Belle (Disney's Beauty and the Beast) and Didi (Waiting for Godot)
  • Generating a prose mashup

and hopefully, some time for experimentation!

Equipment required:

  • a working laptop (most modern laptops should work)
  • wifi connection (which will be available at the substation)
  • example files (will be available for download at the class - I'll also have it available on thumbdrives)
  • and you! the human input!

Skills required:

  • being able to type on a laptop
  • being a human

I first decided to make this when someone (a designer, not a programmer) asked me how to create a text mashup and I was trying to explain to her how simple it was to do with open source libraries such as RiTA. In today's class, I'd like to share with you the most simple way to create a text mashup from available open source tools, which will hopefully spark your further adventures into other aspects of natural language processing...

A Very Very Brief History of Bots, AI, and Spam

Glossary of Terms used in this page

  • HTML - Hyper Text Markup Language. This is a Markup language, not a programming language, which means it is a language used to define the content in a webpage.
  • Javascript - is a programming language commonly used with HTML. It is used to create functionality in a webpage.
  • AJAX - Asynchronous JavaScript and XML - which means to use the XMLHttpRequest object to communicate with other server-side scripts. It is "Asynchronous" because it can make new requests to the server without requiring the page to be reloaded, and thus it is used to update the page based on events. This is really useful and is often used to make pages 'responsive', allowing you to design a page that will change accordingly as you resize the browser window.

For more definitions:

Setting up your own Web Server

Why do you need to set up a "local web server"?

If you open up a HTML page in your browser, most browsers restrict how that HTML page can access other resources. For example: A script on http://dbbd.sg can only perform AJAX requests for other files on http://dbbd.sg, but a file on your computer (which we would refer to a a "local file") has no domain, and therefore cannot perform any AJAX requests.

To get around this, you can either change your browser's security settings for local files, but this is generally inadvisable, as you would not want pages and scripts from the internet to be able to open or access local files on your computer - that would pose a great security risk. So, we have to set up a local web server in order for us to be able to run these scripts today.

Mac

Python SimpleHTTPServer

All new Macs have Python installed. First open Terminal (Which can be found inside Applications > Utilities). Check which version of python you have by typing "python" into Terminal. Then navigate to the folder with your files inside it.

cd /path/to/project/folder 

Use Python's built-in http server:

# Python 2.x
python -m SimpleHTTPServer

# Python 3.x
python -m http.server

Files from that directory will be served up at localhost under port 8000, so you can view the files from that directory if you type this into the browser:

http://localhost:8000/


Apache

First, open the Terminal app and switch to the root user so you can run the commands in this post without any permission issues:

sudo su - Enable Apache on Mac OS X apachectl start Verify It works! by accessing http://localhost or http://localhost:8080/

Enable PHP for Apache Make a backup of the default Apache configuration. This is good practice and serves as a comparison against future versions of Mac OS X.

cd /etc/apache2/
cp httpd.conf httpd.conf.bak

Now edit the Apache configuration. Feel free to use TextEdit if you are not familiar with vi.

vi httpd.conf

Uncomment the following line (remove #) - press X over the letter and save with :wq

LoadModule php5_module libexec/apache2/libphp5.so

Restart Apache:

apachectl restart

Verify PHP is enabled by creating a page in your DocumentRoot.

The default DocumentRoot for Mac OS X El Capitan is /Library/WebServer/Documents. You can verify this from your Apache configuration.

grep DocumentRoot httpd.conf


Other alternatives:

Win

Rita and p5.js

== Examples

Poem

Duologue

Prose