net.sf.classifier4J.bayesian
Class JDBCWordsDataSource

java.lang.Object
  |
  +--net.sf.classifier4J.bayesian.JDBCWordsDataSource
All Implemented Interfaces:
ICategorisedWordsDataSource, IWordsDataSource

public class JDBCWordsDataSource
extends java.lang.Object
implements ICategorisedWordsDataSource

A JDBC based datasource. It requires a table of the following structure (tested in MySQL 4):

 CREATE TABLE word_probability (
	word			VARCHAR(255) NOT NULL,
	category		VARCHAR(20) NOT NULL,
	match_count		INT DEFAULT 0 NOT NULL,
	nonmatch_count	INT DEFAULT 0 NOT NULL,
	PRIMARY KEY(word, category)
 )
 

It will truncate any word longer than 255 characters to 255 characters

Author:
Nick Lothian, Peter Leschev

Constructor Summary
JDBCWordsDataSource(IJDBCConnectionManager cm)
          Create a JDBCWordsDataSource using the DEFAULT_CATEGORY ("DEFAULT")
 
Method Summary
 void addMatch(java.lang.String word)
          Add a matching word to the data source
 void addMatch(java.lang.String category, java.lang.String word)
          Add a matching word to the data source
 void addNonMatch(java.lang.String word)
          Add a non-matching word to the data source
 void addNonMatch(java.lang.String category, java.lang.String word)
          Add a non-matching word to the data source
 WordProbability getWordProbability(java.lang.String word)
           
 WordProbability getWordProbability(java.lang.String category, java.lang.String word)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCWordsDataSource

public JDBCWordsDataSource(IJDBCConnectionManager cm)
                    throws WordsDataSourceException
Create a JDBCWordsDataSource using the DEFAULT_CATEGORY ("DEFAULT")

Parameters:
cm - The connection manager to use
Method Detail

getWordProbability

public WordProbability getWordProbability(java.lang.String category,
                                          java.lang.String word)
                                   throws WordsDataSourceException
Specified by:
getWordProbability in interface ICategorisedWordsDataSource
Parameters:
category - the category to check against
word - The word to calculate the probability of
Returns:
The word probability if the word exists, null otherwise;
Throws:
WordsDataSourceException - If there is a fatal problem. For example, the database is unavailable

getWordProbability

public WordProbability getWordProbability(java.lang.String word)
                                   throws WordsDataSourceException
Specified by:
getWordProbability in interface IWordsDataSource
Parameters:
word - The word to calculate the probability of
Returns:
The word probability if the word exists, null otherwise;
Throws:
WordsDataSourceException - If there is a fatal problem. For example, the database is unavailable

addMatch

public void addMatch(java.lang.String category,
                     java.lang.String word)
              throws WordsDataSourceException
Description copied from interface: ICategorisedWordsDataSource
Add a matching word to the data source

Specified by:
addMatch in interface ICategorisedWordsDataSource
Parameters:
category - the category add the match to
word - the word that matches
Throws:
WordsDataSourceException - If there is a fatal problem. For example, the database is unavailable

addMatch

public void addMatch(java.lang.String word)
              throws WordsDataSourceException
Description copied from interface: IWordsDataSource
Add a matching word to the data source

Specified by:
addMatch in interface IWordsDataSource
Parameters:
word - the word that matches
Throws:
WordsDataSourceException - If there is a fatal problem. For example, the database is unavailable

addNonMatch

public void addNonMatch(java.lang.String category,
                        java.lang.String word)
                 throws WordsDataSourceException
Description copied from interface: ICategorisedWordsDataSource
Add a non-matching word to the data source

Specified by:
addNonMatch in interface ICategorisedWordsDataSource
Parameters:
category - the category add the non-match to
word - the word that does not match
Throws:
WordsDataSourceException - If there is a fatal problem. For example, the database is unavailable

addNonMatch

public void addNonMatch(java.lang.String word)
                 throws WordsDataSourceException
Description copied from interface: IWordsDataSource
Add a non-matching word to the data source

Specified by:
addNonMatch in interface IWordsDataSource
Parameters:
word - the word that does not match
Throws:
WordsDataSourceException - If there is a fatal problem. For example, the database is unavailable


Copyright © 2003-2005 Nick Lothian. All Rights Reserved.