dongmi1221 2018-04-04 02:09
浏览 38
已采纳

从扫描数据中提取数据

I get a text string from a scanned receipt. Here are couple of examples:

George's Restaurant 300 72th Street Miami Beach fl 33141 305-864-5586 Server: Ronald 01/19/2013 Table 20/1 10:53 PM Guests: 1 10062 Reprint #: 1 Ferrari Carano Insalate Cesare Caprese with prosciutto FISH SPEC Spinach Ricotta Ravioli Seafood Pasta Ossobucco 47.00 7.50 9.50 25.95 15.95 19.95 29.95 Sub Total Tax 155.80 14.02 Total 169.82 169.82 Balance Due GRATUITY NOT INCLUDED!!! Thank you for your business

How do I identify what the total amount is in each case (169.82 and 52.88)?

I was thinking I can remove all non-numeric characters, split remaining into array and look for the largest. But it can get confusing with address and phone numbers. I suppose I need to make sure the word TOTAL, SUB-TOTAL, or AMOUNT DUE is close by.

Any suggestions? Thanks.

Another example:

933 ece tur New OrlerS LA 70116 504.:25.1602 wwwfranksresta.ratnewor leans.com 219 KATHY U che 1750 Feb03'1 (7:-2PM Tbl 6/1 Gst 4 1 GARLICBREAD 2 Diet 2 Iced Tea 2 TASTE OF NO 1 Whole Muff 1 Alfredo 3,95 6.00 6.00 33.90 14.95 14.95 Food Tax TOTAL DUE 79.75 7.78 87.53

image here


UPDATE:

It appears I need to look into neural networks to solve this.

  • 写回答

1条回答 默认 最新

  • dreljie602951 2018-04-04 03:15
    关注

    Try this:

    <?php
    
    function checktotal($rcpt) {
        if (preg_match_all('/(\d+\.\d{2})(?:\D|$)/', $rcpt, $match))
            echo 'Total is $' . max($match[1]) . "
    ";
        else echo "No numbers!
    ";
    }
    
    $rcpts = [
        "George's Restaurant 300 72th Street Miami Beach fl 33141 305-864-5586 Server: Ronald 01/19/2013 Table 20/1 10:53 PM Guests: 1 10062 Reprint #: 1 Ferrari Carano Insalate Cesare Caprese with prosciutto FISH SPEC Spinach Ricotta Ravioli Seafood Pasta Ossobucco 47.00 7.50 9.50 25.95 15.95 19.95 29.95 Sub Total Tax 155.80 14.02 Total 169.82 169.82 Balance Due GRATUITY NOT INCLUDED!!! Thank you for your business",
        "SUSHI HARA 8701 W PARMER LANE STE 2128 AUSTIN, TX 78729 123835218 ORDER: A9 Dine-in 25-Jan-2018 6 10 53 1 다tASHU DON SHRIMP TEMPURA (3PCS HARU COMBO SALMON ROLL $11.95 $8.95 $20.00 $7.95 to go Subtotal $48.85 $4.03 S52.88 Tax Total Order 05852ZSBGOW4M Thank you for dining at Sushi Hara",
        "933 ece tur New OrlerS LA 70116 504.:25.1602 wwwfranksresta.ratnewor leans.com 219 KATHY U che 1750 Feb03'1 (7:-2PM Tbl 6/1 Gst 4 1 GARLICBREAD 2 Diet 2 Iced Tea 2 TASTE OF NO 1 Whole Muff 1 Alfredo 3,95 6.00 6.00 33.90 14.95 14.95 Food Tax TOTAL DUE 79.75 7.78 87.53"
        ];
    foreach ($rcpts as $rcpt) checktotal($rcpt);
    

    The output for your test group is:

    Total is $169.82
    Total is $52.88
    Total is $87.53
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程