Java Reference
In-Depth Information
returns the number of categories handled by the model. The DocumentCategorizer-
ME class' getCategory method returns the category given an index.
We used these methods in the following code to display each category and its correspond-
ing likelihood:
double[] outcomes = categorizer.categorize(inputText);
for (int i = 0; i<categorizer.getNumberOfCategories(); i++)
{
String category = categorizer.getCategory(i);
System.out.println(category + " - " + outcomes[i]);
}
For testing, we used part of the Wikipedia article ( http://en.wikipedia.org/wiki/
Toto_%28Oz%29 ) for Toto, Dorothy's dog. We used the first sentence of The classic
topics section as declared here:
String toto = "Toto belongs to Dorothy Gale, the heroine of
"
+ "the first and many subsequent topics. In the
first "
+ "book, he never spoke, although other animals,
native "
+ "to Oz, did. In subsequent topics, other animals "
+ "gained the ability to speak upon reaching Oz or "
+ "similar lands, but Toto remained speechless.";
To test for a cat, we used the first sentence of the Tortoiseshell and Calico section of the
Wikipedia article ( http://en.wikipedia.org/wiki/Cats_and_humans ) as declared here:
String calico = "This cat is also known as a calimanco cat
or "
+ "clouded tiger cat, and by the abbreviation
'tortie'. "
+ "In the cat fancy, a tortoiseshell cat is patched
"
+ "over with red (or its dilute form, cream) and
black "
Search WWH ::




Custom Search