Skip to content

Commit

Permalink
[FormRecognizer] address issues/feedbacks from UX study (#9673)
Browse files Browse the repository at this point in the history
* [FormRecognizer] address issues/feedback from UX study

- Add ref doc to FormField.value and FormField.valueType

* - Filter RecognizedForm.pages to those relevant to the recognized form

* Default confidence to 1 if missing

* - Remove `||` from sample snippets
  • Loading branch information
jeremymeng authored Jun 29, 2020
1 parent ed10a96 commit 06ff96f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sdk/formrecognizer/ai-form-recognizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const fs = require("fs");

async function main() {
const endpoint = "<cognitive services endpoint>";
const apiKey = || "<api key>";
const apiKey = "<api key>";
const path = "<path to your receipt document>"; // pdf/jpeg/png/tiff formats

const readStream = fs.createReadStream(path);
Expand Down
38 changes: 30 additions & 8 deletions sdk/formrecognizer/ai-form-recognizer/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,36 @@ export type FormField = {
*/
valueText?: FieldText;
} & (
| { value?: string, valueType?: "string" }
| { value?: number, valueType?: "number" }
| { value?: Date, valueType?: "date" }
| { value?: string, valueType?: "time" }
| { value?: string, valueType?: "phoneNumber" }
| { value?: number, valueType?: "integer" }
| { value?: FormField[], valueType?: "array" }
| { value?: { [propertyName: string]: FormField }, valueType?: "object" }
| {
/**
* value of the recognized field.
*/
value?: string;
/**
* Type of the 'value' field
*/
valueType?: "string" }
| {
value?: number;
valueType?: "number" }
| {
value?: Date;
valueType?: "date" }
| {
value?: string;
valueType?: "time" }
| {
value?: string;
valueType?: "phoneNumber" }
| {
value?: number;
valueType?: "integer" }
| {
value?: FormField[];
valueType?: "array" }
| {
value?: { [propertyName: string]: FormField };
valueType?: "object" }
)

/**
Expand Down
10 changes: 6 additions & 4 deletions sdk/formrecognizer/ai-form-recognizer/src/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function toFormTable(original: DataTableModel, readResults?: FormPage[]):
boundingBox: toBoundingBox(cell.boundingBox),
columnIndex: cell.columnIndex,
columnSpan: cell.columnSpan || 1,
confidence: cell.confidence,
confidence: cell.confidence || 1,
textContent: cell.elements?.map((element) => toFormContent(element, readResults!)),
isFooter: cell.isFooter || false,
isHeader: cell.isHeader || false,
Expand Down Expand Up @@ -245,7 +245,7 @@ export function toFormFieldFromFieldValueModel(
break;
}
return {
confidence: original.confidence,
confidence: original.confidence || 1,
name: key,
valueText: {
pageNumber: original.pageNumber || 0,
Expand Down Expand Up @@ -299,7 +299,7 @@ export function toFormFromPageResult(original: PageResultModel, pages: FormPage[
return {
formType: `form-${original.clusterId}`,
pageRange: { firstPageNumber: original.pageNumber, lastPageNumber: original.pageNumber },
pages,
pages: pages.filter((p) => p.pageNumber === original.pageNumber),
fields: original.keyValuePairs
? toFieldsFromKeyValuePairs(original.pageNumber, original.keyValuePairs, pages)
: {}
Expand All @@ -311,7 +311,9 @@ export function toRecognizedForm(original: DocumentResultModel, pages: FormPage[
formType: original.docType,
pageRange: { firstPageNumber: original.pageRange[0], lastPageNumber: original.pageRange[1] },
fields: toFieldsFromFieldValue(original.fields, pages),
pages
pages: pages.filter(
(p) => original.pageRange[0] <= p.pageNumber && p.pageNumber <= original.pageRange[1]
)
};
}

Expand Down

0 comments on commit 06ff96f

Please sign in to comment.