def batchSendToComprehend()

in code/comprehend_sync/comprehend_processor.py [0:0]


def batchSendToComprehend(comprehend, textList, language):
    keyPhrases = set()
    entitiesDetected = {}
    try:
        keyphrase_response = comprehend.batch_detect_key_phrases(TextList=textList, LanguageCode=language)
        keyphraseResultsList = keyphrase_response.get("ResultList")
        for keyphraseListResp in keyphraseResultsList:
            keyphraseList = keyphraseListResp.get('KeyPhrases')
            for s in keyphraseList:
                s_txt = s.get("Text").strip('\t\n\r')
                print("Detected keyphrase {}".format(s_txt))
                keyPhrases.add(s_txt)
    except Exception as e:
        pipeline_client.stageFailed("Could not batch detect key phrases in Comprehend")
        raise(e)
    try:
        detect_entity_response = comprehend.batch_detect_entities(TextList=textList, LanguageCode=language)
        entityResultsList = detect_entity_response.get("ResultList")
        for entitiesListResp in entityResultsList:
            entityList = entitiesListResp.get("Entities")
            for s in entityList:
                entitiesDetected.update([(s.get("Type").strip('\t\n\r'), s.get("Text").strip('\t\n\r'))])
    except Exception as e:
        pipeline_client.stageFailed("Could not batch detect entities in batch in Comprehend")
        raise(e)
    
    return (list(keyPhrases), entitiesDetected)