aws-samples / aws-samples/amazon-textract-textractor
The key property of the KeyValue class does not return Line instance
- Dominant language
- Jupyter Notebook
- Stars
- 493
- Forks
- 163
- PR merge metrics
- No merged PRs in 30d
Description
KeyValue class [key](https://aws-samples.github.io/amazon-textract-textractor/textractor.entities.html#textractor.entities.key_value.KeyValue.key) property says that it returns ```Line```.
> Return type. [Line](https://aws-samples.github.io/amazon-textract-textractor/textractor.entities.html#textractor.entities.line.Line)
However, it returns Python List\[Word\] and there is no [text](https://aws-samples.github.io/amazon-textract-textractor/textractor.entities.html#textractor.entities.line.Line.text) property available which the Line class to have.
## Environment
```
import textractor
textractor.__version__
-----
'1.7.4'
from platform import python_version
print(python_version())
-----
3..10.10
```
## Reproduction
```
import json
import os
import pathlib
from PIL import Image
from textractor import Textractor
from textractor.data.constants import TextractFeatures
from textractor.entities.line import Line
from textractor.entities.value import Value
from textractor.entities.word import Word
from textractor.entities.key_value import KeyValue
from textractor.visualizers.entitylist import EntityList
import textractor
textractor.__version__
from platform import python_version
print(python_version())
DATA_DIR=pathlib.Path.home().joinpath("home/repository/data/ml/medical_report/pdf")
FILEPATH=DATA_DIR.joinpath("MedicalExaminerReportExample_13.pdf")
extractor = Textractor(profile_name="eml-ap-southeast-2")
document = extractor.analyze_document(
file_source=str(FILEPATH),
features=[
TextractFeatures.LAYOUT,
TextractFeatures.FORMS,
TextractFeatures.TABLES
],
save_image=True, # To use images property and visualize of the document instance.
)
document.key_values
-----
[Number : 24043,
Year: : 2012,
Decedent: : Martin, Trayvon,
ECC contacted FI Malphurs of an apparent death in Sanford in the courtyard behind Retreal View Circle. Person of contact (POC) was SPD Inv. Serino. POC advised of an unknown B/M who had been shot by a resident of the complex POC stated the following: : ,
On : 02/28/2012,
DOB: : 02/05/1995.,
Page : 2 of 2]
```
```
forms: EntityList[KeyValue] = document.key_values
form: KeyValue = None
for form in forms:
key: Line = form.key
value: Value = form.value
print(f"type of value is {type(value)}.")
print(f"type of key is {type(key)}.")
print(f"type of value is {type(value)}.")
key_text: str = key.text
value_text = ' '.join([
word.text for word in value.words
])
print(
f"key:{key_text}, value:{value_text}, page:{kv.page}, page_id:{kv.page_id}"
)
-----
type of value is .
type of key is .
type of value is .
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[120], line 12
9 print(f"type of key is {type(key)}.")
10 print(f"type of value is {type(value)}.")
---> 12 key_text: str = key.text
13 value_text = ' '.join([
14 word.txt for word in value
15 ])
17 print(
18 f"key:{key_text}, value:{value_text}, page:{kv.page}, page_id:{kv.page_id}"
19 )
AttributeError: 'list' object has no attribute 'text'
```
* [MedicalExaminerReportExample_13.pdf](https://github.com/aws-samples/amazon-textract-textractor/files/14457466/MedicalExaminerReportExample_13.pdf)
Contributor guide
Assessment
This issue has not been assessed yet.