- Học kỳ
- SP2026
- Thời Gian
- 3/5/26
- Loại tài liệu
- PE
NLP301c SP26 NO2 PE RE
NLP301c PE INSTRUCTIONS
Student preparation:
- Before proceeding, install Python 3.8 or higher.
- Install NLTK (nltk-3.6.2), downloadable from
You do not have permission to view link Đăng nhập hoặc Đăng ký.
- Run cmd with administrator role, change the current path in prompt to the nltk-3.6.2 folder, and type the following command to set up: python setup.py install
- Once installed, start up the Python interpreter and install the data required for the book by typing:
Python
<span>>>> </span><span>import</span> nltk<br><span>>>> </span>nltk.download()<br>- In the NLTK Downloader, select the 'book' collection and ensure it is fully installed.
Instructions for completing PE:
- For submission: Create a folder named in the format: YourName YourRollNumber NLP301c
- Example: Nguyễn Thế Hùng with roll number SE09234 will submit: HungNT SE09234 NLP301c
- Create separate files named Q1.py, Q2.py, Q3.py, Q4.py and place them in the folder.
- Submit the folder to the server. Incorrect submissions will receive a ZERO.
Question 1: (2 marks)
- Task: Write a program to count how many words in a customer feedback contain all lowercase letters only.
- Input: A string containing the feedback text.
- Desired Output: An integer representing the number of words written entirely in lowercase.
- Example:
- Input: "This product is amazing and works Perfectly."
- Output: 5
Question 2: (2 marks)
- Task: Write a program to remove all consecutive duplicate characters from a chatbot message.
- Requirements:
- Case-sensitive.
- Only remove consecutive duplicates (not all duplicates).
- Input: A string containing chatbot text.
- Desired Output: A cleaned string.
- Example:
- Input: "heyyy!!! I loooove NLP"
- Output: "hey! I love NLP"
Question 3: (3 marks)
- Task: Write a program to extract all valid job titles from a recruitment post.
- A valid job title must meet these criteria:
- Starts with an uppercase letter.
- Contains only letters and spaces.
- Must be at least 2 words long.
- Input: A string containing a job posting.
- Desired Output: A list of job titles in order of appearance.
- Example:
- Input: "We are hiring Data Scientist and Software Engineer. Join our team as a Junior Developer!"
- Output: ['Data Scientist', 'Software Engineer', 'Junior Developer']
Question 4: (3 marks)
- Task: Write a program to process social media captions and return the longest word in each sentence.
- Rules:
- Sentences are separated by ., !, ?
- Ignore punctuation.
- If multiple longest words exist, return the first one.
- Input: A paragraph string.
- Desired Output: A list of longest words (one per sentence).
- Example:
- Input: "AI is transforming industries. NLP is very powerful!"
- Output: ['transforming', 'powerful']