Question: 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

 Java Coding Language Using the index generated in Assignment #1, write
Java Coding Language
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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!