Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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(); } }

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

Answered: 1 week ago

Answered: 1 week ago