Skip to content

Instantly share code, notes, and snippets.

@jonathanmv
Last active March 8, 2018 23:02
Show Gist options
  • Save jonathanmv/0d7612ad80130fea5f19adc2f7b64e9d to your computer and use it in GitHub Desktop.
Save jonathanmv/0d7612ad80130fea5f19adc2f7b64e9d to your computer and use it in GitHub Desktop.
Detect entities with Amazon Comprehend
// awsHelper.js
const getEntities = text => {
const Text = cleanText(text)
const LanguageCode = 'en'
return comprehend.detectEntitiesAsync({ Text, LanguageCode })
}
// mediumHelper.js
const getStatsFromComprehendResponse = ({ Entities }) => {
const entityTypeCounts = _.countBy(_.uniqBy(Entities, 'Text'), 'Type')
const sortedTypesCount = toSortedCountDesc(entityTypeCounts)
const nonQuantityEntities = Entities.filter(({ Type }) => Type != 'QUANTITY')
const entityNameCounts = _.countBy(nonQuantityEntities, 'Text')
const sortedEntityNamesCount = toSortedCountDesc(entityNameCounts)
// both are arrays containing objects like { name: 'ORGANIZATION', count: 10 }
return { sortedTypesCount, sortedEntityNamesCount }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment