Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
TakaValley committed Mar 21, 2024
1 parent e7ae762 commit e0aef09
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,43 @@

import os
import asyncio
import sys

def print_table(header_names, table_data):
"""Print a two-dimensional array like a table.
Based on provided column header names and two two-dimensional array data, print the strings like table.
Args:
header_names: An array of string, it's the column header names. e.g. ["name", "gender", "age"]
table_data: A two-dimensional array, they're the table data. e.g. [["Mike", "M", 25], ["John", "M", 19], ["Lily", "F", 23]]
Return: None
It's will print the string like table in output window. e.g.
Name Gender Age
Mike M 25
John M 19
Lily F 23
"""
max_len_list = []
for i in range(len(header_names)):
col_values = list(map(lambda row: len(str(row[i])), table_data))
col_values.append(len(str(header_names[i])))
max_len_list.append(max(col_values))

row_format_str = "".join(map(lambda len: f"{{:<{len + 4}}}", max_len_list))

print(row_format_str.format(*header_names))
for row in table_data:
print(row_format_str.format(*row))


async def analyze_custom_documents(custom_model_id):
path_of_parents = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
path_to_sample_documents = os.path.abspath(
os.path.join(path_of_parents, "./sample_forms/forms/Form_1.jpg")
os.path.join(os.path.abspath(__file__), "..", "..", "./sample_forms/forms/Form_1.jpg")
)
sys.path.append(path_of_parents)

# [START analyze_custom_documents]
from azure.core.credentials import AzureKeyCredential
from azure.ai.documentintelligence.aio import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import AnalyzeResult
from helper import utils

endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"]
key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"]
Expand Down Expand Up @@ -101,7 +124,7 @@ async def analyze_custom_documents(custom_model_id):
)
row_data = list(map(extract_value_by_col_name, col_names))
table_rows.append(row_data)
utils.print_table(col_names, table_rows)
print_table(col_names, table_rows)
print("-----------------------------------")
# [END analyze_custom_documents]

Expand Down
Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@

import os

def print_table(header_names, table_data):
"""Print a two-dimensional array like a table.
Based on provided column header names and two two-dimensional array data, print the strings like table.
Args:
header_names: An array of string, it's the column header names. e.g. ["name", "gender", "age"]
table_data: A two-dimensional array, they're the table data. e.g. [["Mike", "M", 25], ["John", "M", 19], ["Lily", "F", 23]]
Return: None
It's will print the string like table in output window. e.g.
Name Gender Age
Mike M 25
John M 19
Lily F 23
"""
max_len_list = []
for i in range(len(header_names)):
col_values = list(map(lambda row: len(str(row[i])), table_data))
col_values.append(len(str(header_names[i])))
max_len_list.append(max(col_values))

row_format_str = "".join(map(lambda len: f"{{:<{len + 4}}}", max_len_list))

print(row_format_str.format(*header_names))
for row in table_data:
print(row_format_str.format(*row))


def analyze_custom_documents(custom_model_id):
path_to_sample_documents = os.path.abspath(
Expand All @@ -38,7 +65,6 @@ def analyze_custom_documents(custom_model_id):
from azure.core.credentials import AzureKeyCredential
from azure.ai.documentintelligence import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import AnalyzeResult
from helper import utils

endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"]
key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"]
Expand Down Expand Up @@ -97,7 +123,7 @@ def analyze_custom_documents(custom_model_id):
)
row_data = list(map(extract_value_by_col_name, col_names))
table_rows.append(row_data)
utils.print_table(col_names, table_rows)
print_table(col_names, table_rows)

print("------------------------------------")
# [END analyze_custom_documents]
Expand Down

0 comments on commit e0aef09

Please sign in to comment.