Skip to content
How to build digital linguistic plants using datamuse, d3.js and python FLASK.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
d3Example
demo
images
interface
lib
.gitignore
README.md
plant.py
plant_server.py
requirements.txt

README.md

Seedlings_

Transplant a word into a new context

Seedlings_ is a project created by Qianxun Chen. It is an experimental web interface to explore the artistic value of algorithmic correlations of words in data driven text analysis. Words are planted as seeds and grow into different ‘plants’ with the help of Datamuse API. It is at once an ambient piece in which words and concepts are dislocated and recontextualized constantly, and a playground for the user to create linguistic immigrants and textual nomads.

You can find a demo here.(Best Viewed in Chrome)


Technical Breakdown of the project

  • API: Datamuse
  • Back end: Python Flask Framework
  • Front end: d3.js

The following sections will be covered in the workshop.

  1. Intro to datamuse, how to use the datamuse API

  2. More about Seedlings_

  3. Basic introduction to d3.js, a JavaScript library for producing dynamic, interactive data visualizations in web browsers.

  4. Build Seedlings_ as a web app (?)

Outline

  1. Datamuse
  • 1.1 What is datamuse
  • 1.2 How to use datamuse?
  • 1.3 APIs used in Seedlings_
  1. Seedlings_
  • 2.1 Defining Plants
  • 2.2 Visualization
  • 2.3 Interface
  1. D3.js
  • 3.1 What is d3.js
  • 3.2 A basic visualization example
  1. How Seedlings_ works
  • 4.1 Setups for seedlings
  • 4.2 Plant from the Command Line!
  • 4.3 Plant server using flask
  • 4.4 PythonAnywhere


1. Datamuse

1.1 What is datamuse

datamuse

The Datamuse API is a word-finding query engine for developers. You can use it in your apps to find words that match a given set of constraints and that are likely in a given context. ”

Major Data sources

1.2 How to use datamuse?

You can access most of the features of the API at the URL api.datamuse.com/words, with the query parameters described below.

1.3 APIs Used in Seedlings_

Query parameters Example Result
rel_jjb Adjectives that are often used to describe ocean /words?rel_jjb=ocean
topics Adjectives describing ocean sorted by how related they are to temperature /words?rel_jjb=ocean&topics=temperature
rel_jja Nouns that are often described by the adjective yellow /words?rel_jja=yellow
rel_bga Frequent followers of hope /words?rel_bga=hope
ml Words with a meaning similar to perished /words?ml=perished
rel_trg "Triggers" (words that are statistically associated with pain in the same piece of text.) /words?rel_trg=pain
rel_ant Antonyms of loud) /words?rel_ant=loud
sp Words that start with t, end in k, and have two letters in between /words?sp=t??k

2.Seedlings_

2.1 Defining Plants

Type Rules
Plant Nouns(ml) <-> Adjectives(ml)
Dandelion Triggers of word in context
Ginkgo Adjectives that are often used to describe context + word
Ivy A sequence of Frequent followers(rel_bga)
Pine A list of words that start and end with the same letters as word in context

2.2 Visualization

Plant

Plant

Dandelion

Dandelion

Ginkgo

Ginkgo

Ivy

Ivy

Pine

Pine

2.3 Interface

Check here to play with Seedlings_.(Best Viewed in Chrome)


3. D3.js

3.1 What is d3.js

"D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS." It is a great tool to create beautiful, interactive, browser-based data visualizations.

d3

SVG

  • SVG stands for Scalable Vector Graphics
  • It is used to define graphics for the Web. It is not a direct image, but a way to create images following instructions. As its name suggests, it scales itself according to the size of the browser, so resizing your browser will not distort the image. All browsers support SVG except IE 8 and below. D3.js provides convenient tools to manipulate SVG.
  • Difference between Canvas and SVG: Canvas is pixel-oriented. Once the pixels hit the screen, you cannot change shapes except by overwriting them with other pixels. However, SVG is like a "draw" program, its graphical elements become part of the DOM. Any part of any shape can be changed through script and CSS.

3.2 A basic visualization example

In d3Example you can find an interactive visualization of adjective/noun relationships in English. It was made using the "rel_jjb" and "rel_jja" queries in datamuse API, and the D3 force layout.

Modify the code to create your own linguistic plant!


4.How to build Seedlings_

4.1 Setups for seedlings

4.1.1 Python environment setup

Beautiful intro to python documentation by Sam Lavigne

a. Check your python version

Open terminal on MacOS, and type in the following and hit enter.

python -V

We are using python3 in this case

b. Install pip

pip is a tool to install python library. If you are on MacOS, open terminal, using command line:

sudo easy_install pip

You will be asked for your mac password, type it and hit enter. You can also follow the install guide here.

c. Install virtualenv

virtualenv creates isolated python environments tied to specific projects. f

sudo pip install virtualenv

4.1.2 Setup Seedlings_

a. Setup directory(folder) and virtual environment

Create a new project folder "your_project_name", and cd(change directory) to this folder on terminal.
In terminal, type in the following to create a virtual environment for this project and activate it

virtualenv env
source env/bin/activate

You should see (env) at the front of the current line in terminal.

b. Install dependencies

  • datamuse, nltk, flask
pip3 install -r requirements.txt


4.2 Plant Seedlings_ from the command line!

To see demo from all plant types:

python plant.py demo

An example of a generative chain:

python plant.py test

Plant specific seedlings with the following syntax: "plant --word(noun or adjective) in --domain as --plantType"

python plant.py soft in postmodernism as plant

4.3 Build local plant server using flask

FLASK_APP=plant_server.py flask run

4.4 Deploying Flask Apps Using Python Anywhere

Video tutorial

You can’t perform that action at this time.