"### Exercise 1 - Text Retrieval ###\n", "One important task in information retrieval is to find news that are more important for a user. The idea is to give a set of keywords and test each news and find the ones where the keywords appears more frequently.\n", "\n", "Write a program that reads a file and uses three keywords and checks how many times each word appears in the text. Run your code in the three files: nytimes.txt, bostonGlobe.txt. and washington Post.txt and indicate which one has more important news using the keywords: election, inflation and climate.\n", "\n", "Notice that we are not interested in counting all the words in the file, just the keywords, so for each file build a dictionary with the keywords and count how many times each. word shows up in the file. At the end print all three dictionaries to see what newspaper has the best news to read. \n", "Notice that news text is not encoded in regular format, they usually use UTF-8 (to display text in the web browser), so, when opening a file use: \n", "\n", "fhand-open(filename, encoding=\"utf-8\")\n", "HINT: read the whole file at once and split the string to check each word in the file.\n", "\n", "You should get the following count for each file, in order: \n", "[{'inflation': 13), ('election': 8), ('climate': 30, 'inflation': 1)]\n", \n", "\n"
"### Exercise 1 - Text Retrieval ###\n", "One important task in information retrieval is to find news that are more important for a user. The idea is to give a set of keywords and test each news and find the ones where the keywords appears more frequently.\n", "\n", "Write a program that reads a file and uses three keywords and checks how many times each word appears in the text. Run your code in the three files: nytimes.txt, bostonGlobe.txt. and washington Post.txt and indicate which one has more important news using the keywords: election, inflation and climate.\n", "\n", "Notice that we are not interested in counting all the words in the file, just the keywords, so for each file build a dictionary with the keywords and count how many times each. word shows up in the file. At the end print all three dictionaries to see what newspaper has the best news to read. \n", "Notice that news text is not encoded in regular format, they usually use UTF-8 (to display text in the web browser), so, when opening a file use: \n", "\n", "fhand-open(filename, encoding=\"utf-8\")\n", "HINT: read the whole file at once and split the string to check each word in the file.\n", "\n", "You should get the following count for each file, in order: \n", "[{'inflation': 13), ('election': 8), ('climate': 30, 'inflation': 1)]\n", \n", "\n"
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
Related questions
Question
python
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning