Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSC 470/570: Artificial Intelligence Program 1: Search to Find Path of Links Bet

ID: 3862174 • Letter: C

Question

CSC 470/570: Artificial Intelligence Program 1: Search to Find Path of Links Between Two Input Files or URLs Write a program that finds a path of links between two input files or URLs using one of the search algorithms discussed in class thus far. You are expected to write the program in Java, Python, or C++ with good programming style and documentation. In addition to the program specifications, you will need to write a paper (no more than 1 page in length) that describes the algorithms we have discussed in class (including advantages and disadvantages) and then reveal the algorithm you chose to implement, and state why you made that choice. You may use the following information to aid you in the answering of the question, writing of your paper, and the coding of your program. You should construct a tree showing the URL connections and include it in vour documentation. Help for Assignment: Sample Expected Content of the Writing Part As an ordinary person (or agent) browsing the web, we can only generate the successors of a page by visiting it. We where the heuristic is some function of the number of can then do search, or perhaps words in common between the start and goal pages: this may help keep the links on target. Search engines keep the complete graph of the web, and may provide the user access to all (or at least some of the pages that link to a page this would allow us to do bi-directional search This program finds a path of links between two input URL using earch. The program is written in and runs on Of the 5 algorithms discussed in class, I chose to implement the because discuss the advantages and disadvantages of each algorithm) The file LinkSearchjava (if you are using JAVA), LinkSearc.py (if you are using Python or LinkSearch.cpp (ifyou are using C++) implements the algorithm. There are five test files each file has a list of other files (URLs) as given in the following tables Yahoo txt Msn.txt Basketball Sports, Mavericks txt Computer txt Sports txt Soccer txt Pistons txt Football tykt Home tykt News. Mail txt

Explanation / Answer

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class LinkSearch {

   public static void main(String[] args) throws IOException {

       File fileBasket = new File("D:/docs/Chegg/LinkSearch/src/Basktball.txt");
       BufferedReader brBasket = new BufferedReader(new InputStreamReader(new FileInputStream(fileBasket)));

       File fileMsn = new File("D:/docs/Chegg/LinkSearch/src/Msn.txt");
       BufferedReader brMsn = new BufferedReader(new InputStreamReader(new FileInputStream(fileMsn)));

       File fileSports = new File("D:/docs/Chegg/LinkSearch/src/Sports.txt");
       BufferedReader brSports = new BufferedReader(new InputStreamReader(new FileInputStream(fileSports)));

       File fileYahoo = new File("D:/docs/Chegg/LinkSearch/src/Yahoo.txt");
       BufferedReader brYahoo = new BufferedReader(new InputStreamReader(new FileInputStream(fileYahoo)));

       Scanner sc = new Scanner(System.in);
       System.out.println("Enter two links to search: ");
       String stringOne = sc.nextLine();
       String stringTwo = sc.nextLine();
       List linkReverse = new ArrayList<>();
       linkReverse.add(stringTwo);
       Boolean notFound = true;
       for (int i = 0; i < 4; i++) {
           while (notFound) {
               String line = null;
               while ((line = brBasket.readLine()) != null) {
                   // System.out.println(line);
                   if (line.equalsIgnoreCase((String) linkReverse.get(linkReverse.size() - 1))) {
                       linkReverse.add("Basketball.txt");
                       notFound = false;
                   }
               }
               while ((line = brMsn.readLine()) != null) {
                   // System.out.println(line);
                   if (line.equalsIgnoreCase((String) linkReverse.get(linkReverse.size() - 1))) {
                       linkReverse.add("Msn.txt");
                       notFound = false;
                   }
               }
               while ((line = brSports.readLine()) != null) {
                   // System.out.println(line);
                   if (line.equalsIgnoreCase((String) linkReverse.get(linkReverse.size() - 1))) {
                       linkReverse.add("Sports.txt");
                       notFound = false;
                   }
               }
               while ((line = brYahoo.readLine()) != null) {
                   // System.out.println(line);
                   if (line.equalsIgnoreCase((String) linkReverse.get(linkReverse.size() - 1))) {
                       linkReverse.add("Yahoo.txt");
                       notFound = false;
                   }
               }
               notFound = false;
           }
       }

       if (linkReverse.size() < 2) {
           System.out.println("Trying to find path from " + stringOne + " to " + stringTwo);
           System.out.println("Sorry, A path was not found. Check the filenames or increase the count limit.");
       } else {

           System.out.println("Trying to find path from " + stringOne + " to " + stringTwo);
           System.out.println("**********************GOAL FOUND**********************");
           System.out.print("Path is : ");
           for (int i = linkReverse.size() - 1; i >= 0; i--) {
               System.out.print(" -> " + linkReverse.get(i));

           }
       }

   }

}