@@ -193,25 +193,98 @@ void retainsAdjacentNonOverlappingNearbyUnitFragmentAsReviewEvidence() throws Ex
193193 }
194194
195195 @ Test
196- void retainsAdjacentNonOverlappingNearbyUnitFragmentBeforeAddressAsReviewEvidence () throws Exception {
196+ void excludesAdjacentNonOverlappingHeaderFragmentsFromAddressEvidence () throws Exception {
197197 String tsv = TSV_HEADER + "\n " + String .join ("\n " ,
198- "5\t 1\t 1\t 1\t 1\t 1\t 410\t 70\t 20\t 10\t 90\t 3B" ,
199- "5\t 1\t 1\t 1\t 2\t 1\t 100\t 100\t 300\t 20\t 90\t 123 MAIN ST" ,
200- "5\t 1\t 1\t 1\t 3\t 1\t 100\t 140\t 120\t 20\t 90\t DETROIT" );
198+ "5\t 1\t 1\t 1\t 1\t 1\t 100\t 70\t 40\t 10\t 90\t eG»" ,
199+ "5\t 1\t 1\t 1\t 2\t 1\t 100\t 82\t 30\t 10\t 90\t 929" ,
200+ "5\t 1\t 1\t 1\t 3\t 1\t 100\t 100\t 300\t 20\t 90\t 123 MAIN ST" ,
201+ "5\t 1\t 1\t 1\t 4\t 1\t 100\t 140\t 120\t 20\t 90\t DETROIT" );
201202 Map <String , Object > lineEvidence = Map .of (
202- "1" , evidence (1 , true , List .of (reading ("easyocr" , "3B" ))),
203- "2" , consensusEvidence ("123 MAIN ST" ),
204- "3" , consensusEvidence ("DETROIT" ));
203+ "1" , evidence (1 , true , List .of (reading ("tesseract" , "eG»" ))),
204+ "2" , evidence (1 , true , List .of (reading ("tesseract" , "929" ))),
205+ "3" , consensusEvidence ("123 MAIN ST" ),
206+ "4" , consensusEvidence ("DETROIT" ));
205207 String output = consensusOutput (tsv , lineEvidence );
206208 AddressOcrService service = new AddressOcrService ("ocr-binary" , "eng" ,
207209 ignored -> new AddressOcrService .ProcessResult (0 , output , "" ), false );
208210
209211 PlaceCandidate candidate = service .extractAddressCandidates (png (), "route.png" , "" ).get (0 );
210212
211213 assertEquals ("123 MAIN ST, DETROIT" , candidate .text ());
214+ assertEquals (3 , candidate .ocrAgreement ());
215+ assertFalse (candidate .ocrReviewRequired ());
216+ assertTrue (candidate .ocrAlternatives ().stream ().noneMatch (value -> value .startsWith ("line 1 " )
217+ || value .startsWith ("line 2 " )));
218+ }
219+
220+ @ Test
221+ void retainsAdjacentNonOverlappingNearbyUnitFragmentBeforeAddressAsReviewEvidence () throws Exception {
222+ for (String unit : List .of ("3B" , "A208" )) {
223+ String tsv = TSV_HEADER + "\n " + String .join ("\n " ,
224+ "5\t 1\t 1\t 1\t 1\t 1\t 410\t 70\t 20\t 10\t 90\t " + unit ,
225+ "5\t 1\t 1\t 1\t 2\t 1\t 100\t 100\t 300\t 20\t 90\t 123 MAIN ST" ,
226+ "5\t 1\t 1\t 1\t 3\t 1\t 100\t 140\t 120\t 20\t 90\t DETROIT" );
227+ Map <String , Object > lineEvidence = Map .of (
228+ "1" , evidence (1 , true , List .of (reading ("easyocr" , unit ))),
229+ "2" , consensusEvidence ("123 MAIN ST" ),
230+ "3" , consensusEvidence ("DETROIT" ));
231+ String output = consensusOutput (tsv , lineEvidence );
232+ AddressOcrService service = new AddressOcrService ("ocr-binary" , "eng" ,
233+ ignored -> new AddressOcrService .ProcessResult (0 , output , "" ), false );
234+
235+ PlaceCandidate candidate = service .extractAddressCandidates (png (), "route.png" , "" ).get (0 );
236+
237+ assertEquals ("123 MAIN ST, DETROIT" , candidate .text ());
238+ assertEquals (1 , candidate .ocrAgreement ());
239+ assertTrue (candidate .ocrReviewRequired ());
240+ assertTrue (candidate .ocrAlternatives ().contains ("line 1 easyocr: " + unit ));
241+ }
242+ }
243+
244+ @ Test
245+ void keepsAdjacentPlainNumericFragmentOnlyWhenAddressHasUnitMarker () throws Exception {
246+ for (String unit : List .of ("929" , "2018" )) {
247+ String tsv = TSV_HEADER + "\n " + String .join ("\n " ,
248+ "5\t 1\t 1\t 1\t 1\t 1\t 100\t 82\t 30\t 10\t 90\t " + unit ,
249+ "5\t 1\t 1\t 1\t 2\t 1\t 100\t 100\t 300\t 20\t 90\t 123 MAIN ST APT" ,
250+ "5\t 1\t 1\t 1\t 3\t 1\t 100\t 140\t 120\t 20\t 90\t DETROIT, MI" );
251+ Map <String , Object > lineEvidence = Map .of (
252+ "1" , evidence (1 , true , List .of (reading ("tesseract" , unit ))),
253+ "2" , consensusEvidence ("123 MAIN ST APT" ),
254+ "3" , consensusEvidence ("DETROIT, MI" ));
255+ String output = consensusOutput (tsv , lineEvidence );
256+ AddressOcrService service = new AddressOcrService ("ocr-binary" , "eng" ,
257+ ignored -> new AddressOcrService .ProcessResult (0 , output , "" ), false );
258+
259+ PlaceCandidate candidate = service .extractAddressCandidates (png (), "route.png" , "" ).get (0 );
260+
261+ assertEquals ("123 MAIN ST APT, DETROIT, MI" , candidate .text ());
262+ assertEquals (1 , candidate .ocrAgreement ());
263+ assertTrue (candidate .ocrReviewRequired ());
264+ assertTrue (candidate .ocrAlternatives ().contains ("line 1 tesseract: " + unit ));
265+ }
266+ }
267+
268+ @ Test
269+ void retainsUnknownAdjacentTwoLetterFragmentSoFollowingLocalityStillJoins () throws Exception {
270+ String tsv = TSV_HEADER + "\n " + String .join ("\n " ,
271+ "5\t 1\t 1\t 1\t 1\t 1\t 100\t 100\t 300\t 20\t 90\t 22 1/2 EASTRIDGE CT" ,
272+ "5\t 1\t 1\t 1\t 2\t 1\t 100\t 124\t 30\t 10\t 90\t NN" ,
273+ "5\t 1\t 1\t 1\t 3\t 1\t 100\t 140\t 120\t 20\t 90\t ALBANY NY" );
274+ Map <String , Object > lineEvidence = Map .of (
275+ "1" , consensusEvidence ("22 1/2 EASTRIDGE CT" ),
276+ "2" , evidence (1 , true , List .of (reading ("tesseract" , "NN" ))),
277+ "3" , consensusEvidence ("ALBANY NY" ));
278+ String output = consensusOutput (tsv , lineEvidence );
279+ AddressOcrService service = new AddressOcrService ("ocr-binary" , "eng" ,
280+ ignored -> new AddressOcrService .ProcessResult (0 , output , "" ), false );
281+
282+ PlaceCandidate candidate = service .extractAddressCandidates (png (), "route.png" , "" ).get (0 );
283+
284+ assertEquals ("22 1/2 EASTRIDGE CT, ALBANY NY" , candidate .text ());
212285 assertEquals (1 , candidate .ocrAgreement ());
213286 assertTrue (candidate .ocrReviewRequired ());
214- assertTrue (candidate .ocrAlternatives ().contains ("line 1 easyocr: 3B " ));
287+ assertTrue (candidate .ocrAlternatives ().contains ("line 2 tesseract: NN " ));
215288 }
216289
217290 @ Test
0 commit comments