Question: import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class SearchEngine { private int mode; private Tree nodeTree; // List -> Tree //

import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class SearchEngine { private int mode; private Tree nodeTree; // List -> Tree // build everything bahahah // TODO: mode 3 = BST mode 4 = AVL public SearchEngine(int mode) throws IOException { this.mode = mode; } public Tree getNodeTree(){ return this.nodeTree; } // assumes that the file exists already // TODO: tweak logic so that it builds the proper tree public void buildList() throws IOException { System.out.println("reading"); BufferedReader reader = new BufferedReader(new FileReader("dataset.txt")); String url; while((url = reader.readLine()) != null){ Document doc = Jsoup.connect(url).get(); String text = doc.body().text().toLowerCase(); String[] words = text.split("\\s+"); // splits by whitespace for (String word : words) { // HERE } } reader.close(); System.out.println("Finished reading through all URLs"); } // return a List ew ._. // TODO: Return the reference list of URLs public ArrayList search(String term) { System.out.println("Searching for " + term + " using data structure mode " + mode + "..."); // Search logic goes here return new ArrayList<>(); } public static void main(String[] args) throws IOException{ Scanner input = new Scanner(System.in); System.out.println("Enter mode as in what data structure to use:"); System.out.println(" 1. Array List "); System.out.println(" 2. Sorted Array List"); int mode = input.nextInt(); System.out.println("Building Search Engine..."); SearchEngine engine = new SearchEngine(mode); String answer = "y"; while (answer.equals("y")) { input.nextLine(); // consume the remaining newline character System.out.print("Search (enter a term to query): "); String term = input.nextLine(); engine.search(term); System.out.print("Would you like to search another term (y/n)? "); answer = input.nextLine(); } input.close(); } }

--------------for building search engine-----------------------

import java.util.ArrayList; import java.lang.Comparable; // For building the SearchEngine public class Node implements Comparable { private String keyword; private ArrayList references; public Node(String keyword){ this.keyword = keyword; this.references = new ArrayList(); } public String getKeyword(){ return this.keyword; } public ArrayList getReferences(){ return this.references; } // // public int compareTo(Object o){ // if(o instanceof Node){ // Node other = (Node) o; // return this.keyword.compareTo(other.keyword); // } // return -1; // } public void insertReference(String website){ this.references.add(website); } public boolean equals (Object o) { if (o instanceof Node) { Node other = (Node) o; return this.keyword.equals(other.keyword); } else return false; } public String toString(){ return this.keyword + " " + this.references; } public int compareTo(Node o) { return this.keyword.compareTo(o.keyword); } }

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!