Book Software Use of Java Generics and Native Types
Book
Many of the example programs do not strictly follow common Java programming idioms – this is usually done for brevity. For example, when a short example is all
in one Java package I will save lines of code and programing listing space by not declaring class data private with public getters and setters; instead, I will sometimes
simply use package visibility as in this example:
public static class Problem { constants for appliance types:
enum Appliance {REFRIGERATOR, MICROWAVE, TV, DVD}; constants for problem types:
enum ProblemType {NOT_RUNNING, SMOKING, ON_FIRE,
MAKES_NOISE}; constants for environmental data:
enum EnvironmentalDescription {CIRCUIT_BREAKER_OFF, LIGHTS_OFF_IN_ROOM};
Appliance applianceType; ListProblemType problemTypes =
new ArrayListProblemType; ListEnvironmentalDescription environmentalData =
new ArrayListEnvironmentalDescription; etc.
} Please understand that I do not advocate this style of programming in large projects
but one challenge in writing about software development is the requirement to make the examples short and easily read and understood. Many of the examples started as
large code bases for my own projects that I “whittled down” to a small size to show one or two specific techniques. Forgoing the use of “getters and setters” in many of
the examples is just another way to shorten the examples.
Authors of programming books are faced with a problem in formatting program snippets: limited page width. You will frequently see what would be a single line in
a Java source file split over two or three lines to accommodate limited page width as seen in this example:
private static void createTestFactsWorkingMemory workingMemory
throws Exception { ...
}
3
Chapter 1 is the introduction for this book. Chapter 2 deals with heuristic search in two domains: two-dimensional grids for
example mazes and graphs defined by nodes and edges connecting nodes. Chapter 3 covers logic, knowledge representation, and reasoning using the Power-
Loom system. Chapter 4 covers the Semantic Web. You will learn how to use RDF and RDFS
data for knowledge representation and how to use the popular Sesame open source Semantic Web system.
Chapter 5 introduces you to rule-based or production systems. We will use the open source Drools system to implement simple expert systems for solving “blocks
world” problems and to simulate a help desk system.
Chapter 6 gives an overview of Genetic Algorithms, provides a Java library, and solves a test problem. The chapter ends with suggestions for projects you might
want to try.
Chapter 7 introduces Hopfield and Back Propagation Neural Networks. In addition to Java libraries you can use in your own projects, we will use two Swing-based Java
applications to visualize how neural networks are trained.
Chapter 8 introduces you to the GPLed Weka project. Weka is a best of breed toolkit for solving a wide range of machine learning problems.
Chapter 9 covers several Statistical Natural Language Processing NLP techniques that I often use in my own work: processing text tokenizing, stemming, and de-
termining part of speech, named entity extraction from text, using the WordNet lexical database, automatically assigning tags to text, text clustering, three different
approaches to spelling correction, and a short tutorial on Markov Models.
Chapter 10 provides useful techniques for gathering and using information: using the Open Calais web services for extracting semantic information from text, infor-
mation discovery in relational databases, and three different approaches to indexing and searching text.
4
2 Search
Early AI research emphasized the optimization of search algorithms. This approach made a lot of sense because many AI tasks can be solved effectively by defining
state spaces and using search algorithms to define and explore search trees in this state space. Search programs were frequently made tractable by using heuristics to
limit areas of search in these search trees. This use of heuristics converts intractable problems to solvable problems by compromising the quality of solutions; this trade
off of less computational complexity for less than optimal solutions has become a standard design pattern for AI programming. We will see in this chapter that we
trade off memory for faster computation time and better results; often, by storing extra data we can make search time faster, and make future searches in the same
search space even more efficient.
What are the limitations of search? Early on, search applied to problems like check- ers and chess misled early researchers into underestimating the extreme difficulty of
writing software that performs tasks in domains that require general world knowl- edge or deal with complex and changing environments. These types of problems
usually require the understanding and then the implementation of domain specific knowledge.
In this chapter, we will use three search problem domains for studying search algo- rithms: path finding in a maze, path finding in a graph, and alpha-beta search in the
games tic-tac-toe and chess.