Most of the electronic stuffs we use everyday are products of artificial intelligence in collaboration with electrical, mechanical and computer engineering. These things include cell phones in general, digital radios, digital clocks, car stereo or t.v., microwave ovens and more you can add to the list.
Artificial Intelligence is also responsible in making your social network sites like twitter, easy to use, even on iPhones or Droids. It is also the core concept in web research engines like google and yahoo. Added to the list are data mining technologies, and text classification and filtering.
AI is just the theory or the concept. In order for this concept to work, we need a tool to implement a systematic program that will create its interface. And this is where Java comes in. Java is a one of the most portable and easiest to write programming language. It is in fact the widely used platform of most software applications today.
So, in this article, we will discuss the 5 easy ways to use artificial intelligence with Java.
Customer Recommender System
Most often, customers depend on recommendations to make decisions. Having a large volume of information in your site, not to mention the competitor's solutions, it is important to employ collaborative filtering in your recommender system.
Collaborative filtering strains out historical search items for a specific user and then correlates them to available information in your site, thus the process predicts the user's future interests and recommends the best given option. An example implementation for this is shown here.
Intelligent Search Applications

Intelligent Search Applications
Intelligent search is a process of finding relevant information from an enormous set of non-relevant information. Finding the best results from a given search keyword is a task of a full-featured text search engine library such as Apache Lucenel
The Apache Lucene is the 800 pound gorilla in the realm of open source search. It's written in 100% JAVA however it's been ported to many other languages. Here is a short example of how to use the library.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
// Store the index in memory:
Directory directory = new RAMDirectory();
// To store an index on disk, use this instead:
//Directory directory = FSDirectory.open("/tmp/testindex");
IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
new IndexWriter.MaxFieldLength(25000));
Document doc = new Document();
String text = "This is the text to be indexed.";
doc.add(new Field("fieldname", text, Field.Store.YES,
Field.Index.ANALYZED));
iwriter.addDocument(doc);
iwriter.close(); |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| // Now search the index:
// read-only=true
IndexSearcher isearcher = new IndexSearcher(directory, true);
// Parse a simple query that searches for "text":
QueryParser parser = new QueryParser("fieldname", analyzer);
Query query = parser.parse("text");
ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
assertEquals(1, hits.length);
// Iterate through the results:
for (int i = 0; i < hits.length; i++) {
Document hitDoc = isearcher.doc(hits[i].doc);
assertEquals("This is text to be indexed.", hitDoc.get("fieldname"));
}
isearcher.close();
directory.close(); |
Text Processing
Probably the most widely used computer application is text processing. Text processing is the manipulation of letters, words or phrases and even sentences and paragraphs. This process is performed by text processors such as your Microsoft Word, Lotus Notes etc. We do text editing of all sorts which may come handy depending on the type of document we are working on.

Text Document Classification
Text processing is enabled by text editor programs developed in JavaScript/ECMAScript,which is higly customizable. An example of a text editor program is JTextPro. A Java-based Text Processing tool that includes sentence boundary detection (using maximum entropy classifier), word tokenization (following Penn conventions), part-of-speech tagging (using CRFTagger), and phrase chunking (using CRFChunker).
A desirable feature of a word processing application is to change the case of a word, sentence or entire document. This sample application shows you, how to implement the different cases known from Microsoft Word in TX Text Control ActiveX. We are going to implement the following case changes:
* UPPER CASE
* lower case
* Title Case
* tOgGlE cAsE
* Sentence case.
Click here to see a snippet code for this implementation.
Text Document Classification
Document classification is the partitioning of unstructured sets of documents into groups that describe the contents of the documents. There are two main variants of document classification: text clustering and text categorization. The first is concerned with finding a static group structure in the set of documents, while the second (also known as text classification) can be seen as the task of structuring the repository of documents according to a group structure that is known in advance. For our discussion, let's focus on text classification.
Data can be classified according to any criteria, not only relative importance or frequency of use. For example, data can be broken down according to its topical content, file type, operating platform, average file size in megabytes or gigabytes etc. A well-constructed data classification system makes essential data easy to find.
Naive Bayesian Network is one best way to implement text classification. A naive Bayes classifier is a simple probabilistic classifier based on applying Bayes' theorem (from Bayesian statistics) with strong (naive) independence assumptions. In simple terms, a naive Bayes classifier assumes that the presence (or absence) of a particular feature of a class is unrelated to the presence (or absence) of any other feature. Here is a worked example of naive Bayesian classification to the document classification problem.
If you find this interesting, here is a sample code for the naive bayes classifier using Lucene.
Data Mining
Data mining "is a process for finding patterns and relationships in the data". This process is then used to classify users text or document into an information relevant to profiling practices, such as marketing, surveillance, fraud detection and scientific discovery.
Data mining commonly involves four classes of task, classification, clustering, regression and association rule learning. Please refer to "Text Classification" section for Classification and clustering. Regression attempts to find a function which models the data with the least error. A common method is to use Genetic Programming. Finally, association rule learning searches for relationships between variables. For example a supermarket might gather data of what each customer buys. Using association rule learning, the supermarket can work out what products are frequently bought together, which is useful for marketing purposes. This is sometimes referred to as "market basket analysis".
Refer to this link for in-depth discussion on this topic.