Develop an interactive Java-based system that gets queries with k terms, where e
ID: 3860574 • Letter: D
Question
Develop an interactive Java-based system that gets queries with k terms, where each term is marked by either a plus sign or a minus sign. Additionally, the system has access to a .CSV file that contains the results of the last indexing and crawling performed by the search-engine crawler. Ignoring computational complexity, design and implement (in Java, Java Collections, Java GUI, and Javadoc) the above system under the following spec.
1) The user can insert up to three terms via an input widget,
2) Along, with each term the user has to denote whether it is a plus-term or a minus-term (the plus and minus signs are entered via a widget such as a radio button and not as prefixes).
3) The user hits a “Search” button (you do not have to implement this button) and then:
4) The system checks if the terms entered are in the crawler list of inverted indexes.
a. If any of the terms is not in the list, the system responds with “Invalid Terms.”
b. If the terms are in the list, the system responds with the first up-to 5 matching page-ids.
c. If the result of the query has valid terms but does not match any page that complies with the constraints, the system responds with “No Match.”
5) You can, use any collection[s] in your solution. There is no requirement to use a hash table and it is not necessarily the best data structure for storing the list of inverted indexes. 6) Carefully document your system using Javadoc.
Explanation / Answer
SORTEDSTRINGLIST.JAVA : I modified the class a bit by removing the interface class derivation (public class SortedStringList Implements ..) so that I can test it locally. You can add it back.
import java.util.ArrayList;
import java.util.Arrays;
public class SortedStringList {
private static ArrayList<String> data; // a reference to an ArrayList of String objects
public SortedStringList()
// creates an empty list
{
data = new ArrayList();
} // end no-args constructor
public boolean isEmpty()
// Determines whether a list is empty
{
if (data.isEmpty())
return true;
else
return false;
} // end isEmpty
public int size()
// Returns the number of items that are in a list
{
return data.size();
} // end size
public void removeAll()
// Removes all the items in the list
{
data.clear();
} // end removeAll
public void add(String item) throws ListException
// Inserts item into its proper position in a sorted list
// Throws an exception if the item connot be placed on the list
{
try
{
data.add(item) ;
}
catch(Exception e)
{
throw new ListException("Add to List failed: " + e.toString());
}
}
public String get(int index) throws ListIndexOutOfBoundsException
// Retrieves the item at position index of a sorted list, if 1 <= index <= size().
// The list is left unchanged by this operation.
// Throws an exception when index is out of range.
{
if (index > size())
{
throw new ListIndexOutOfBoundsException(index + " is an invalid index");
}
return data.get(index);
}
public void remove(String item) throws ListException
// Removes the item from a sorted list.
// Throws an exception if the item is not found.
{
try
{
data.remove(item) ;
}
catch(Exception e)
{
throw new ListException("Remove " + item.toString() + " from List failed: " + e.toString());
}
}
public int locateIndex(String item)
// Returns the position where the item belongs or exists in a sorted list;
// item and the list are unchanged.
{
return data.indexOf(item);
}
} // end SortedStringList
HELLOWORLD.JAVA : This is the test code to test the above class
public class HelloWorld{
public static void main(String []args){
System.out.println("Hello World");
SortedStringList mylist = new SortedStringList();
if (mylist == null)
System.out.println("List Is not created");
else if (mylist.isEmpty())
{
System.out.println("List Is Empty");
mylist.add("a");
mylist.add("b");
mylist.add("c");
mylist.add("d");
mylist.add("e");
System.out.println("List created with elements :");
System.out.println(mylist.get(0));
System.out.println(mylist.get(1));
System.out.println(mylist.get(2));
System.out.println(mylist.get(3));
System.out.println(mylist.get(4));
int i = mylist.locateIndex("c");
System.out.println("lets remove character c is at index " + i);
mylist.remove("c");
System.out.println("new character at index " + i + " is " + mylist.get(i));
}
}
}
// this project code download is available at: https://drive.google.com/open?id=0B0-Ll2y6vo_sQ2RQUWI1NTY4aGM
// demo at: https://youtu.be/ssFIPSGZSDM
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.