Published
Edited
Sep 25, 2018
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vttToJson = require('vtt-to-json@0.1.1/index.js').catch(() => window.convertVttToJson)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
videoID = "q_q61B-DyPk"
Insert cell
Insert cell
function getSubtitles(videoID){
getYoutubeSubtitles(videoID).then(subtitles => {
console.log(subtitles)
subtitles_holder.push(subtitles)
return subtitles
})
.catch(err => {
console.log(err)
subtitles_holder.push(err)
})
}

Insert cell
// subtitles = getSubtitles(videoID)
Insert cell
Insert cell
Insert cell
Insert cell
json_transcript_output = vttToJson(vtt_string)
.then((result) => {
return(result)
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getAllWords(json_){
let all_words = [];
for (var i = 0; i < json_.length; i++) {
let words = json_[i]["words"]
for (var j = 0; j < words.length; j++){
all_words.push(words[j]["word"])
}
}
return all_words
}
Insert cell
Insert cell
Insert cell
function turnArrayofWordsIntoString(arrayOfWords){
let wordString = "";
for (var i = 0; i < arrayOfWords.length; i++) {
console.log(arrayOfWords[i])
wordString = wordString+" "+arrayOfWords[i]
}
return wordString
}
Insert cell
Insert cell
words = turnArrayofWordsIntoString(all_words_array)
Insert cell
Insert cell
Insert cell
Insert cell
VERBS = nlp(words).verbs().out('array')
Insert cell
Insert cell
NOUNS = nlp(words).nouns().out('array')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
json_transcript_output
Insert cell
function getNounsByTime(words_andtime){
var newArrayForObj = []
for(var i = 0; i < words_andtime.length; i++){
var newObj = {}
newObj['start'] = json_transcript_output[i]['start']
newObj['end'] = json_transcript_output[i]['end']
var nouns_obj = json_transcript_output[i]['words']
var all_nouns = []
for (var j = 0; j < nouns_obj.length; j++){
all_nouns.push(nouns_obj[j]['word'])
}
newObj['nouns'] = longerWords2(all_nouns)
//newObj['nouns'] = nlp(turnArrayofWordsIntoString(json_transcript_output[i]['words'])).nouns().out('array')
newArrayForObj.push(newObj)
}
return newArrayForObj
}
Insert cell
Insert cell
function reStructureWordsForTime(nouns_and_timeGroup){
var newArrayofObj = []
for(var i = 0; i < nouns_and_timeGroup.length; i++){
var start = nouns_and_timeGroup[i]['start']
for (var j = 0; j < nouns_and_timeGroup[i]['nouns'].length; j++){
var wordObj = {}
wordObj['time'] = parseInt(start)+(j*200)
wordObj['word'] = nouns_and_timeGroup[i]['nouns'][j]
newArrayofObj.push(wordObj)
}
}
return newArrayofObj
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more