Quickstart Code Example

Annotate a document and read the entities back — in Python

This page submits one document with the Python SDK and reads the coded entities out of the result. It is the shortest path from an API key to structured output; the Quickstart covers the same ground from the command line, and Building your own client goes deeper.

Install the SDK and set your key in the environment:

pip install emtellipro
export EMTELLIPRO_API_KEY='...'

Create a client

The SDK takes the server URL and your credentials. A single string is an API key; a (access key, shared secret) tuple selects HMAC authentication instead.

Pass the server URL explicitly, as below. Emtellipro.DEFAULT_SERVER names https://nlp.emtelligent.com in the SDK source, but 7.2.0 — the current release — still compiles in https://api.us.emtelligent.com. That host answers, so the default works either way; passing the URL is how you know which one you got.

import os
from emtellipro import Emtellipro
client = Emtellipro(
"https://nlp.emtelligent.com",
os.environ["EMTELLIPRO_API_KEY"],
)

Submit a document

Every document needs an id unique within the submission, plus a category and subcategory — these are validated against the sets the engine accepts, so they are not free text.

from emtellipro.data import InputDocument
doc = InputDocument(
"doc-1",
"Clinical",
"generic",
"The 2.4 cm melanoma on his left shin has become larger since 2 months ago.",
)
future = client.submit([doc])

submit returns immediately with a ResultFuture. Passing features= narrows what the engine computes; the default is every feature.

Wait for the result

future.done(timeout=300)
result = future.result()

Read the entities

A Result holds annotated_docs, one per document you submitted. Each found entity carries the text it matched, its assertion attributes, and the concepts it resolved to — which is how one mention maps into several ontologies at once.

for annotated_doc in result.annotated_docs:
for entity in annotated_doc.found_entities:
print(entity.text, entity.polarity, entity.section_name)

The shape of what comes back — how concept_links and locations resolve — is laid out with a real payload on the JSON Result Format page.

The whole thing

nlp_quickstart.py
import os
from emtellipro import Emtellipro
from emtellipro.data import InputDocument
client = Emtellipro(
"https://nlp.emtelligent.com",
os.environ["EMTELLIPRO_API_KEY"],
)
doc = InputDocument(
"doc-1",
"Clinical",
"generic",
"The 2.4 cm melanoma on his left shin has become larger since 2 months ago.",
)
future = client.submit([doc])
future.done(timeout=300)
result = future.result()
for annotated_doc in result.annotated_docs:
for entity in annotated_doc.found_entities:
print(entity.text, entity.polarity, entity.section_name)

Next