Created
March 8, 2018 23:03
-
-
Save jonathanmv/3bf238e2ef62238b6ccfd9ff085c0e16 to your computer and use it in GitHub Desktop.
Create phrases from entities to describe a post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const describePostTexts = texts => { | |
const postTitle = texts[0] | |
const postIntro = texts.slice(1, 4).join('.\n') | |
const intro = `The post is titled "${postTitle}" and it reads as it follows:\n` | |
return intro + postIntro | |
} | |
const describeEntityCounts = counts => { | |
const top = counts[0] | |
const intro = `We find a total of ${counts.length} entities mentioned. ` | |
const topCount = `Mainly "${top.name}" which appears ${top.count} times, followed by ` | |
const topCounts = counts.slice(1, 4).map(({name, count}) => `"${name}" mentioned ${count} times`).join(', ') | |
const rest = counts.slice(4, 7).map(({name}) => name).join(', ') | |
const others = `. Some other mentions include ${rest} plus many others` | |
return intro + topCount + topCounts + others | |
} | |
const describeTypesCounts = counts => { | |
const intro = `Regarding the types of entities, it includes ` | |
const other = counts.find(({name}) => name = 'OTHER') | |
const noOther = counts.filter(({name}) => name != 'OTHER') | |
const body = noOther.map(({name, count}) => `${count} ${plural(cleanName(name), count)}`).join(', ') | |
const closing = `, and also some other ${other.count} things` | |
return intro + body + closing | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment