Book Image

Hands-On Artificial Intelligence for Search

By : Devangini Patel
Book Image

Hands-On Artificial Intelligence for Search

By: Devangini Patel

Overview of this book

With the emergence of big data and modern technologies, AI has acquired a lot of relevance in many domains. The increase in demand for automation has generated many applications for AI in fields such as robotics, predictive analytics, finance, and more. In this book, you will understand what artificial intelligence is. It explains in detail basic search methods: Depth-First Search (DFS), Breadth-First Search (BFS), and A* Search, which can be used to make intelligent decisions when the initial state, end state, and possible actions are known. Random solutions or greedy solutions can be found for such problems. But these are not optimal in either space or time and efficient approaches in time and space will be explored. We will also understand how to formulate a problem, which involves looking at it and identifying its initial state, goal state, and the actions that are possible in each state. We also need to understand the data structures involved while implementing these search algorithms as they form the basis of search exploration. Finally, we will look into what a heuristic is as this decides the quality of one sub-solution over another and helps you decide which step to take.
Table of Contents (5 chapters)

Do it yourself

In this section, we will look at an application that you can develop by yourself. We will take a look at a new application and discuss the changes that are required. In the Introduction to file search applications section, we discussed two applications of file searching; now, we will develop the second type of example. Our aim is to develop a search application that is able to find program files containing specific program text.

In the code for recursive DFS, we mainly used three classes, as follows:

  • State: This has the three main ingredients of the search process
  • Node: This is used to build search trees
  • Recursive DFS: This has the actual algorithm implementation

Suppose that we want to adapt this code or file search application to new application. We will need to change three methods: getInitialState, successorFunction, and checkGoalState. For the new application of program searching, you will need to change just one method: checkGoalState.

In your new checkGoalState function, you will need to open the file, read the contents of the file line by line, and perform a substring check or regular expression check. Lastly, based on the results of the check, you will return true or false.

So, go ahead and try it out for yourself!