nlpsdbi 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. nlpsdbi-0.1.0/PKG-INFO +18 -0
  2. nlpsdbi-0.1.0/README.md +11 -0
  3. nlpsdbi-0.1.0/pyproject.toml +19 -0
  4. nlpsdbi-0.1.0/setup.cfg +4 -0
  5. nlpsdbi-0.1.0/src/nlpsdbi/__init__.py +3 -0
  6. nlpsdbi-0.1.0/src/nlpsdbi/cli.py +17 -0
  7. nlpsdbi-0.1.0/src/nlpsdbi/files/api.py +156 -0
  8. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp1.py +30 -0
  9. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp10.py +22 -0
  10. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp11.py +57 -0
  11. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp12.py +24 -0
  12. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp13.py +32 -0
  13. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp14.py +33 -0
  14. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp15.py +9 -0
  15. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp16.py +51 -0
  16. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp17.py +80 -0
  17. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp18.py +28 -0
  18. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp19.py +16 -0
  19. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp2.py +26 -0
  20. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp20.py +0 -0
  21. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp21.py +18 -0
  22. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp3.py +16 -0
  23. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp4.py +30 -0
  24. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp5.py +15 -0
  25. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp6.py +20 -0
  26. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp7.py +101 -0
  27. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp8.py +33 -0
  28. nlpsdbi-0.1.0/src/nlpsdbi/files/nlp9.py +27 -0
  29. nlpsdbi-0.1.0/src/nlpsdbi/files/webscraping.py +18 -0
  30. nlpsdbi-0.1.0/src/nlpsdbi.egg-info/PKG-INFO +18 -0
  31. nlpsdbi-0.1.0/src/nlpsdbi.egg-info/SOURCES.txt +32 -0
  32. nlpsdbi-0.1.0/src/nlpsdbi.egg-info/dependency_links.txt +1 -0
  33. nlpsdbi-0.1.0/src/nlpsdbi.egg-info/entry_points.txt +2 -0
  34. nlpsdbi-0.1.0/src/nlpsdbi.egg-info/top_level.txt +1 -0
