-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.py
81 lines (58 loc) · 2.13 KB
/
examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from pathlib import Path
from fuzzy_table_extractor.handlers.docx_handler import DocxHandler
from fuzzy_table_extractor.extractor import Extractor, FieldOrientation
def get_basic_table():
path = r"sample_docs\E001 - basic content.docx"
file_path = Path(path)
handler = DocxHandler(file_path)
extractor = Extractor(handler)
df = extractor.extract_closest_table(["id", "name", "age"])
print("This is the result extraction of a very simple document:")
print(df)
print("\n")
def getting_in_inner_tables():
path = r"sample_docs\E002 - inner tables.docx"
file_path = Path(path)
handler = DocxHandler(file_path)
extractor = Extractor(handler)
df = extractor.extract_closest_table(["id", "city", "population"])
print(
"This is the result extraction of a document that has the target table inside other table:"
)
print(df)
print("\n")
def document_with_typos():
path = r"sample_docs\E003 - typos.docx"
file_path = Path(path)
handler = DocxHandler(file_path)
extractor = Extractor(handler)
df = extractor.extract_closest_table(["id", "name", "age"])
print("This is the result extraction of a document that has typos in the table:")
print(df)
print("\n")
def splited_tables():
path = r"sample_docs\E004 - splited tables.docx"
file_path = Path(path)
handler = DocxHandler(file_path)
extractor = Extractor(handler)
df = extractor.extract_closest_table(["id", "name", "age"])
print(
"This is the result extraction of a document that has 2 tables with the same header:"
)
print(df)
print("\n")
def getting_a_field():
path = r"sample_docs\E005 - extract single field.docx"
file_path = Path(path)
handler = DocxHandler(file_path)
extractor = Extractor(handler)
df = extractor.extract_single_field(field="area", orientation=FieldOrientation.ROW)
print("This is the result extraction of a single field oriented in row:")
print(df)
print("\n")
if __name__ == "__main__":
get_basic_table()
getting_in_inner_tables()
document_with_typos()
splited_tables()
getting_a_field()