我有以下代码:
const original = {
speakers: {
name: 'Author',
words: [
{ duration: '0.360000', name: 'Arthur', time: '0.660000', speaker: 'p0-0' },
{ duration: '0.150000', name: 'the', time: '1.020000', speaker: 'p0-0' },
{ duration: '0.380000', name: 'rat', time: '1.170000', speaker: 'p0-0' },
{ duration: '0.770000', name: '.', time: '1.550000', speaker: 'p0-0' },
{ duration: '0.360000', name: 'Arthur', time: '89.820000', speaker: 'p1-0' },
{ duration: '0.390000', name: 'stood', time: '90.180000', speaker: 'p1-0' },
{ duration: '0.090000', name: 'and', time: '90.570000', speaker: 'p1-0' }
]
}
}
const R = require('ramda');
const wordsPath = R.lensPath(['transcript', 'words']);
const wordsSpeakers = R.pipe(
R.view(wordsPath),
R.groupBy(R.prop('para')),
R.map(R.map(R.dissoc('para'))),
R.toPairs,
R.map(R.zipObj(['para', 'words']))
)(Transcript);
console.log(wordsSpeakers)
返回:
[
{
speaker: 'p0-0',
words: [
{
duration: '0.360000',
name: 'Arthur',
time: '0.660000'
},
{
duration: '0.150000',
name: 'the',
time: '1.020000'
},
{
duration: '0.380000',
name: 'rat',
time: '1.170000'
},
{
duration: '0.770000',
name: '.',
time: '1.550000'
}
]
},
{
speaker: 'p1-0',
words: [
{
duration: '0.360000',
name: 'Arthur',
time: '89.820000'
},
{
duration: '0.390000',
name: 'stood',
time: '90.180000'
},
{
duration: '0.090000',
name: 'and',
time: '90.570000'
}
]
}
]
如何修改代码,以便将每个发言者的实际段落添加到每个发言人的数组列表中?
以便我得到以下输出:
[
{
speaker: 'p0-0',
words: [
{
duration: '0.360000',
name: 'Arthur',
time: '0.660000'
},
{
duration: '0.150000',
name: 'the',
time: '1.020000'
},
{
duration: '0.380000',
name: 'rat',
time: '1.170000'
},
{
duration: '0.770000',
name: '.',
time: '1.550000'
}
].
paragraph: `Arthur the rat.
},
{
speaker: 'p1-0',
words: [
{
duration: '0.360000',
name: 'Arthur',
time: '89.820000'
},
{
duration: '0.390000',
name: 'stood',
time: '90.180000'
},
{
duration: '0.090000',
name: 'and',
time: '90.570000'
}
],
paragraph: `Arthur stood and.`
}
]
基本上我想知道是否在rambda 6中创建了每个words
数组对象列表?