Last active
March 8, 2018 23:02
-
-
Save jonathanmv/0d7612ad80130fea5f19adc2f7b64e9d to your computer and use it in GitHub Desktop.
Detect entities with Amazon Comprehend
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
// 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