Skip to content

Commit 8494339

Browse files
Merge branch 'master' into datascraping
2 parents 8462dc7 + 7c76ed6 commit 8494339

File tree

215 files changed

+17856
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+17856
-300
lines changed

.github/ChatBot/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Rule Based Chatbot using NLTK
2+
3+
This is a simple rule based chatbot implemented using the Natural Language Toolkit (NLTK) library in Python. The chatbot engages in conversations with users by matching their input with predefined patterns and providing appropriate responses.
4+
5+
## How it Works
6+
7+
The chatbot is built using NLTK's `Chat` class, which allows us to define patterns and corresponding responses. When the user inputs a message, the chatbot searches for a pattern that matches the input and responds with the associated response. If there's no direct match, the chatbot provides a default response to handle any unrecognized inputs.
8+
9+
The predefined patterns cover a range of greetings, questions about the chatbot, jokes, recommendations, and handling user intentions. The chatbot is designed to respond politely and engagingly to various types of user queries.
10+
11+
## Usage
12+
13+
1. Run the `chatbot.py` script, and the chatbot will greet you with a welcome message.
14+
2. Enter your message or query, and the chatbot will respond accordingly.
15+
3. To stop the conversation, simply type `quit` as your input, and the chatbot will bid you goodbye.
16+
17+
## Improving the Chatbot
18+
19+
The predefined patterns can be expanded to make the chatbot more engaging and diverse. In the `chat_patterns.py` file, you can add more patterns and responses to handle a broader range of queries. By doing so, you can reduce the likelihood of default responses and create a more dynamic and interactive chatbot.
20+
21+
## Dependencies
22+
23+
To run the chatbot, ensure you have the following installed:
24+
25+
- Python 3.x
26+
- NLTK library
27+
28+
You can install the required dependencies using pip:
29+
30+
```bash
31+
pip install nltk

.github/ChatBot/chat_patterns.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Predefined patterns and responses for the chatbot
2+
3+
patterns = [
4+
# Greetings
5+
(r'hi|hello|hey', ['Hello!', 'Hi!', 'Hey!', 'Hi there!']),
6+
(r'how are you?', ['I am good, thank you!',
7+
'I am doing well!', 'All good!', 'I\'m fine, thanks!']),
8+
(r'what is your name?', ['You can call me Chatbot.',
9+
'I am Chatbot!', 'My name is Chatbot.']),
10+
(r'bye|goodbye', ['Goodbye!', 'See you later!',
11+
'Bye!', 'Have a great day!']),
12+
13+
# Jokes
14+
(r'tell me a joke', ['Why don’t scientists trust atoms? Because they make up everything!',
15+
'Parallel lines have so much in common. It’s a shame they’ll never meet.',
16+
'Why did the scarecrow win an award? Because he was outstanding in his field!']),
17+
18+
# Age
19+
(r'how old are you?', ['I am a computer program, so I don\'t have an age!',
20+
'Age is just a number, and I don\'t have one!']),
21+
22+
# Creator
23+
(r'who created you?', ['I was created by OpenAI.',
24+
'My creators are from OpenAI.']),
25+
26+
# Compliments
27+
(r'(.*) (like|love) you', ["Aw, that's so sweet!",
28+
"Thank you! I really appreciate it."]),
29+
(r'you are (.*)(good|awesome|amazing)',
30+
["Thank you! I'm here to assist you.", "I'm glad you think so!"]),
31+
32+
# Weather
33+
(r'(.*) (weather|temperature) today', ["I'm sorry, I am just a chatbot and don't have access to real-time data.",
34+
"You can check the weather online or through a weather app."]),
35+
36+
# Recommendations
37+
(r'(.*) (movie|book) (recommendation|recommend)', ["I recommend you watch 'The Shawshank Redemption' or read 'To Kill a Mockingbird'.",
38+
"You might enjoy 'Inception' or 'The Great Gatsby'.",
39+
"If you like action, 'The Dark Knight' is a great choice."]),
40+
41+
# How to create/build something
42+
(r'how (can|do) (I|you) (create|build) (a|an) (.*)', ["To create {4}, you can follow these steps...",
43+
"Building {4} requires some technical knowledge, but here are the basics...",
44+
"Sure! Here's a basic guide on building {4}..."]),
45+
46+
# User intentions
47+
(r'I (want|need) (.*)',
48+
["Why do you need {1}?", "What would you do with {1}?"]),
49+
(r'I am (feeling|looking) (.*)',
50+
["Why are you feeling {1}?", "Tell me more about why you are {1}."]),
51+
52+
# More patterns and responses to handle different queries
53+
# Add more patterns and responses here to make the chatbot more engaging and diverse
54+
55+
# Default response
56+
(r'.*', ["I'm sorry, I don't quite understand. Could you please rephrase that?",
57+
"I'm still learning, and I'm not sure how to respond to that.",
58+
"Let's talk about something else. What else would you like to know?"]),
59+
]

.github/ChatBot/chatbot.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import nltk
2+
from nltk.chat.util import Chat, reflections
3+
# Import patterns from the chat_patterns.py file
4+
from chat_patterns import patterns
5+
6+
chatbot = Chat(patterns, reflections)
7+
8+
9+
def start_chat():
10+
print("Chatbot: Hi! How can I help you today?")
11+
while True:
12+
user_input = input("You: ")
13+
if user_input.lower() == 'quit':
14+
print("Chatbot: Goodbye!")
15+
break
16+
response = chatbot.respond(user_input)
17+
print("Chatbot:", response)
18+
19+
20+
if __name__ == "__main__":
21+
nltk.download('punkt')
22+
start_chat()

2048 GAME/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Project Name
2+
3+
This is a simple implementation of the classic game 2048 in Python. The objective of the game is to slide numbered tiles on a grid to combine them and create a tile with the number 2048. The game ends when the grid is full, and no more moves can be made, or when the player successfully creates the 2048 tile.
4+
5+
## How to Play (For Games/Apps)
6+
7+
Initialization: At the start of the game, an empty 4x4 grid is displayed with two randomly placed tiles, each having a value of 2.
8+
9+
Controls: Use the following keys to control the game:
10+
11+
'W' or 'w': Move Up
12+
'S' or 's': Move Down
13+
'A' or 'a': Move Left
14+
'D' or 'd': Move Right
15+
Gameplay: The game progresses with each move in the direction specified by the player. All tiles slide in the specified direction until they reach the grid's edge or collide with another tile of the same value. If two tiles of the same value collide, they merge into a single tile with double the value. After each move, a new tile with a value of 2 is added to the grid at a random empty cell.
16+
17+
Winning Condition: The game is won when a tile with the value of 2048 is created.
18+
19+
Losing Condition: The game is lost when the grid is full, and no more valid moves can be made.
20+
21+
## Features
22+
23+
Basic 2048 gameplay with grid and tile manipulation.
24+
Random tile generation after each move.
25+
Game over and win conditions detection.
26+
Simple console-based interface.
27+
28+
## Technologies Used
29+
30+
Python programming language.

2048 GAME/game.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# 2048.py
2+
3+
# importing the logic.py file
4+
# where we have written all the
5+
# logic functions used.
6+
import logic
7+
8+
# Driver code
9+
if __name__ == '__main__':
10+
11+
# calling start_game function
12+
# to initialize the matrix
13+
mat = logic.start_game()
14+
15+
while(True):
16+
17+
# taking the user input
18+
# for next step
19+
x = input("Press the command : ")
20+
21+
# we have to move up
22+
if(x == 'W' or x == 'w'):
23+
24+
# call the move_up function
25+
mat, flag = logic.move_up(mat)
26+
27+
# get the current state and print it
28+
status = logic.get_current_state(mat)
29+
print(status)
30+
31+
# if game not over then continue
32+
# and add a new two
33+
if(status == 'GAME NOT OVER'):
34+
logic.add_new_2(mat)
35+
36+
# else break the loop
37+
else:
38+
break
39+
40+
# the above process will be followed
41+
# in case of each type of move
42+
# below
43+
44+
# to move down
45+
elif(x == 'S' or x == 's'):
46+
mat, flag = logic.move_down(mat)
47+
status = logic.get_current_state(mat)
48+
print(status)
49+
if(status == 'GAME NOT OVER'):
50+
logic.add_new_2(mat)
51+
else:
52+
break
53+
54+
# to move left
55+
elif(x == 'A' or x == 'a'):
56+
mat, flag = logic.move_left(mat)
57+
status = logic.get_current_state(mat)
58+
print(status)
59+
if(status == 'GAME NOT OVER'):
60+
logic.add_new_2(mat)
61+
else:
62+
break
63+
64+
# to move right
65+
elif(x == 'D' or x == 'd'):
66+
mat, flag = logic.move_right(mat)
67+
status = logic.get_current_state(mat)
68+
print(status)
69+
if(status == 'GAME NOT OVER'):
70+
logic.add_new_2(mat)
71+
else:
72+
break
73+
else:
74+
print("Invalid Key Pressed")
75+
76+
# print the matrix after each
77+
# move.
78+
print(mat)

0 commit comments

Comments
 (0)