Java Reference
In-Depth Information
+ "directory to work with a professional "
+ "Realtor and find your perfect home.";
String martinLuther =
"Luther taught that salvation and subsequently "
+ "eternity in heaven is not earned by good deeds "
+ "but is received only as a free gift of God's "
+ "grace through faith in Jesus Christ as redeemer "
+ "from sin and subsequently eternity in Hell.";
To reuse the classifier serialized in the previous section, use the AbstractExternal-
izable class' readObject method as shown here. We will use the LMClassifier
class instead of the DynamicLMClassifier class. They both support the classify
method but the DynamicLMClassifier class is not readily serializable:
LMClassifier classifier = null;
try {
classifier = (LMClassifier)
AbstractExternalizable.readObject(
new File("classifier.model"));
} catch (IOException | ClassNotFoundException ex) {
// Handle exceptions
}
In the next code sequence, we apply the LMClassifier class' classify method.
This returns a JointClassification instance, which we use to determine the best
match:
JointClassification classification =
classifier.classify(text);
System.out.println("Text: " + text);
String bestCategory = classification.bestCategory();
System.out.println("Best Category: " + bestCategory);
For the forSale text, we get the following output:
Text: Finding a home for sale has never been easier. With
Homes.com, you can search new homes, foreclosures,
multi-family homes, as well as condos and townhouses for
sale. You can even search our real estate agent directory
Search WWH ::




Custom Search