首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SAP CRM呼叫中心基于HANA情感分析引擎的集成

SAP CRM呼叫中心基于HANA情感分析引擎的集成

作者头像
Jerry Wang
发布2019-05-31 09:53:12
4020
发布2019-05-31 09:53:12
举报

版权声明:本文为博主汪子熙原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1439493

Output parameter definition:

Input parameter definition:

Procedure script:

/********* Begin Procedure Script ************/
BEGIN
/*Procedure output is a table with structure of "SocialPostUUID" + "SentimentCode"(e.g. SP, WP...)*/
ET_SENTIMENT =
       SELECT UUID,
       CASE WHEN TA_NUM = 0 THEN 'NE'
       WHEN TA_NUM <= 1 AND TA_NUM > 0 THEN 'WP'
       WHEN TA_NUM <= 2 AND TA_NUM > 1 THEN 'SP'
       WHEN TA_NUM < 0 AND TA_NUM >= -1 THEN 'WN'
       WHEN TA_NUM < -1 AND TA_NUM >= -2 THEN 'SN'
       WHEN TA_NUM = 3 THEN 'NA'
       ELSE 'NA'END AS SENTI_CODE
       FROM (
             /*Secondly assign an integer value (from -2 to 2) to each TA_TYPE.
             For no TA_TYPE entries(NULL), assign 3 as an indicator. Afterward calculate average for each post*/
             SELECT UUID, SUM (CASE WHEN TA_TYPE = 'NeutralSentiment' OR TA_TYPE = 'NeutralEmoticon' THEN 0
             WHEN TA_TYPE = 'StrongNegativeSentiment' OR TA_TYPE = 'MajorProblem' OR TA_TYPE = 'StrongNegativeEmoticon' THEN -2
             WHEN TA_TYPE = 'StrongPositiveSentiment' OR TA_TYPE = 'StrongPositiveEmoticon' THEN 2
             WHEN TA_TYPE = 'WeakNegativeSentiment' OR TA_TYPE = 'MinorProblem' OR TA_TYPE = 'WeakNegativeEmoticon' THEN -1
             WHEN TA_TYPE = 'WeakPositiveSentiment' OR TA_TYPE = 'WeakPositiveEmoticon' THEN 1
             WHEN TA_TYPE IS NULL THEN 3
             ELSE 0 END)/COUNT(2) AS TA_NUM
             FROM (
                    /*firstly join input UUID with $TA table and pick up entries only with specified TA_TYPE*/            
                    SELECT A.UUID, B.TA_TYPE
                    FROM :IT_UUID A LEFT JOIN "$TA_INDEXVOICEOFCUST" B ON A.UUID = B.SOCIALDATAUUID
                    AND B.TA_TYPE in (
                    'NeutralSentiment' ,
                    'StrongNegativeSentiment' ,
                    'StrongPositiveSentiment',
                    'WeakNegativeSentiment' ,
                    'WeakPositiveSentiment',
                    'MinorProblem',
                    'MajorProblem',
                    'StrongPositiveEmoticon',
                    'WeakPositiveEmoticon',
                    'WeakNegativeEmoticon',
                    'NeutralEmoticon', 
                    'StrongNegativeEmoticon')
             )
              GROUP BY UUID
       );
 
END;
 /********* End Procedure Script ************/
method if_soc_senti_badi~calculate_sentiment.
*The prerequisite of this BAdI implementation is a pre-defined HANA database procedure as well as the generated procedure proxy.
*In the following example, the HANA database procedure is ZDP_SENTIMENT_ASSIGNMENT.
*The relevant procedure proxy is ZDPP_SENTIMENT_ASSIGNMENT, and its interface ZIF_ZDPP_SENTIMENT_ASSIGNMENT is defined as:
*interface ZIF_ZDPP_SENTIMENT_ASSIGNMENT public.
*types: begin of it_uuid,
*         uuid                           type c length 32,
*       end of it_uuid.
*types: begin of et_sentiment,
*         uuid                           type c length 32,
*         senti_code                     type c length 2,
*       end of et_sentiment.
*endinterface .

  DATA: lt_uuid      TYPE STANDARD TABLE OF zif_zdpp_sentiment_assignment=>it_uuid,
        ls_sentiment TYPE zif_zdpp_sentiment_assignment=>et_sentiment,
        lt_sentiment TYPE STANDARD TABLE OF zif_zdpp_sentiment_assignment=>et_sentiment.

*prepare uuid list of social posts to be calculated for sentiment.
  LOOP AT ct_social_data ASSIGNING FIELD-SYMBOL(<line>).
    APPEND <line>-uuid TO lt_uuid.
  ENDLOOP.

*Wait 5 seconds for HANA TA processing  
  WAIT UP TO 5 SECONDS. 

*Pass uuid list to database procedure proxy. database procedure/proxy is defined in HDB
  TRY .
      CALL DATABASE PROCEDURE zdpp_sentiment_assignment
        EXPORTING it_uuid = lt_uuid
        IMPORTING et_sentiment = lt_sentiment.
    CATCH cx_sy_db_procedure_sql_error.
*    DB procedure has issue or does not exist at all!
  ENDTRY.

*Fill sentiment into changing table.
*If entry is missing in lt_sentiment(this case rarely happens), fill sentiment 'NA' - Not Applicable.
  LOOP AT ct_social_data ASSIGNING <line>.
    READ TABLE lt_sentiment INTO ls_sentiment WITH KEY uuid = <line>-uuid.
    IF sy-subrc = 0.
      <line>-sentiment = ls_sentiment-senti_code.
    ELSE.
      <line>-sentiment = 'NA'.
    ENDIF.
  ENDLOOP.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年02月10日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档