提取BIZ(Transaction)的SMS(分析)金额和说明 [英] Extract (parse) amount and description from BIZ (Transaction) sms

查看:557
本文介绍了提取BIZ(Transaction)的SMS(分析)金额和说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做下面的步骤。


  1. 匹配短信与正则表达式


  2. 如果包含然后指定的关键字从短信的身体得到的值例如量,说明(原因交易),账户号码(如果ATM退出),交易类型(借方/贷方)

    这正则表达式不匹配各种银行/交易从而短信给它是没有效率,没有任何其他的方式来识别银行的消息。


例如短信:

1)尊敬的客户,您的帐号的 XXXXXX6377 卢比215.000 是DBT / DBTL资金的转移19/05 / 2015年 - 印度中央银行

2)的A / C NN5715的借记 2000卢比; ATM WDL。的A / C巴尔(子到CHQ realisatn)Rs13286.23上24APR 21:19hr。拨打1800226999阻止你的卡,如果不使用你。

3)尊敬的客户,您的交流 XXXXXXXX5666 INR8,922.00 2月16日的信息。 INF * 000080483346 *薪水。你的净可用巴尔是INR 8,922.00。

 私有静态的ArrayList< SmsDto> parsevalues​​(ArrayList的< SmsDto> body_val){
    ArrayList的< SmsDto> resSms =新的ArrayList<>();
    的for(int i = 0; I< body_val.size();我++){
        SmsDto smsDto = body_val.get(ⅰ);
        正则表达式模式
                = Pattern.compile((?:INR | RS)+ [\\\\ S] * [0-9 + \\\\] * + [0-9] *] + [\\\\] * [0-9 ] +);
        //查找模式的实例相匹配
        匹配器M = regEx.matcher(smsDto.getBody());
        如果(m.find()){
            尝试{
                Log.e(amount_value =,+ m.group(0));
                字符串量=(m.group(0).replaceAll(INR,));
                量= amount.replaceAll(RS,);
                量= amount.replaceAll(INR,);
                量= amount.replaceAll(,);
                量= amount.replaceAll(,,);
                smsDto.setAmount(Double.valueOf(量));
                如果(smsDto.getBody()。包含(扣除)||
                        smsDto.getBody()。包含(收购)|| smsDto.getBody()。包含(购买)|| smsDto.getBody()。包含(博士)){
                    smsDto.setTransactionType(0);
                }否则如果(smsDto.getBody()。包含(记)|| smsDto.getBody()。包含(CR)){
                    smsDto.setTransactionType(1);
                }
                smsDto.setParsed(1);
                Log.e(matchedValue =,量+);
                如果(!Character.isDigit(smsDto.getSenderid()。的charAt(0)))
                    resSms.add(smsDto);
            }赶上(例外五){
                e.printStackTrace();
            }
        }其他{
            Log.e(No_matchedValue,No_matchedValue);
        }
    }
    返回resSms;
}


解决方案

下面的两个常规的前pressions帮助中大部分来自银行交易(HDFC,ICICI,ING,KOTAK,SBI,卡纳拉,PNB的发现量):

  [II] [NN] [RR](\\\\ S * \\\\ S * \\\\ D *)
[RR] [SS](\\\\ S * \\\\ S * \\\\ D *)

请评论,如果你有比上面计算出更好的前pressions。

I am doing below steps.

  1. match sms with regex

  2. if contains specified keyword then get values from sms body like amount,description (reason of transaction), Account number(if ATM withdraw),transaction type(debit/credit)

    this regex not matching all kind of bank/transaction sms thus it is not efficient , is there any other way to identify bank message.

example sms :

1) Dear Customer, your Account Number XXXXXX6377 has been credited by Rs 215.000 being DBT/DBTL funds transfer on 19/05/2015 - CENTRAL BANK OF INDIA

2)A/c NN5715 debited for Rs 2000; ATM WDL. A/c Bal(sub to chq realisatn) Rs13286.23 on 24APR 21:19hr. Call 1800226999 to block your card if not used by you.

3) Dear Customer, Your Ac XXXXXXXX5666 is credited with INR8,922.00 on 16 Feb. Info. INF*000080483346*SALARY. Your Net Available Bal is INR 8,922.00.

private static ArrayList<SmsDto> parsevalues(ArrayList<SmsDto> body_val) {
    ArrayList<SmsDto> resSms = new ArrayList<>();
    for (int i = 0; i < body_val.size(); i++) {
        SmsDto smsDto = body_val.get(i);
        Pattern regEx
                = Pattern.compile("(?:inr|rs)+[\\s]*[0-9+[\\,]*+[0-9]*]+[\\.]*[0-9]+");
        // Find instance of pattern matches
        Matcher m = regEx.matcher(smsDto.getBody());
        if (m.find()) {
            try {
                Log.e("amount_value= ", "" + m.group(0));
                String amount = (m.group(0).replaceAll("inr", ""));
                amount = amount.replaceAll("rs", "");
                amount = amount.replaceAll("inr", "");
                amount = amount.replaceAll(" ", "");
                amount = amount.replaceAll(",", "");
                smsDto.setAmount(Double.valueOf(amount));
                if (smsDto.getBody().contains("debited") ||
                        smsDto.getBody().contains("purchasing") || smsDto.getBody().contains("purchase") || smsDto.getBody().contains("dr")) {
                    smsDto.setTransactionType("0");
                } else if (smsDto.getBody().contains("credited") || smsDto.getBody().contains("cr")) {
                    smsDto.setTransactionType("1");
                }
                smsDto.setParsed("1");
                Log.e("matchedValue= ", "" + amount);
                if (!Character.isDigit(smsDto.getSenderid().charAt(0)))
                    resSms.add(smsDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            Log.e("No_matchedValue ", "No_matchedValue ");
        }
    }
    return resSms;
}

解决方案

The following two regular expressions helped in finding amount from most of the bank transactions(HDFC, ICICI, ING, KOTAK, SBI, CANARA, PNB):

[Ii][Nn][Rr](\\s*.\\s*\\d*)
[rR][sS](\\s*.\\s*\\d*)

Please comment if you have figured out much better expressions than the above.

这篇关于提取BIZ(Transaction)的SMS(分析)金额和说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