Skip to content

Instantly share code, notes, and snippets.

@nchibana
nchibana / updatedata.js
Created October 17, 2019 23:29
d3 update data function
function updateData(){
d3.json('https://storyplotsapp.herokuapp.com/api', {
method:"POST",
body: JSON.stringify({
movie_title: ItemSelect
}),
headers: {"Content-type": "application/json; charset=UTF-8"}
}).then(function(data){
console.log(data);
// // Prepare and clean data
@nchibana
nchibana / cluster.py
Last active October 17, 2019 23:21
hierarchical clustering
from scipy.cluster.hierarchy import fcluster
import scipy.cluster.hierarchy as hac
Z = hac.linkage(df_interpolate.iloc[:,0:266], method='ward', metric='euclidean')
# k Number of clusters I'd like to extract
results = fcluster(Z, k, criterion='maxclust')
@nchibana
nchibana / process.py
Created October 17, 2019 23:14
simple labMT process function
def process():
windowSizes = [2000]
words = [x.lower() for x in re.findall(r"[\w\@\#\'\&\]\*\-\/\[\=\;]+",raw_text_clean,flags=re.UNICODE)]
lines = raw_text_clean.split("\n")
kwords = []
klines = []
for i in range(len(lines)):
if lines[i][0:3] != "<b>":
tmpwords = [x.lower() for x in re.findall(r"[\w\@\#\'\&\]\*\-\/\[\=\;]+",lines[i],flags=re.UNICODE)]
kwords.extend(tmpwords)
@nchibana
nchibana / arousal_lexicon.py
Last active October 17, 2019 23:09
new lexicon
dict = pd.read_csv('./NRC-VAD-Lexicon-Aug2018Release/NRC-VAD-Lexicon-Aug2018Release/NRC-VAD-Lexicon.txt', sep='\t')
dict['Ranking'] = np.arange(1, len(dict)+1)
columnsTitles = ["Word","Ranking","Arousal","Valence","Dominance"]
dict = dict.reindex(columns=columnsTitles)
dict['Arousal'] = dict['Arousal'].astype(str)
newDict = dict.set_index('Word').T.to_dict('list')
@nchibana
nchibana / download_all_scripts.py
Last active May 15, 2023 15:24
Scrape IMSDB movie scripts
import os
from urllib.parse import quote
from bs4 import BeautifulSoup
import requests
BASE_URL = 'http://www.imsdb.com'
SCRIPTS_DIR = 'scripts'