Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Coding Language Using the index generated in Assignment #1, write a program that interacts with a user to process information retrieval queries. Your program

image text in transcribed
Java Coding Language
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Using the index generated in Assignment #1, write a program that interacts with a user to process information retrieval queries. Your program should prompt the user for a query, then use it to display the documents that contain the query term. For this assignment, your program only needs to handle single-term queries. However, it must also be able to handle misspelled queries. If a query term is submitted that is not contained in your index, your program must determine a candidate list of (at least 3) possible matches. It must, then, use the edit distance to determine the distance from each candidate to the misspelled query term. Your program should display each candidate and distance in order (decreasing order in terms of distance) and allow the user to select the one he or she wants. The program should then display the documents relevant to that candidate as the query term. Your program should be an extension of the first assignment, so it needs to fulfill all of the requirements of the first assignment (including program header). Your instructor will compile and execute your program. Your main class must be called Assignment2 in a file called Assignment2.java (it is okay if Canvas changes the name of your file). Do not submit any executables or input documents. */ import java.io. BufferedReader; import java.io. Buffered Writer; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util. Map; import java.util.Scanner; public class IRSystem // before witing index, assume and all index data will fit into memory Map> index = new HashMap(); Map documents = new HashMap(); int docid = 0; // read and created index void create(File file) throws IOException { String name = file.getName(); // document ID documents.put(name, ++docid); Buffered Reader reader = null; reader = new BufferedReader(new FileReader(file)); String line; while((line = reader.readLine()) != null) { String words[] = line.split("[^A-Za-z]"); // word tokenize for(String word : words) { List docs = index.get(word); if(docs == null) { docs = new ArrayList(); try { index.put(word, docs); } docs.add(docid); } } } finally { if(reader != null) { reader.close(); } } } // writes index back to file void write(File file) throws IOException { Buffered Writer writer = null; try { writer = new Buffered Writer(new FileWriter(file)); // documents mapping for(String doc : documents.keySet()) { int id = documents.get(doc); writer.write(doc); writer.write(" "); writer.write(String.valueOf(id)); writer.newLine(); } // inverted index for(String word: index.keySet()) { List docs = index.get(word); writer.write(word); writer.write(" "); int s = docs.size(); for(int i = 0; i > index = new HashMap(); Map documents = new HashMap(); int docid = 0; // read and created index void create(File file) throws IOException { String name = file.getName(); // document ID documents.put(name, ++docid); Buffered Reader reader = null; reader = new BufferedReader(new FileReader(file)); String line; while((line = reader.readLine()) != null) { String words[] = line.split("[^A-Za-z]"); // word tokenize for(String word : words) { List docs = index.get(word); if(docs == null) { docs = new ArrayList(); try { index.put(word, docs); } docs.add(docid); } } } finally { if(reader != null) { reader.close(); } } } // writes index back to file void write(File file) throws IOException { Buffered Writer writer = null; try { writer = new Buffered Writer(new FileWriter(file)); // documents mapping for(String doc : documents.keySet()) { int id = documents.get(doc); writer.write(doc); writer.write(" "); writer.write(String.valueOf(id)); writer.newLine(); } // inverted index for(String word: index.keySet()) { List docs = index.get(word); writer.write(word); writer.write(" "); int s = docs.size(); for(int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions