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 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析