"### 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"

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

python

"### Exercise 1 - Text Retrieval ###\n",
"\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",
bostonGlobe.txt
"\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,
and washingtonPost.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",
"\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",
`\n",
"fhand-open(filename, encoding=\"utf-8\")\n",
"```\n",
"\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",
"```\n",
"[{'inflation': 13}, {'election': 8}, {'climate': 30, 'inflation': 1}]\n",
```\n",
"\n"
Transcribed Image Text:"### Exercise 1 - Text Retrieval ###\n", "\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", bostonGlobe.txt "\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, and washingtonPost.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", "\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", `\n", "fhand-open(filename, encoding=\"utf-8\")\n", "```\n", "\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", "```\n", "[{'inflation': 13}, {'election': 8}, {'climate': 30, 'inflation': 1}]\n", ```\n", "\n"
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
File Input and Output Operations
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning