Files
ai6-m3/jokes_bot/v4.0/README.md
2026-02-13 10:54:29 +03:00

336 lines
11 KiB
Markdown

# AI-Enhanced Joke Bot v4.0 - Enhanced User Analytics Edition
Welcome to the AI-Enhanced Joke Bot! This application combines humor with artificial intelligence to deliver jokes and analyze user preferences with detailed analytics.
## 📋 Project Structure
```
v4.0/
├── jokes.py # Main application with enhanced user sentiment tracking and analytics
├── jokes.db # SQLite database containing jokes and detailed user sentiments
├── clean_sample_data.sql # Clean sample data with user identifiers
└── README.md # This file
```
## 🚀 Quick Start
### 1. Run the Application
Simply run the main application file:
```bash
python jokes.py
```
The application will:
- Automatically create the database if it doesn't exist
- Add sample data with user identifiers
- Prompt you for a username to track your preferences
## 🔧 Key Features
### Enhanced User Sentiment Tracking
- **User Identification**: Each sentiment rating is linked to a specific user identifier
- **Rating History**: Track all jokes you've rated with timestamps
- **Personal Favorites**: See which jokes you've specifically liked
- **Duplicate Prevention**: Users can update their existing ratings
### Advanced Analytics
- **Community Insights**: See overall sentiment trends and statistics
- **User Preference Analysis**: Identify which users have the most positive/negative ratings
- **Detailed Breakdowns**: View sentiment distribution for individual jokes
- **Popularity Metrics**: Understand which jokes are most liked by the community
## 🎯 Menu Options
1. **Get Random Joke**: Receive a joke with community ratings and detailed sentiment breakdown
2. **Add New Joke**: Submit your own jokes for community rating
3. **View Your Ratings**: See your complete rating history
4. **See Your Favorites**: View jokes you've specifically liked
5. **Community Analytics**: Access detailed community statistics and user rankings
6. **Quit**: Exit the application
## 📊 Database Schema Enhancements
The `user_sentiments` table now includes:
- `user_identifier`: Links each rating to a specific user
- `user_sentiment`: The rating (up/down/neutral)
- `created_at`: Timestamp of when the rating was made
- Support for updating existing ratings
## 💡 Usage Examples
### Getting Started
```
🤖 Welcome to Joke Bot! 🤖
Please enter your username (or press Enter for 'Guest'): JohnDoe
👤 Logged in as: JohnDoe
```
### Viewing Detailed Analytics
When viewing a joke, you'll see:
```
🤣 Why don't scientists trust atoms? Because they make up everything!
👤 Contributor: ScienceFan
👥 Community Rating: 👍 Up (3 votes)
🔍 Detailed Breakdown:
👍 Up: 2 votes
😐 Neutral: 1 votes
```
### Accessing Personal Analytics
Option 3 shows your rating history:
```
📊 Your Joke Ratings History (5 ratings):
--------------------------------------------------
👍 Why did the scarecrow win an award? He was outstanding in his field!
Rated: 2024-01-15 14:30:25
👎 What do you call a fish with no eyes? Fsh!
Rated: 2024-01-15 14:25:10
```
### Community Insights
Option 5 provides comprehensive analytics:
```
📈 COMMUNITY ANALYTICS
==============================
🏆 Most Positive Users:
-------------------------
1. ComedyFan: 85.7% positive (6/7 ratings)
2. JokeLover: 75.0% positive (3/4 ratings)
3. FunnyPerson: 66.7% positive (4/6 ratings)
📊 Overall Statistics:
Total jokes rated: 8
Total ratings: 24
Community positivity: 62.5%
```
## 🛠️ Technical Improvements
- **Enhanced Data Model**: User identifiers enable sophisticated analytics
- **Better UX**: Session-based user identification for consistent tracking
- **Rich Analytics**: Multiple layers of statistical insights
- **Data Integrity**: Prevents duplicate ratings while allowing updates
## 🎉 Benefits of User Identification
1. **Personalized Experience**: Track your own joke preferences over time
2. **Social Insights**: Understand community rating patterns
3. **Quality Control**: Identify consistently popular contributors
4. **Engagement Metrics**: Measure user participation and preferences
5. **Recommendation Potential**: Foundation for future personalized joke recommendations
Enjoy the enhanced AI-powered humor experience with detailed user analytics!
# Joke Bot - Enhanced Setup Instructions
## For Beginners
### Running the Enhanced Version
1. Simply run: `python jokes.py`
2. Enter your username when prompted
3. Enjoy personalized joke ratings and community analytics!
The enhanced version automatically handles all database setup and provides rich analytics features right out of the box.
```
## 代码修改建议
```
# AI-Enhanced Joke Bot v4.0
Welcome to the AI-Enhanced Joke Bot! This application combines humor with artificial intelligence to deliver jokes and analyze their sentiment.
## 📋 Project Structure
```
v4.0/
├── database.py # Creates the SQLite database and jokes table with user sentiment tracking
├── jokes.py # Main application with AI sentiment analysis and user rating
├── jokes.db # SQLite database containing jokes and user sentiments
├── sample_data.sql # Sample jokes to populate the database
├── populate_db.py # Script to populate the database with sample data
├── check_db.py # Utility to check database content
├── upgrade_db.py # Utility to upgrade existing databases with new schema
└── README.md # This file
```
## 🚀 Quick Start
### 1. Install Dependencies
First, make sure you have Python installed and then install the required packages:
```bash
# Create and activate virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install required packages
pip install textblob
# Download required corpora for textblob
python -m textblob.download_corpora
```
### 2. Set Up the Database
Run the database creation script:
```bash
python database.py
```
This creates the `jokes.db` file with the proper table structure, including a table for user sentiments.
### 3. (Optional) Upgrade Existing Database
If you have an existing database from a previous version, run the upgrade script:
```bash
python upgrade_db.py
```
This adds the `user_sentiments` table to your existing database.
### 4. Populate the Database with Sample Jokes
To add sample jokes to your database:
```bash
python populate_db.py
```
Alternatively, you can use the SQL file directly:
```bash
sqlite3 jokes.db < sample_data.sql
```
### 5. Run the Application
Start the Joke Bot:
```bash
python jokes.py
```
## 🔧 Troubleshooting
### No Jokes in Database
If you're getting "No jokes in the database" message:
1. Make sure you've run `python database.py` to create the database
2. Run `python populate_db.py` to add sample jokes to the database
3. Verify the database content with `python check_db.py`
### Missing Dependencies
If you get an ImportError for textblob:
```bash
pip install textblob
python -m textblob.download_corpora
```
## ⚙️ Features
- **Random Joke Generator**: Get a random joke from the database
- **AI Sentiment Analysis**: Analyzes the sentiment of jokes using TextBlob
- **User Sentiment Rating**: After each joke, rate it with thumbs up/down/neutral
- **Community Ratings**: See how other users rated each joke
- **Mood-Based Joke Selection**: Filter jokes by sentiment (positive, negative, neutral)
- **Add New Jokes**: Contribute your own jokes to the database
- **Joke Management**: View all jokes in the database with community ratings
## 💡 Usage Tips
- Choose option 1 to get a random joke, then rate it with U(p)/D(own)/N(eutral)
- Choose option 2 to add a new joke with automatic sentiment analysis and rating
- Choose option 3 to analyze the sentiment of any text
- Choose option 4 to get jokes based on mood
- Choose option 5 to view all jokes in the database with community ratings
- Choose option 6 to exit the application
## 🗂️ Database Schema
The application uses two tables:
- `jokes`: Contains the joke text, contributor, publication date, and AI-analyzed sentiment
- `user_sentiments`: Tracks user ratings for each joke with timestamps
Enjoy the AI-enhanced humor experience with community feedback!
# Joke Bot - Simple Setup Instructions
Welcome to the Joke Bot! This is a fun program that tells jokes and lets you rate them. Follow these simple steps to get it working!
## Simplified Project Structure
The application now has a minimal structure:
```
v4.0/
├── jokes.py # Complete application with database creation and sample data
└── README.md # This file
```
## Step-by-Step Instructions for Beginners
### Step 1: Open Python IDLE
1. Find Python IDLE on your computer (it looks like a blue and white icon)
2. Click on it to open it
3. When it opens, click on "File" then "New File" to create a new file
### Step 2: Save Your New File
1. In the new file window, click "File" then "Save As..."
2. Save the file in your folder and name it `jokes.py`
3. Remember where you saved it!
### Step 3: Get the Code from the Website
1. Go to this website: https://gitea.techshare.cc/technolyceum/ai6-m3/src/branch/main/jokes_bot/v4.0
2. Look for the `jokes.py` file in the list
3. Click on it to see the code
4. Select all the code (Ctrl+A on Windows or Cmd+A on Mac)
5. Copy it (Ctrl+C on Windows or Cmd+C on Mac)
### Step 4: Paste the Code
1. Go back to your Python IDLE window
2. Paste the code you copied (Ctrl+V on Windows or Cmd+V on Mac)
3. Click "File" then "Save" to save the code in your file
### Step 5: Run the Program in PowerShell
1. Open PowerShell (on Windows) or Terminal (on Mac)
2. Navigate to the folder where you saved your jokes.py file
- Type: `cd ` followed by the path to your folder
3. Create a virtual environment (this keeps your programs organized):
- Type: `python -m venv venv`
4. Activate the virtual environment:
- On Windows: `venv\Scripts\Activate.ps1`
- On Mac: `source venv/bin/activate`
5. Run the program:
- Type: `python jokes.py`
### Step 6: Using the Joke Bot
1. When the program runs, you'll see a menu with options
2. Press "1" to get a random joke
3. Press "2" to add your own joke
4. Press "3" to quit the program
## Simple Explanation for New Programmers
Think of programming like cooking:
- The code is like a recipe
- Python is like your kitchen tools
- The computer is like your kitchen where everything happens
When you run the Joke Bot:
- The program automatically creates a database (like a notebook) to store jokes
- If there are no jokes in the notebook, it adds some sample jokes for you
- Then it shows you the menu so you can interact with it
The program is smart enough to handle everything by itself - you don't need to worry about databases or SQL statements. Just run it and enjoy the jokes!
Have fun with your Joke Bot! 😄