textRuleScore applyConcept

Standard Case: Customer Feedback Analysis for Product and Sentiment Extraction

Scénario de test & Cas d'usage

Business Context

A marketing department wants to analyze customer support emails to automatically identify which products are mentioned and the associated sentiment (positive or negative). This allows them to quickly route feedback and gauge customer satisfaction.
About the Set : textRuleScore

Rule-based scoring of text documents.

Discover all actions of textRuleScore
Data Preparation

Create two tables: one for the customer emails ('customer_feedback') and one for the custom LITI model ('product_sentiment_liti') that defines rules for extracting products and sentiment.

Copied!
1DATA mycas.customer_feedback;
2 LENGTH feedback_id $ 10 email_body $ 500;
3 INFILE DATALINES delimiter='|';
4 INPUT feedback_id $ email_body $;
5 DATALINES;
6email001|I am very happy with the new FusionX Pro, it's incredibly fast!
7email002|The DataStreamer tool is a bit complicated, and the performance is disappointing.
8email003|My FusionX Pro arrived broken. This is an awful experience.
9email004|Just a quick note to say the DataStreamer is a fantastic product. Great job!
10;
11run;
12 
13data mycas.product_sentiment_liti;
14 length model_id $ 20 model_txt $ 500;
15 infile datalines delimiter='|';
16 INPUT model_id $ model_txt $;
17 DATALINES;
18model1|CONCEPT:PRODUCT@FusionX Pro, DataStreamer
19model1|CONCEPT:SENTIMENT_POS@happy, fantastic, great job
20model1|CONCEPT:SENTIMENT_NEG@disappointing, broken, awful
21model1|SEQUENCE:PRODUCT_SENTIMENT:(SENTIMENT_POS, SENTIMENT_NEG) (PRODUCT):_c
22;
23RUN;

Étapes de réalisation

1
Load the text data and the LITI model into the CAS server. This step is covered by the data_prep section.
Copied!
1/*
2Data is prepared and loaded in the data_prep step */
2
Execute the applyConcept action using the custom LITI model. Generate both a concept output table and a fact output table to link products with sentiment.
Copied!
1PROC CAS;
2 textRuleScore.applyConcept /
3 TABLE={name='customer_feedback'},
4 docId='feedback_id',
5 text='email_body',
6 model={name='product_sentiment_liti'},
7 casOut={name='feedback_concepts', replace=true},
8 factOut={name='feedback_facts', replace=true};
9RUN;
10QUIT;

Expected Result


Two output tables are created. The 'feedback_concepts' table contains all individual matches for PRODUCT, SENTIMENT_POS, and SENTIMENT_NEG concepts. The 'feedback_facts' table contains extracted facts, linking specific products to the sentiment expressed in the same email (e.g., linking 'FusionX Pro' to 'happy' for email001).