Recover document layout from line breaks using a small set of block types.
Input and workflow
Keep the source strings unchanged while classifying their roles. Join wrapped lines only after resolving the previous block type.
Request
{
"model": "ngila-judge",
"state": {
"previous": "Installation",
"current": "1. Unpack the archive.",
"next": "2. Run the installer."
},
"questions": {
"block": {
"type": "choice",
"instructions": "Classify the current line.",
"criteria": {
"heading": "",
"paragraph": "",
"list item": "",
"code": ""
}
},
"continuation": {
"type": "noul",
"instructions": "Is the current line a wrapped continuation of the previous line?"
}
}
}Run locally
Save ngila.py alongside your script and set NGILA_API_KEY. Save any linked input images in the same directory.
import json
from ngila import NgilaClient
state = {'previous': 'Installation',
'current': '1. Unpack the archive.',
'next': '2. Run the installer.'}
questions = {'block': {'type': 'choice',
'instructions': 'Classify the current line.',
'criteria': {'heading': '',
'paragraph': '',
'list item': '',
'code': ''}},
'continuation': {'type': 'noul',
'instructions': 'Is the current line a wrapped continuation '
'of the previous line?'}}
response = NgilaClient().system_one(state, questions)
a = response["answers"]
print(json.dumps(a, indent=2, ensure_ascii=False))Use the answers
The following application fragment uses a = response["answers"]. Supply any thresholds, lookup tables, or previous results from your workflow before applying it.
block_type = a["block"]["choice"]
join_previous = a["continuation"]["noul"] >= threshold