nlpsdbi-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: nlpsdbi
3
+ Version: 0.1.0
4
+ Summary: NLP practical programs - run `nlpsdbi` to copy them into the current folder
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+
8
+ # nlpsdbi
9
+
10
+ NLP practical programs.
11
+
12
+ pip install nlpsdbi
13
+ nlpsdbi # copies all the programs into the current folder
14
+
15
+ Or from Python:
16
+
17
+ import nlpsdbi
18
+ nlpsdbi.copy_files()
@@ -0,0 +1,11 @@
1
+ # nlpsdbi
2
+
3
+ NLP practical programs.
4
+
5
+ pip install nlpsdbi
6
+ nlpsdbi # copies all the programs into the current folder
7
+
8
+ Or from Python:
9
+
10
+ import nlpsdbi
11
+ nlpsdbi.copy_files()
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "nlpsdbi"
7
+ version = "0.1.0"
8
+ description = "NLP practical programs - run `nlpsdbi` to copy them into the current folder"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+
12
+ [project.scripts]
13
+ nlpsdbi = "nlpsdbi.cli:main"
14
+
15
+ [tool.setuptools.packages.find]
16
+ where = ["src"]
17
+
18
+ [tool.setuptools.package-data]
19
+ nlpsdbi = ["files/*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .cli import copy_files
2
+
3
+ __all__ = ["copy_files"]
@@ -0,0 +1,17 @@
1
+ import shutil
2
+ from pathlib import Path
3
+
4
+
5
+ def copy_files(dest=None):
6
+ """Copy all bundled programs into dest (default: current folder)."""
7
+ src = Path(__file__).parent / "files"
8
+ dest = Path(dest) if dest else Path.cwd()
9
+ for f in sorted(src.iterdir()):
10
+ if f.is_file():
11
+ shutil.copy(f, dest / f.name)
12
+ print("copied", f.name)
13
+ print(f"Done. Files are in {dest}")
14
+
15
+
16
+ def main():
17
+ copy_files()
@@ -0,0 +1,156 @@
1
+ #1. GET - Get All Products
2
+ import requests
3
+
4
+ # URL of Fake Store API
5
+ url = "https://fakestoreapi.com/products"
6
+
7
+ # Send GET request
8
+ response = requests.get(url)
9
+
10
+ # Check status code
11
+ if response.status_code == 200:
12
+ print("GET Request Successful\n")
13
+
14
+ products = response.json()
15
+
16
+ for product in products:
17
+ print(product['title'],product['price'],product['description'],product['category'])
18
+ else:
19
+ print("Request Failed")
20
+ print("Status Code:", response.status_code)
21
+
22
+ print('/**************************************************************/')
23
+
24
+ #2. POST - Add a New Product
25
+ import requests
26
+
27
+ # API URL
28
+
29
+ url = "https://fakestoreapi.com/products"
30
+
31
+ #ADD NEW DATA
32
+ new_products = {
33
+ "title": "Laptop",
34
+ "price": 30000,
35
+ "description": "It is a HP Laptop for Office work ",
36
+ "category": "Electornics",
37
+ "image": "http://example.com"
38
+ }
39
+
40
+ # Send POST request
41
+
42
+ response = requests.post(url, json=new_products)
43
+
44
+ # Check response
45
+
46
+ if response.status_code == 201:
47
+
48
+ print("POST Request Successful\n")
49
+
50
+ created_product = response.json()
51
+
52
+ print(created_product)
53
+
54
+ else:
55
+
56
+ print("POST Request Failed")
57
+
58
+ print(response.status_code)
59
+
60
+ print('/**************************************************************/')
61
+ #3. GET - Get a Single Product
62
+
63
+ import requests
64
+
65
+ # Product ID
66
+
67
+ product_id = 1
68
+
69
+ url = f"https://fakestoreapi.com/products/{product_id}"
70
+
71
+ # Send GET request
72
+
73
+ response = requests.get(url)
74
+
75
+ if response.status_code == 200:
76
+
77
+ product = response.json()
78
+
79
+ print("Product Details")
80
+
81
+ print("----------------")
82
+
83
+ print("ID:", product["id"])
84
+
85
+ print("Title:", product["title"])
86
+
87
+ print("Price:", product["price"])
88
+
89
+ print("Description:", product["description"])
90
+
91
+ print("Category:", product["category"])
92
+
93
+ else:
94
+
95
+ print("Request Failed")
96
+
97
+ print('/**************************************************************/')
98
+ #4. PUT - Update a Product
99
+ import requests
100
+
101
+ # Product ID to Update
102
+
103
+ product_id = 1
104
+
105
+ url = f"https://fakestoreapi.com/products/{product_id}"
106
+
107
+ updated_product = {
108
+
109
+ "title": "Gaming Laptop",
110
+
111
+ "price": 85000,
112
+
113
+ "description": "Latest Gaming Laptop",
114
+
115
+ "image": "https://i.pravatar.cc",
116
+
117
+ "category": "electronics"
118
+
119
+ }
120
+
121
+ response = requests.put(url, json=updated_product)
122
+
123
+ if response.status_code == 200:
124
+
125
+ print("Product Updated Successfully\n")
126
+
127
+ print(response.json())
128
+
129
+ else:
130
+
131
+ print("Update Failed")
132
+ print('/**************************************************************/')
133
+ #5. DELETE - Delete a Product
134
+ import requests
135
+
136
+ # Product ID
137
+
138
+ product_id = 5
139
+
140
+ url = f"https://fakestoreapi.com/products/{product_id}"
141
+
142
+ # Send DELETE request
143
+
144
+ response = requests.delete(url)
145
+
146
+ if response.status_code == 200:
147
+
148
+ print("Product Deleted Successfully")
149
+
150
+ print(response.json())
151
+
152
+ else:
153
+
154
+ print("Delete Failed")
155
+
156
+ print('/**************************************************************/')
@@ -0,0 +1,30 @@
1
+ #NLTK AND STOP WORDS AND Lemmatizer and Stemmer
2
+ import nltk
3
+ from nltk.corpus import stopwords
4
+ from nltk.stem import WordNetLemmatizer, PorterStemmer
5
+ from nltk.tokenize import word_tokenize
6
+
7
+ nltk.download('punkt')
8
+ nltk.download('stopwords')
9
+ nltk.download('wordnet')
10
+ nltk.download('omw-1.4')
11
+
12
+ paragraph = """Natural Language Processing (NLP) is a field of AI that helps computers understand and process
13
+ human language. It is used in applications like chatbots, translation systems, and voice assistants. """
14
+ print("--------")
15
+
16
+ paragraph = paragraph.lower()
17
+ tokens = word_tokenize(paragraph)
18
+ print ("------------------")
19
+
20
+ lemmatizer = WordNetLemmatizer()
21
+ stemer = PorterStemmer()
22
+
23
+ lemmatized = [lemmatizer.lemmatize(word) for word in tokens]
24
+ print(lemmatized)
25
+ print('---------------------------')
26
+
27
+
28
+ stemed = [stemer.stem(word)for word in lemmatized]
29
+ print(stemed)
30
+ print('----------------------------------------------------')
@@ -0,0 +1,22 @@
1
+ #DTM and TDM (Document Matrix)
2
+
3
+ from sklearn.feature_extraction.text import CountVectorizer
4
+
5
+ docs = [
6
+ "nlp is fun",
7
+ "NLP and PyTHon",
8
+ "Python is EASY"
9
+ ]
10
+ cv = CountVectorizer()
11
+ x = cv.fit_transform(docs)
12
+
13
+ print("Feature Names (Coulmns) : ")
14
+ print(cv.get_feature_names_out())
15
+
16
+ print("\nDTM:")
17
+ print("Rows = Documents , columns = Features")
18
+ print(x.toarray())
19
+
20
+ print("\nTDM")
21
+ print("Rows = features , coloumns = Documents")
22
+ print(x.toarray().T)
@@ -0,0 +1,57 @@
1
+ #WordCloud
2
+ from wordcloud import WordCloud
3
+ import matplotlib.pyplot as plt
4
+
5
+ text = """
6
+ Data Analyst
7
+ Job Description
8
+
9
+ Overview:
10
+ We are seeking a talented and detail-oriented Data Analyst to join our dynamic team. As a Data Analyst,
11
+ you will be responsible for interpreting data, analyzing results, and providing actionable insights to drive
12
+ informed decision-making across the agency. You will work closely with stakeholders to understand their
13
+ data needs, develop analytical solutions, and present findings in a clear and concise manner.
14
+ Responsibilities
15
+ Data Collection and Processing
16
+ • Extract, transform, and load (ETL) data from various sources.
17
+ • Clean and preprocess data to ensure accuracy and consistency.
18
+ • Develop scripts and workflows to automate data collection and processing tasks.
19
+ Data Analysis and Interpretation:
20
+ • Perform exploratory data analysis to uncover trends, patterns, and anomalies.
21
+ • Apply statistical and analytical techniques to derive insights from complex datasets.
22
+ • Conduct hypothesis testing and predictive modeling to support business objectives.
23
+ Data Visualization and Reporting
24
+ • Create visually appealing and interactive dashboards, reports, and presentations.
25
+ • Communicate findings and recommendations to stakeholders using data visualization tools.
26
+ • Collaborate with cross-functional teams to design and deliver actionable insights.
27
+ Data Quality Assurance
28
+ • Validate data accuracy, completeness, and integrity.
29
+ • Identify and address data quality issues and discrepancies.
30
+ • Implement data quality controls and monitoring mechanisms.
31
+ Business Intelligence and Decision Support
32
+ • Partner with business units to define key performance indicators (KPIs) and metrics.
33
+ • Analyze business processes and operations to identify opportunities for improvement.
34
+ • Provide decision support through ad-hoc analysis and scenario modeling.
35
+ Continuous Learning and Development
36
+ • Stay abreast of industry trends, best practices, and emerging technologies in data analytics.
37
+ • Participate in training programs and professional development opportunities.
38
+ • Share knowledge and insights with colleagues to foster a culture of continuous learning.
39
+
40
+ Requirements:
41
+ • Bachelor's degree in Statistics, Mathematics, Computer Science, Economics, or related field.
42
+ Master's degree preferred.
43
+ • Proven experience in data analysis, business intelligence, or related roles.
44
+ • Proficiency in data analysis tools and programming languages (e.g., SQL, Python, R, etc.).
45
+ • Strong analytical and problem-solving skills with attention to detail.
46
+ • Excellent communication and presentation abilities.
47
+ • Ability to work independently and collaboratively in a fast-paced environment.
48
+ • Experience with data visualization tools (e.g., Tableau, Power BI, etc.) is a plus.
49
+ • Knowledge of machine learning and data mining techniques is desirable.
50
+
51
+ """
52
+ wc = WordCloud (width = 800 , height=400 , background_color="white").generate(text)
53
+
54
+ plt.imshow(wc,interpolation="bilinear")
55
+ plt.axis("off")
56
+ plt.title("Word Cloud")
57
+ plt.show ()
@@ -0,0 +1,24 @@
1
+ #pip install thefuzz
2
+
3
+ from thefuzz import fuzz
4
+ from thefuzz import process
5
+
6
+ s1="Data Science"
7
+ s2="Data Science. and AI"
8
+ similarity_score=fuzz.ratio(s1,s2)
9
+
10
+ print(similarity_score)
11
+
12
+
13
+ choices=["Data Science & AI","Machine Learning","Data Sci and AI","AI & Data Science"]
14
+ query="Data Science and AI"
15
+ best_match=process.extractOne(query,choices)
16
+ print(best_match)
17
+
18
+
19
+ # extracting best match based on treshold
20
+ threshold=90
21
+ matches=process.extractBests(query,choices,score_cutoff=threshold)
22
+ #print(matches)
23
+ for match in matches:
24
+ print(match)
@@ -0,0 +1,32 @@
1
+ #TF-IDF (Term frequency - Inverse Document Frequency)
2
+ """
3
+ How it works
4
+ Term Frequency (TF)
5
+ TF(t,d) = Count of term t in document d
6
+ -----------------------------
7
+ Total words in document d
8
+
9
+ Inverse Document Frequency (IDF)
10
+
11
+ IDF = log ( Total Number of documents (N))
12
+ ---------------------------------------
13
+ Number of docuemnts contanting the term
14
+ """
15
+
16
+ from sklearn.feature_extraction.text import TfidfVectorizer
17
+
18
+ #Sample Documnet
19
+
20
+ documents = [
21
+ "The Cat sat on the MaT.",
22
+ "The dog sat on the log.",
23
+ "The cat chased the dog."
24
+ ]
25
+ #TF-IDF
26
+ vectorizer = TfidfVectorizer() #Default simple Tokenization
27
+ X = vectorizer.fit_transform(documents) #Sparse TF-IDF matrix
28
+ terms = vectorizer.get_feature_names_out()
29
+
30
+ #Output : Terms and TF-IDF matrix
31
+ print(list(terms))
32
+ print(X.toarray())
@@ -0,0 +1,33 @@
1
+ #WebScraping
2
+
3
+ import requests
4
+ from bs4 import BeautifulSoup
5
+
6
+ #Start Scraping from the intial Wikipidia Actical
7
+
8
+ url = ("https://en.wikipedia.org/wiki/Mercedes-Benz")
9
+
10
+ h = {
11
+ "User-Agent":"Monzilla/5.0"
12
+ }
13
+
14
+ response = requests.get(url, headers=h)
15
+
16
+ if response.status_code == 200:
17
+ soup = BeautifulSoup(response.text,"html.parser")
18
+
19
+ title = soup.find(id="firstHeading")
20
+ print("Title:",title.text)
21
+
22
+ paragraphs = soup.find_all("p")
23
+
24
+ for p in paragraphs :
25
+ print(p.get_text())
26
+
27
+ else:
28
+ print("page not loaded")
29
+ print("Status Code : ",response.status_code)
30
+
31
+
32
+
33
+
@@ -0,0 +1,9 @@
1
+ #google translator
2
+
3
+ from deep_translator import GoogleTranslator
4
+
5
+ text = "Hello i am Jay Aashar"
6
+
7
+ translated_text = GoogleTranslator('en','hi').translate(text)
8
+ print(translated_text)
9
+
@@ -0,0 +1,51 @@
1
+ #API GET AND POST Method
2
+
3
+
4
+ #GET METHOD
5
+ import requests
6
+ #define the url of the api endpoint
7
+ url = 'https://jsonplaceholder.typicode.com/users' # the url of the users
8
+
9
+ #send a GET request to the server
10
+ respones = requests.get(url)
11
+
12
+ #Check if request was succesfull or not (status code 200)
13
+
14
+ if respones.status_code == 200:
15
+ print("Get request Succesfull ")
16
+ data = respones.json()
17
+
18
+ for x in data:
19
+ print(x['name'],x['email'],x['username'])
20
+
21
+ else :
22
+ print('Get request failed with the status code : ',respones.status_code)
23
+
24
+
25
+
26
+ # POST METHOD
27
+
28
+ import requests
29
+ #define the url of the api endpoint
30
+ url = 'https://jsonplaceholder.typicode.com/posts' #the url of the posts
31
+
32
+ #define data to be sent in the POST request
33
+
34
+ data = {
35
+ 'title' : 'foo',
36
+ 'body' : 'bar',
37
+ 'userId' : 1
38
+ }
39
+
40
+ #Send a POST requesrt to the server
41
+ respones = requests.post(url,json=data)
42
+
43
+ #Check if the request was scussful (status code == 200)
44
+ if respones.status_code == 201:
45
+ #parse the json response
46
+ created_data = respones.json()
47
+ print('POST request Succesfull')
48
+ print('Created Data:',created_data)
49
+
50
+ else:
51
+ print('POST Request faild with status code : ',respones.status_code)
@@ -0,0 +1,80 @@
1
+ # TOPIC MODEL
2
+
3
+ from sklearn.feature_extraction.text import CountVectorizer
4
+ from sklearn.decomposition import LatentDirichletAllocation
5
+
6
+ documents = [
7
+ "The football team practiced every evening before the big match.",
8
+ "The doctor told the patient to drink more water and eat healthy food.",
9
+ "Students used computers to learn how to write simple programs.",
10
+ "The farmer grew rice, wheat, and vegetables on his land.",
11
+ "The bank gave a small loan to a shop owner.",
12
+ "The teacher explained a science lesson about plants and animals.",
13
+ "The cricket team won the game by scoring many runs.",
14
+ "The hospital opened a new room for patients with fever and cough.",
15
+ "People used a mobile app to order food from nearby restaurants.",
16
+ "Heavy rain filled the river and caused flooding in some villages.",
17
+ "The company sold new laptops and smartphones in its store.",
18
+ "The chef cooked rice, curry, and fresh vegetables for dinner.",
19
+ "The government built a new road between two small towns.",
20
+ "The player hurt his leg during the basketball game.",
21
+ "The school started a library with books about history and science.",
22
+ "Doctors gave free health checkups to people in the village.",
23
+ "The train arrived late because of strong rain and wind.",
24
+ "Scientists studied the weather to understand climate change.",
25
+ "The online store delivered clothes, shoes, and bags to customers.",
26
+ "The singer performed songs in front of a large crowd.",
27
+ "Farmers needed more water because the summer was very hot.",
28
+ "The computer program helped workers manage customer information.",
29
+ "The team coach taught players how to pass the ball correctly.",
30
+ "The market sold fruits, vegetables, milk, and bread.",
31
+ "The nurse checked the patient's temperature and blood pressure.",
32
+ "The city added more buses to help people travel to work.",
33
+ "Students watched a video about space, planets, and stars.",
34
+ "The business earned more money after selling products online.",
35
+ "The park had many trees, birds, and small animals.",
36
+ "The museum showed old paintings, coins, and historical objects.",
37
+ ]
38
+
39
+ #Convert text to numbers
40
+ vectorizer = CountVectorizer(stop_words='english')
41
+ X = vectorizer.fit_transform(documents)
42
+
43
+ #Create Topic Model
44
+ lda = LatentDirichletAllocation(n_components=3 , random_state=42)
45
+ lda.fit(X)
46
+
47
+ #GEt all Words
48
+ words = vectorizer.get_feature_names_out()
49
+ print('/**************************************************************/')
50
+ print(words)
51
+ print('/**************************************************************/')
52
+ #Print Top 5 words from each topic
53
+ for i in range(3):
54
+ #i=0 , i=1
55
+ print("\nTopic",i+1)
56
+
57
+ topic_words = lda.components_[i]
58
+
59
+ top_indices = topic_words.argsort()[-5:]
60
+
61
+ for index in reversed(top_indices):
62
+ print(words[index])
63
+
64
+
65
+ print('/**************************************************************/')
66
+ print(topic_words)
67
+
68
+ print('/---------------------------------------------------------------/')
69
+
70
+ print('\n\nDocument Calssification')
71
+ topic_probablites = lda.transform(X)
72
+ for i in range(len(documents)):
73
+ print("\nDocument:",documents[i])
74
+ print("Topic Probabilities:",topic_probablites[i])
75
+
76
+ assigned_topic = topic_probablites[i].argmax()
77
+
78
+ print('Assigned Topic : ',assigned_topic+1)
79
+
80
+
@@ -0,0 +1,28 @@
1
+ import pandas as pd
2
+ import yake
3
+
4
+ reviews = [
5
+ "the laptop has excellent battery life and fast performance",
6
+ "customer service was very helpful and resolved my issue quickly",
7
+ "the mobile app crashes frequently and needs improvement"
8
+ ]
9
+
10
+ extractor = yake.KeywordExtractor(
11
+ lan="en",
12
+ n=3,
13
+ top=3,
14
+ dedupLim=0.9
15
+ )
16
+
17
+ review_no = 1
18
+
19
+ for review in reviews:
20
+ print("\nreview", review_no)
21
+
22
+ keywords = extractor.extract_keywords(review)
23
+
24
+ for keyword, score in keywords:
25
+ print(keyword)
26
+
27
+
28
+ review_no = review_no + 1
@@ -0,0 +1,16 @@
1
+ from groq import Groq
2
+
3
+ client = Groq(api_key="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")
4
+
5
+ question = input("Enter a question: ")
6
+
7
+ completion = client.chat.completions.create(
8
+ model="openai/gpt-oss-120b",
9
+ messages=[
10
+ {"role": "user", "content": question}
11
+ ]
12
+ )
13
+
14
+ print(completion.choices[0].message.content)
15
+
16
+
@@ -0,0 +1,26 @@
1
+ #POS TAG and Lemmatized_words_with_pos
2
+ import nltk
3
+ from nltk.tokenize import word_tokenize
4
+ from nltk.stem import WordNetLemmatizer, PorterStemmer
5
+
6
+ nltk.download('punkt')
7
+ nltk.download('averaged_preceptron_tagger')
8
+
9
+ sentence = """Natural Language Processing (NLP) is a field of AI that helps computers understand and process
10
+ human language. It is used in applications like chatbots, translation systems, and voice assistants."""
11
+
12
+ words = word_tokenize(sentence)
13
+
14
+ pos_tags = nltk.pos_tag(words)
15
+
16
+ print("WORD : POS TAG")
17
+ for word , tag in pos_tags:
18
+ print(f"{word} : {tag}")
19
+
20
+ lemmatizer = WordNetLemmatizer()
21
+ print("\nlemmatization with the POS Tag")
22
+ lemmatized_words_with_pos = [(word , lemmatizer.lemmatize(word , pos='v' if tag.startswith('VB') else 'n'))
23
+ for word,tag in pos_tags]
24
+ print(lemmatized_words_with_pos)
25
+
26
+
File without changes
@@ -0,0 +1,18 @@
1
+ from sumy.parsers.plaintext import PlaintextParser
2
+ from sumy.nlp.tokenizers import Tokenizer
3
+ from sumy.summarizers.text_rank import TextRankSummarizer
4
+
5
+ text="""Video provides a powerful way to help you prove your point. When you click Online Video,
6
+ you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.
7
+ To make your document look professionally produced, Word provides header, footer, cover page, and text box designs
8
+ that complement each other. For example, you can add a matching cover page, header, and sidebar.
9
+ Click Insert and then choose the elements you want from the different galleries."""
10
+
11
+ summarizer=TextRankSummarizer()
12
+
13
+ parser=PlaintextParser.from_string(text,Tokenizer("english"))
14
+
15
+ #summarize into 2 sentences
16
+ summary=summarizer(parser.document,2)
17
+ for sentence in summary:
18
+ print(sentence)
@@ -0,0 +1,16 @@
1
+ # SpaCy Library using and load the library
2
+ import spacy
3
+
4
+ #!python -m spacy downlaod en_core_web_md
5
+
6
+ nlp = spacy.load("en_core_web_md")
7
+
8
+ text ="SpaCy is a popular natural lanuague processing library"
9
+
10
+ doc = nlp(text)
11
+
12
+ print("Original Text : , text")
13
+ print("PoS tagging result :")
14
+
15
+ for token in doc :
16
+ print(f"{token.text}:{token.pos_}")
@@ -0,0 +1,30 @@
1
+ #Using regex and deemjoies the text
2
+ import re
3
+
4
+ def clean_text(text):
5
+ text = re.sub(r"http\S+", "", text) # remove URLs
6
+ text = re.sub(r"@\w+", "", text) # remove mentions
7
+ text = re.sub(r"#\w+", "", text) # remove hashtags
8
+ text = re.sub(r"[^\x00-\x7F]+", "", text) # remove emojis/non-ASCII
9
+ text = re.sub(r"[^a-zA-Z0-9\s]", "", text) # remove special chars
10
+ return text
11
+
12
+ text = "Hello 😊 !!!!!! I am Jay and visit our website https://rawtoready.co.in #AI @JAY $$$ 12342"
13
+
14
+ print(clean_text(text))
15
+
16
+
17
+
18
+ #-------------------
19
+
20
+ #demoemjoies
21
+
22
+ import emoji
23
+
24
+ text1 = "Python is Fun 😊 😃 😎 "
25
+
26
+ #convert in the demoejoies
27
+
28
+ demojized = emoji.demojize(text1)
29
+
30
+ print("Demjoized",demojized)
@@ -0,0 +1,15 @@
1
+ #NER (named Entity Recognition)
2
+ import spacy
3
+
4
+ #nlp = spacy.load ('en _core_web_md')
5
+ #nlp = spacy.load('en _core_web_lg')
6
+
7
+ #!python -m spacy downlaod en_core_web_md
8
+
9
+ nlp = spacy.load('en_core_web_lg')
10
+
11
+ text = "Jay Ashar , The founder of the RawToReady, Will travel to ahmedabad on 7th of next month to sign the contarct for the AI automation worth 1 lakh rs "
12
+
13
+ doc = nlp (text)
14
+ for ent in doc.ents:
15
+ print(ent.text , ent.label_)
@@ -0,0 +1,20 @@
1
+ #Grammer Checker
2
+ #with the downalod version
3
+
4
+ print('---------------Downaload version use---------------------')
5
+ import language_tool_python
6
+
7
+ tool = language_tool_python.LanguageTool('en-US',language_tool_download_version = '6.3')
8
+
9
+ text = "She go to school everydays. He don't likes appoles."
10
+ print(tool.correct(text))
11
+
12
+
13
+ print('-----------------_API use-------------------------')
14
+ import language_tool_python
15
+
16
+ tool = language_tool_python.LanguageToolPublicAPI('en-US',remote_server = 'https://api.languagetool.org')
17
+
18
+ text = "She go to school everydays. He don't likes appoles."
19
+ print(tool.correct(text))
20
+
@@ -0,0 +1,101 @@
1
+ #Sentimate Analyis with the (NLTK (Text Bloob), and NLTK vader_lexicon)
2
+
3
+ #NLTK vader_lexicon method
4
+ from nltk.sentiment.vader import SentimentIntensityAnalyzer
5
+ import nltk
6
+ nltk.download('vader_lexicon')
7
+
8
+ analyzer = SentimentIntensityAnalyzer()
9
+
10
+ text = 'I hated the food'
11
+
12
+ scores = analyzer.polarity_scores(text)
13
+ print(scores)
14
+ compound = scores['compound']
15
+
16
+ if compound >= 0.05:
17
+ sentiment = "Positive"
18
+ elif compound <= -0.05:
19
+ sentiment ='Negative'
20
+ else:
21
+ sentiment = "Neutral"
22
+
23
+ print("Compound score : ",compound)
24
+ print("Sentimate : ",sentiment)
25
+
26
+ #NLTK (Text Bloob)
27
+ from textblob import TextBlob
28
+
29
+ text = "The service was excellent and the staff were friendly"
30
+ blob = TextBlob(text)
31
+
32
+ polarity = blob.sentiment.polarity
33
+ print(polarity)
34
+
35
+ if polarity >= 0.05:
36
+ print("Positive")
37
+ elif polarity <= -0.05:
38
+ print("Negative")
39
+ else:
40
+ print("Neutral")
41
+
42
+
43
+
44
+ # Exaplantion
45
+
46
+
47
+ '''Why We Use 0.05 Instead of 0 for Sentiment Classification
48
+
49
+ In sentiment analysis, the compound score generated by VADER ranges from -1 to +1, where:
50
+
51
+ * -1 indicates extremely negative sentiment.
52
+ * +1 indicates extremely positive sentiment.
53
+ * 0 indicates neutral sentiment.
54
+
55
+ If we use 0 as the threshold, even a very small positive score (e.g., 0.01) would be classified as positive, and a very small negative score (e.g., -0.01) would be classified as negative. These tiny values often occur due to minor variations in text and may not represent a strong sentiment.
56
+
57
+ To avoid misclassifying such weak sentiments, VADER recommends using ±0.05 as the threshold:
58
+
59
+ * Compound score ≥ 0.05 → Positive Sentiment
60
+ * Compound score ≤ -0.05 → Negative Sentiment
61
+ * Compound score between -0.05 and 0.05 → Neutral Sentiment
62
+
63
+ This creates a small neutral zone around zero, ensuring that texts with very weak or ambiguous sentiment are classified as neutral rather than being incorrectly labeled as positive or negative.
64
+
65
+ For example:
66
+
67
+ Compound Score Sentiment
68
+ 0.70 Positive
69
+ 0.12 Positive
70
+ 0.03 Neutral
71
+ -0.02 Neutral
72
+ -0.25 Negative
73
+
74
+ Therefore, using 0.05 instead of 0 improves the accuracy and reliability of sentiment classification by preventing insignificant score fluctuations from affecting the final sentiment label.
75
+
76
+ '''
77
+
78
+
79
+ # thier is one more example with the excel so in the exam thier will be also possible that excel will give and we have to perfome so this same as we do but with the excle file
80
+ # in tis we can use any of the method from the above
81
+
82
+ import pandas as pd
83
+ from textblob import TextBlob
84
+
85
+ df = pd.read_excel("/Users/jayashar/Documents/COLLEGE/NLP/reviews.xlsx")
86
+
87
+ def analyze(text):
88
+ polarity = TextBlob(str(text)).sentiment.polarity
89
+ if polarity >= 0.05:
90
+ sentiment = "Positive"
91
+ elif polarity <= -0.05:
92
+ sentiment = "Negative"
93
+ else:
94
+ sentiment = "Neutral"
95
+ return polarity, sentiment
96
+
97
+ df[["Polarity","Sentiment"]] = df["Review"].apply(
98
+ lambda x : pd.Series(analyze(x))
99
+ )
100
+
101
+ df.to_excel("review_with_sentimate.xlsx",index=False)
@@ -0,0 +1,33 @@
1
+ # Spacy idtenfy the sapce and simlaity between the sentence
2
+ # finding the Simlarity scores
3
+
4
+ import spacy
5
+ nlp = spacy.load("en_core_web_lg")
6
+
7
+ #Define the texts
8
+
9
+
10
+ '''
11
+ text1 = "She enjoys readuing book in the evening"
12
+ text2 = "She likes to read book at night"
13
+ '''
14
+
15
+ '''
16
+ text1 = "The weather is very hot today"
17
+ text2 = "It is sunny day"
18
+ '''
19
+
20
+ text1 = "I love playing football"
21
+
22
+ text2 = "The Stock market crashed yesterday"
23
+
24
+ #process the text
25
+
26
+ doc1 = nlp(text1)
27
+ doc2 = nlp(text2)
28
+
29
+ #calculate similarity
30
+
31
+ similarity = doc1.similarity(doc2)
32
+
33
+ print("Simlarity scores",similarity)
@@ -0,0 +1,27 @@
1
+ #Words Simalrity gensim
2
+
3
+ #With API
4
+ print("\n WITH API")
5
+ import gensim.downloader as api
6
+
7
+ model = api.load("glove-wiki-gigaword-50")
8
+
9
+ print("Simalarity king-queen",model.similarity("king","queen"))
10
+ print("Simalarity cat-dog",model.similarity("cat","dog"))
11
+ print("Simalarity king-banana",model.similarity("king","banana"))
12
+ #Without API
13
+ print("\n WITHOUT API")
14
+ from gensim.models import Word2Vec
15
+ sentences = [
16
+ ["king","queen","men","women","prince","princess"],
17
+ ["dog","cat","animal","pet"],
18
+ ["car","bus","train","vehicle"],
19
+ ["apple","banana","mango","fruit"]
20
+ ]
21
+
22
+ model = Word2Vec(sentences,vector_size=50,window=3,min_count=1,workers=1)
23
+ print("Words similar to 'king' : ")
24
+ print(model.wv.most_similar("king"))
25
+
26
+ print("\nWords simialr to 'cat' : ")
27
+ print(model.wv.most_similar("cat"))
@@ -0,0 +1,18 @@
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+
4
+ url = "https://books.toscrape.com/catalogue/category/books/sequential-art_5/index.html"
5
+
6
+ response = requests.get(url)
7
+ soup = BeautifulSoup(response.text, "html.parser")
8
+
9
+ books = soup.find_all("article", class_="product_pod")
10
+
11
+ for book in books:
12
+ name = book.h3.a["title"]
13
+ price = book.find("p", class_="price_color").text
14
+ stock = book.find("p", class_="instock availability").text.strip()
15
+ print("Book Name :", name)
16
+ print("Price :", price)
17
+ print("Stock :", stock)
18
+ print("-" * 40)
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: nlpsdbi
3
+ Version: 0.1.0
4
+ Summary: NLP practical programs - run `nlpsdbi` to copy them into the current folder
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+
8
+ # nlpsdbi
9
+
10
+ NLP practical programs.
11
+
12
+ pip install nlpsdbi
13
+ nlpsdbi # copies all the programs into the current folder
14
+
15
+ Or from Python:
16
+
17
+ import nlpsdbi
18
+ nlpsdbi.copy_files()
@@ -0,0 +1,32 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/nlpsdbi/__init__.py
4
+ src/nlpsdbi/cli.py
5
+ src/nlpsdbi.egg-info/PKG-INFO
6
+ src/nlpsdbi.egg-info/SOURCES.txt
7
+ src/nlpsdbi.egg-info/dependency_links.txt
8
+ src/nlpsdbi.egg-info/entry_points.txt
9
+ src/nlpsdbi.egg-info/top_level.txt
10
+ src/nlpsdbi/files/api.py
11
+ src/nlpsdbi/files/nlp1.py
12
+ src/nlpsdbi/files/nlp10.py
13
+ src/nlpsdbi/files/nlp11.py
14
+ src/nlpsdbi/files/nlp12.py
15
+ src/nlpsdbi/files/nlp13.py
16
+ src/nlpsdbi/files/nlp14.py
17
+ src/nlpsdbi/files/nlp15.py
18
+ src/nlpsdbi/files/nlp16.py
19
+ src/nlpsdbi/files/nlp17.py
20
+ src/nlpsdbi/files/nlp18.py
21
+ src/nlpsdbi/files/nlp19.py
22
+ src/nlpsdbi/files/nlp2.py
23
+ src/nlpsdbi/files/nlp20.py
24
+ src/nlpsdbi/files/nlp21.py
25
+ src/nlpsdbi/files/nlp3.py
26
+ src/nlpsdbi/files/nlp4.py
27
+ src/nlpsdbi/files/nlp5.py
28
+ src/nlpsdbi/files/nlp6.py
29
+ src/nlpsdbi/files/nlp7.py
30
+ src/nlpsdbi/files/nlp8.py
31
+ src/nlpsdbi/files/nlp9.py
32
+ src/nlpsdbi/files/webscraping.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ nlpsdbi = nlpsdbi.cli:main
@@ -0,0 +1 @@
1
+ nlpsdbi