[Solved]Python 3 Help Provided Google Doc Research Paperstxt File Https Docsgooglecom Document D 1 Q37142231
Python 3 Help: I have provided google doc of theresearch-papers.txt file that I have:
https://docs.google.com/document/d/1UlFUN-lU1EjI01PLTyyVk-kkv225ZWkxEhFiZ8fRhQM/edit?usp=sharing
Please help with question 4AB and 5
Question 1 – Open the file and read itscontents into a list Name the list papers.

Question 2- Make a dictionary that maps paperIDs to paper titles. Go through the list of papers and make adictionary that maps paper IDs (as keys) to paper titles (asvalues). Name your dictionary paper_titles.

Question 3- Index the papers so we can searchthem by keyword (in the title). Make a dictionary that maps eachterm in the paper titles to a list of papers whose titles containthat term (identified by the paper ID). Requirements: Name yourdictionary term_index
![term_index -dict () for each_id in paper titles: title-paper_titles [each_id] for each term in title.split( : if each term in](https://media.cheggcdn.com/media%2F826%2F826401ba-7303-4d90-9786-8e6d61b1b7df%2Fphpf6HZME.png)
Question 4- Everything and anything I search for I amgetting no result

I am getting a Name error 

Once the errors are corrected I need to be ableto:
Index the papers so that we can search for papers byauthor.
You should have a dictionary that has authors as keysand lists of paper IDs as values.
f -open( ‘research-papers.txt’) paperslist() for each line in f: each_lineeach_line.strip() papers.append (each_line) print(papers) paper_titles dict() for each _paper in papers: title, id, other-each _paper.split(‘ title, id-title.strip(), id.strip( paper_titles[id] title print (paper_titles) term_index -dict () for each_id in paper titles: title-paper_titles [each_id] for each term in title.split( : if each term in term index: term index[each terml.append (each id) else: term index[each terml[each idl print(term index) Part A (5 pts): Write a search function Requirements: Name your function search_papers() Your function should take 2 parameters: 1) the query term to search for, and 2) your term_index from Question 3 . Your function should return a list of matching papers . Your function should not fail if the user enters a term that isn’t in the term_index: in that situation, your function should return an empty list (i.e., a list with 0 items in it) : # Define your function here def search_papers (term, term_index): if term in term_index: return term_index[term] else: return[ term_index- s_term- input ( ‘Enter search term: ‘) s_papers- search papers (s_term, term_index) print (‘There are , len(s_papers),’papers that match your search’) for p in s_papers: print(p, s_papers[pl) Enter search term: data There are 0 papers that match your search Part B (4 pts): Write a program that uses the search function Requirements Print a message that tells the user how many results were found (hint: you can compute this by getting the length of the list of results, if your function was defined corectly) . . If there are matching papers, print out each matching paper ID, along with its paper title (retrieved from the paper_titles dictionary from Question 2) Here is an example of an input/output trace from a function and program that meets these requirements What do you want to search for? data There are 9 papers that match your search. 1960191312 empirical analysis of data breach litigation 2364071307 learning individual behavior using sensor data the case of gps traces and taxi drivers 2529452593 modeling user engagement in mobile content consumption with tapstream data and field experiment 2338895451 understanding user economic behavior in the city using large scale geotagged and crowdsourced data 2273081434 gaussian processes for independence tests with non iid data in causal inference 2601121662 graph structure learning from unlabeled data for early outbreak detection 2575532943 graph structure learning from unlabeled data for event detection 1961666882 identifying emerging novel outbreaks in textual emergency department data 2243328796 predicting bundles of spatial locations from learning revealed preference data Here is another example trace for a situation where the user’s term isn’t in the dictionary: What do you want to search for? mouse There are 0 papers that match your search. query input ( “What do you want to search for?” results search _papers (query, term_index) print (“There are”, len (results), papers that match your search.’ for paper_id in result: print(paper_id, paper_titles[paper_id]) What do you want to search for? data There are 0 papers that match your search. Traceback (most recent call last) NameError ipython-input-3-d739c9b35af8> in <module> 2 results – search_papers (query, term index) 3 print (“There are”, len (results), ‘papers that match your search.’ 4 for paper_id in result: 5 print (paper_id, paper titles [paper_id]) NameError: name ‘result’ is not defined Show transcribed image text f -open( ‘research-papers.txt’) paperslist() for each line in f: each_lineeach_line.strip() papers.append (each_line) print(papers)
paper_titles dict() for each _paper in papers: title, id, other-each _paper.split(‘ title, id-title.strip(), id.strip( paper_titles[id] title print (paper_titles)
term_index -dict () for each_id in paper titles: title-paper_titles [each_id] for each term in title.split( : if each term in term index: term index[each terml.append (each id) else: term index[each terml[each idl print(term index)
Part A (5 pts): Write a search function Requirements: Name your function search_papers() Your function should take 2 parameters: 1) the query term to search for, and 2) your term_index from Question 3 . Your function should return a list of matching papers . Your function should not fail if the user enters a term that isn’t in the term_index: in that situation, your function should return an empty list (i.e., a list with 0 items in it) : # Define your function here def search_papers (term, term_index): if term in term_index: return term_index[term] else: return[ term_index- s_term- input ( ‘Enter search term: ‘) s_papers- search papers (s_term, term_index) print (‘There are , len(s_papers),’papers that match your search’) for p in s_papers: print(p, s_papers[pl) Enter search term: data There are 0 papers that match your search
Part B (4 pts): Write a program that uses the search function Requirements Print a message that tells the user how many results were found (hint: you can compute this by getting the length of the list of results, if your function was defined corectly) . . If there are matching papers, print out each matching paper ID, along with its paper title (retrieved from the paper_titles dictionary from Question 2) Here is an example of an input/output trace from a function and program that meets these requirements What do you want to search for? data There are 9 papers that match your search. 1960191312 empirical analysis of data breach litigation 2364071307 learning individual behavior using sensor data the case of gps traces and taxi drivers 2529452593 modeling user engagement in mobile content consumption with tapstream data and field experiment 2338895451 understanding user economic behavior in the city using large scale geotagged and crowdsourced data 2273081434 gaussian processes for independence tests with non iid data in causal inference 2601121662 graph structure learning from unlabeled data for early outbreak detection 2575532943 graph structure learning from unlabeled data for event detection 1961666882 identifying emerging novel outbreaks in textual emergency department data 2243328796 predicting bundles of spatial locations from learning revealed preference data Here is another example trace for a situation where the user’s term isn’t in the dictionary: What do you want to search for? mouse There are 0 papers that match your search.
query input ( “What do you want to search for?” results search _papers (query, term_index) print (“There are”, len (results), papers that match your search.’ for paper_id in result: print(paper_id, paper_titles[paper_id]) What do you want to search for? data There are 0 papers that match your search. Traceback (most recent call last) NameError ipython-input-3-d739c9b35af8> in 2 results – search_papers (query, term index) 3 print (“There are”, len (results), ‘papers that match your search.’ 4 for paper_id in result: 5 print (paper_id, paper titles [paper_id]) NameError: name ‘result’ is not defined
Expert Answer
Answer to Python 3 Help: I have provided google doc of the research-papers.txt file that I have: https://docs.google.com/document/… . . .
OR

