Extract named entities using Azure Cognitive Services

This year I helped to build drugplug as part of Hack Zurich. One key feature of the app is the extraction of relevant information or warnings out of a drug leaflet. We used Azure Cognitive Services in combination with fuse.js (for fuzzy search) for this purpose.

Integrating Text Analytics into our “data pipeline” was super easy. The following code will extract the named entities and store them as an array.

const entityResults = await client.recognizeEntities( [text] );
for (let document of entityResults) {
    if (document.entities) {
        processedEntities = {}
        for (let entity of document.entities) {
            if (!drug[element.key]) {
                drug[element.key] = [];
            }
            
            var tag = {};
            tag.name = entity.text;
            tag.category = entity.category;
            drug[element.key].push(tag);
        }
    }
};

We then displayed those entities within our Single Page Application:

Cognitive Services entities response interface

The complete code is available on github.

← Back to Articles