Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class SearchEngine { private int mode; private Dictionary nodeTable; public
import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class SearchEngine { private int mode; private DictionarynodeTable; public SearchEngine(int mode) throws IOException {
if(mode == 5){ this.mode = 5; this.nodeTable = new HashTableOpenAddressing<>(); buildList(); }else if (mode == 6){ this.mode = 6; this.nodeTable = new HashTableWithChaining<>(); buildList(); }
} public DictionarygetNodeTree(){ return this.nodeTable; } // TODO: assumes that the file exists already 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(); if(url.equals("https://en.wikipedia.org/wiki/Kamala_Harris")) System.out.println(text); // System.out.println(text); String[] words = text.split("\\s+"); // splits by whitespace int count = 0; for (String word : words) { // TODO: } } reader.close(); System.out.println("Finished reading through all URLs"); } // TODO: return the results from one term public ArrayList search(String term) { System.out.println("Searching for " + term + " using data structure mode " + mode + "..."); return new ArrayList<>(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started