@@ -2,8 +2,9 @@ import { expect } from "chai";
22import path from "node:path" ;
33import { InferenceResponse } from "../../../src/parsing/v2" ;
44import { LocalResponse } from "../../../src" ;
5- import { ListField , ObjectField , SimpleField } from "../../../src/parsing/v2/field" ;
5+ import { FieldConfidence , ListField , ObjectField , SimpleField } from "../../../src/parsing/v2/field" ;
66import { promises as fs } from "node:fs" ;
7+ import { Polygon } from "../../../src/geometry" ;
78
89const resourcesPath = path . join ( __dirname , ".." , ".." , "data" ) ;
910const v2DataDir = path . join ( resourcesPath , "v2" ) ;
@@ -12,6 +13,7 @@ const inferencePath = path.join(v2DataDir, "inference");
1213const deepNestedFieldPath = path . join ( inferencePath , "deep_nested_fields.json" ) ;
1314const standardFieldPath = path . join ( inferencePath , "standard_field_types.json" ) ;
1415const standardFieldRstPath = path . join ( inferencePath , "standard_field_types.rst" ) ;
16+ const locationFieldPath = path . join ( findocPath , "complete_with_coordinates.json" ) ;
1517const rawTextPath = path . join ( inferencePath , "raw_texts.json" ) ;
1618const blankPath = path . join ( findocPath , "blank.json" ) ;
1719const completePath = path . join ( findocPath , "complete.json" ) ;
@@ -208,4 +210,37 @@ describe("inference", async () => {
208210 expect ( response . inference . toString ( ) ) . to . be . eq ( rstString ) ;
209211 } ) . timeout ( 10000 ) ;
210212 } ) ;
213+
214+ describe ( "field locations and confidence" , async ( ) => {
215+ it ( "to be properly exposed" , async ( ) => {
216+ const response = await loadV2Inference ( locationFieldPath ) ;
217+
218+ expect ( response . inference ) . to . not . be . null ;
219+
220+ const dateField = response . inference . result . fields . get ( "date" ) as SimpleField ;
221+ expect ( dateField . locations ) . to . exist ;
222+ expect ( dateField . locations ! [ 0 ] ) . to . exist ;
223+ expect ( dateField . locations ! [ 0 ] . page ) . to . equal ( 0 ) ;
224+
225+ const polygon : Polygon = dateField . locations ! [ 0 ] . polygon ! ;
226+
227+ expect ( polygon [ 0 ] . length ) . to . equal ( 2 ) ;
228+
229+ expect ( polygon [ 0 ] [ 0 ] ) . to . equal ( 0.948979073166918 ) ;
230+ expect ( polygon [ 0 ] [ 1 ] ) . to . equal ( 0.23097924535067715 ) ;
231+
232+ expect ( polygon [ 1 ] [ 0 ] ) . to . equal ( 0.85422 ) ;
233+ expect ( polygon [ 1 ] [ 1 ] ) . to . equal ( 0.230072 ) ;
234+
235+ expect ( polygon [ 2 ] [ 0 ] ) . to . equal ( 0.8540899268330819 ) ;
236+ expect ( polygon [ 2 ] [ 1 ] ) . to . equal ( 0.24365775464932288 ) ;
237+
238+ expect ( polygon [ 3 ] [ 0 ] ) . to . equal ( 0.948849 ) ;
239+ expect ( polygon [ 3 ] [ 1 ] ) . to . equal ( 0.244565 ) ;
240+
241+ expect ( dateField . confidence ) . to . equal ( FieldConfidence . medium ) ;
242+ expect ( String ( dateField . confidence ) ) . to . equal ( "Medium" ) ;
243+
244+ } ) . timeout ( 10000 ) ;
245+ } ) ;
211246} ) ;
0 commit comments