Repository navigation
Expand file tree
/
Copy pathsentiment_classification.sql
More file actions
71 lines (61 loc) · 2.74 KB
/
Copy pathsentiment_classification.sql
File metadata and controls
71 lines (61 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* AI Text Analysis Demo
*
* Scenario:
* Analyzing customer product reviews to extract sentiment and classify feedback.
*
* Requirements:
* - Dremio environment with Generative AI features enabled.
* - Connected AI provider (e.g., OpenAI, Azure OpenAI).
*/
-------------------------------------------------------------------------------
-- 0. SETUP: Create Dummy Data
-------------------------------------------------------------------------------
-- PREREQUISITE: Ensure a space named 'RetailDB' exists.
CREATE FOLDER IF NOT EXISTS RetailDB.AI_Lab;
CREATE TABLE IF NOT EXISTS RetailDB.AI_Lab.Customer_Reviews (
ReviewID INT,
Product VARCHAR,
ReviewText VARCHAR
);
INSERT INTO RetailDB.AI_Lab.Customer_Reviews (ReviewID, Product, ReviewText) VALUES
(1, 'Wireless Headphones', 'The battery life is amazing, but the ear cups are a bit uniformtable after an hour.'),
(2, 'Smart Watch', 'Completely stopped working after two days. Terrible support experience.'),
(3, 'Running Shoes', 'Love the cushioning! Best run I have had in years. Highly recommend.'),
(4, 'Coffee Maker', 'It makes okay coffee, but it is way too loud and vibrates the whole counter.'),
(5, 'Laptop Stand', 'Sturdy and adjustable. Exactly what I needed for my home office.');
-------------------------------------------------------------------------------
-- 1. SENTIMENT ANALYSIS
-- Use AI to determine if a review is Positive, Negative, or Neutral.
-------------------------------------------------------------------------------
SELECT
ReviewID,
Product,
ReviewText,
AI_GENERATE(
'Analyze the sentiment of the following customer review. Respond with only one word: "Positive", "Negative", or "Neutral". Review: ' || ReviewText
) AS Sentiment
FROM RetailDB.AI_Lab.Customer_Reviews;
-------------------------------------------------------------------------------
-- 2. CLASSIFICATION & TAGGING
-- Extract specific issues or topics from the text.
-------------------------------------------------------------------------------
SELECT
ReviewID,
Product,
ReviewText,
AI_GENERATE(
'Identify the main topic of this review (e.g., "Quality", "Support", "Performance", "Comfort", "Price"). Return only the topic name. Review: ' || ReviewText
) AS Main_Topic
FROM RetailDB.AI_Lab.Customer_Reviews;
-------------------------------------------------------------------------------
-- 3. CLEANING & SUMMARIZATION
-- Fix typos or summarize long reviews.
-------------------------------------------------------------------------------
SELECT
ReviewID,
ReviewText,
AI_GENERATE(
'Correct any spelling mistakes in the following text and return the cleaned version: ' || ReviewText
) AS Cleaned_Text
FROM RetailDB.AI_Lab.Customer_Reviews;