Practical Artificial Intelligence Programming in Java, Third Edition, Mark Watson.pdf

(1273 KB) Pobierz
162480794 UNPDF
Practical Artificial Intelligence
Programming With Java
Third Edition
Mark Watson
Copyright 2001-2008 Mark Watson. All rights reserved.
This work is licensed under a Creative Commons
Attribution-Noncommercial-No Derivative Works
Version 3.0 United States License.
November 11, 2008
Contents
Preface
xi
1 Introduction
1
1.1 Other JVM Languages . . . . . . . . . . . . . . . . . . . . . . . .
1
1.2 Why is a PDF Version of this Book Available Free on the Web? . . .
1
1.3 Book Software . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.4 Use of Java Generics and Native Types . . . . . . . . . . . . . . . .
2
1.5 Notes on Java Coding Styles Used in this Book . . . . . . . . . . .
3
1.6 Book Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
2 Search 5
2.1 Representation of Search State Space and Search Operators . . . . . 5
2.2 Finding Paths in Mazes . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Finding Paths in Graphs . . . . . . . . . . . . . . . . . . . . . . . . 13
2.4 Adding Heuristics to Breadth First Search . . . . . . . . . . . . . . 22
2.5 Search and Game Playing . . . . . . . . . . . . . . . . . . . . . . . 22
2.5.1 Alpha-Beta Search . . . . . . . . . . . . . . . . . . . . . . 22
2.5.2 A Java Framework for Search and Game Playing . . . . . . 24
2.5.3 Tic-Tac-Toe Using the Alpha-Beta Search Algorithm . . . . 29
2.5.4 Chess Using the Alpha-Beta Search Algorithm . . . . . . . 34
3 Reasoning 45
3.1 Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3.1.1 History of Logic . . . . . . . . . . . . . . . . . . . . . . . 47
3.1.2 Examples of Different Logic Types . . . . . . . . . . . . . 47
3.2 PowerLoom Overview . . . . . . . . . . . . . . . . . . . . . . . . 48
3.3 Running PowerLoom Interactively . . . . . . . . . . . . . . . . . . 49
3.4 Using the PowerLoom APIs in Java Programs . . . . . . . . . . . . 52
3.5 Suggestions for Further Study . . . . . . . . . . . . . . . . . . . . 54
4 Semantic Web
57
4.1 Relational Database Model Has Problems Dealing with Rapidly Chang-
ing Data Requirements . . . . . . . . . . . . . . . . . . . . . . . . 58
4.2 RDF: The Universal Data Format . . . . . . . . . . . . . . . . . . . 59
4.3 Extending RDF with RDF Schema . . . . . . . . . . . . . . . . . . 62
4.4 The SPARQL Query Language . . . . . . . . . . . . . . . . . . . . 63
4.5 Using Sesame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
iii
Contents
4.6 OWL: The Web Ontology Language . . . . . . . . . . . . . . . . . 69
4.7 Knowledge Representation and REST . . . . . . . . . . . . . . . . 71
4.8 Material for Further Study . . . . . . . . . . . . . . . . . . . . . . 72
5 Expert Systems 73
5.1 Production Systems . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.2 The Drools Rules Language . . . . . . . . . . . . . . . . . . . . . 75
5.3 Using Drools in Java Applications . . . . . . . . . . . . . . . . . . 77
5.4 Example Drools Expert System: Blocks World . . . . . . . . . . . 81
5.4.1 POJO Object Models for Blocks World Example . . . . . . 82
5.4.2 Drools Rules for Blocks World Example . . . . . . . . . . . 85
5.4.3 Java Code for Blocks World Example . . . . . . . . . . . . 88
5.5 Example Drools Expert System: Help Desk System . . . . . . . . . 90
5.5.1 Object Models for an Example Help Desk . . . . . . . . . . 91
5.5.2 Drools Rules for an Example Help Desk . . . . . . . . . . . 93
5.5.3 Java Code for an Example Help Desk . . . . . . . . . . . . 95
5.6 Notes on the Craft of Building Expert Systems . . . . . . . . . . . . 97
6 Genetic Algorithms 99
6.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6.2 Java Library for Genetic Algorithms . . . . . . . . . . . . . . . . . 101
6.3 Finding the Maximum Value of a Function . . . . . . . . . . . . . . 105
7 Neural Networks 109
7.1 Hopfield Neural Networks . . . . . . . . . . . . . . . . . . . . . . 110
7.2 Java Classes for Hopfield Neural Networks . . . . . . . . . . . . . 111
7.3 Testing the Hopfield Neural Network Class . . . . . . . . . . . . . 114
7.4 Back Propagation Neural Networks . . . . . . . . . . . . . . . . . 116
7.5 A Java Class Library for Back Propagation . . . . . . . . . . . . . . 119
7.6 Adding Momentum to Speed Up Back-Prop Training . . . . . . . . 127
8 Machine Learning with Weka 129
8.1 Using Weka’s Interactive GUI Application . . . . . . . . . . . . . . 130
8.2 Interactive Command Line Use of Weka . . . . . . . . . . . . . . . 132
8.3 Embedding Weka in a Java Application . . . . . . . . . . . . . . . 134
8.4 Suggestions for Further Study . . . . . . . . . . . . . . . . . . . . 136
9 Statistical Natural Language Processing 137
9.1 Tokenizing, Stemming, and Part of Speech Tagging Text . . . . . . 137
9.2 Named Entity Extraction From Text . . . . . . . . . . . . . . . . . 141
9.3 Using the WordNet Linguistic Database . . . . . . . . . . . . . . . 144
9.3.1 Tutorial on WordNet . . . . . . . . . . . . . . . . . . . . . 144
9.3.2 Example Use of the JAWS WordNet Library . . . . . . . . 145
9.3.3 Suggested Project: Using a Part of Speech Tagger to Use
the Correct WordNet Synonyms . . . . . . . . . . . . . . . 149
iv
Contents
9.3.4 Suggested Project: Using WordNet Synonyms to Improve
Document Clustering . . . . . . . . . . . . . . . . . . . . . 150
9.4 Automatically Assigning Tags to Text . . . . . . . . . . . . . . . . 150
9.5 Text Clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9.6 Spelling Correction . . . . . . . . . . . . . . . . . . . . . . . . . . 156
9.6.1 GNU ASpell Library and Jazzy . . . . . . . . . . . . . . . 157
9.6.2 Peter Norvig’s Spelling Algorithm . . . . . . . . . . . . . . 158
9.6.3 Extending the Norvig Algorithm by Using Word Pair Statistics162
9.7 Hidden Markov Models . . . . . . . . . . . . . . . . . . . . . . . . 166
9.7.1 Training Hidden Markov Models . . . . . . . . . . . . . . . 168
9.7.2 Using the Trained Markov Model to Tag Text . . . . . . . . 173
10 Information Gathering 177
10.1 Open Calais . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10.2 Information Discovery in Relational Databases . . . . . . . . . . . 181
10.2.1 Creating a Test Derby Database Using the CIA World Fact-
Book and Data on US States . . . . . . . . . . . . . . . . . 182
10.2.2 Using the JDBC Meta Data APIs . . . . . . . . . . . . . . . 183
10.2.3 Using the Meta Data APIs to Discern Entity Relationships . 187
10.3 Down to the Bare Metal: In-Memory Index and Search . . . . . . . 187
10.4 Indexing and Search Using Embedded Lucene . . . . . . . . . . . . 193
10.5 Indexing and Search with Nutch Clients . . . . . . . . . . . . . . . 197
10.5.1 Nutch Server Fast Start Setup . . . . . . . . . . . . . . . . 198
10.5.2 Using the Nutch OpenSearch Web APIs . . . . . . . . . . . 201
11 Conclusions
207
v
Zgłoś jeśli naruszono regulamin