I am looking into ramda and have t questions, from the following Ramda REPL:
const R = require('ramda')
//const original = require('./test/fixtures/original.json')
const original = {
speakers: {
name: 'Author',
words: [
{ duration: '0.360000', name: 'Arthur', time: '0.660000', paragraph: 'p0-0' },
{ duration: '0.150000', name: 'the', time: '1.020000', paragraph: 'p0-0' },
{ duration: '0.380000', name: 'rat', time: '1.170000', paragraph: 'p0-0' },
{ duration: '0.770000', name: '.', time: '1.550000', paragraph: 'p0-0' },
{ duration: '0.360000', name: 'Arthur', time: '89.820000', paragraph: 'p1-0' },
{ duration: '0.390000', name: 'stood', time: '90.180000', paragraph: 'p1-0' },
{ duration: '0.090000', name: 'and', time: '90.570000', paragraph: 'p1-0' }
]
}
}
const words = R.lensPath(['speakers', 'words'])
const wordsList = R.view(words, original)
const result = [...wordsList.reduce((hash, { duration, time, name, paragraph }) => {
const current = hash.get(paragraph) || { paragraph, words: [] };
current.words.push({ duration, time, name });
return hash.set(paragraph, current);
}, new Map).values()];
console.log(result);
How do I use groupBy in order to get it grouped by paragraphs instead of the above method?
From this result, how do I do a find of a string that can have one or more items, by sorting all the words in order of time and returning only the matched paragraphs?
search_criteria = 'Arthur stood';
results = [
{ para: 'p1-0',
words: [
{ 'name': 'Arthur', 'time': 89.820000},
{ 'name': 'stood', 'time': 90.180000}
}
]
How would you replace these items with replace = 'Arthuro stopped'?
Any advise is much appreciated.