Text Analysis with LingPipe 4
Text Analysis with LingPipe 4
复制标题
使用 LingPipe 4 进行文本分析
DOI:
--
复制
发表时间:
2011
期刊:
影响因子:
--
通讯作者:
Breck Baldwin
中科院分区:
文献类型:
--
作者:
Bob Carpenter;Breck Baldwin
Externalizable.compileTo(classifier,file); @SuppressWarnings("unchecked") ConditionalClassifier<CharSequence> compiledClassifier = (ConditionalClassifier<CharSequence>) AbstractExternalizable.readObject(file); file.delete(); The static utility method compileTo() from Java’s class AbstractExternalizable class (in the util package) is used to do the writing. This could also be done through LingPipe’s Compilable interface directly using the traditional naive Bayes class’s method compileTo(ObjectOut). We deserialized using another utility method, readObject(), which reads and returns serialized objects from files (there are also utility methods to read compiled or serialized models from the class path as resources). Usually, one program would write the compiled file and another program, perhaps on another machine or at a different site, would read it. Here, we have put the two operations together for reference. Note that the unchecked cast warning on reading back in is suppressed; an error may still result at runtime from the cast if the file supplied to read back in has an object of a different type or isn’t a serialized object at all. Note that when read back in, it is assigned to a JointClassifier<CharSequence>; attempting to cast to a TradNaiveBayesClassifier would fail, as the compiled version is not an instance of that class. We do the same thing for serialization, using a different utility method to serialize, but the same readObject() method to deserialize. AbstractExternalizable.serializeTo(classifier,file);Externalizable.serializeTo(classifier,file); @SuppressWarnings("unchecked") TradNaiveBayesClassifier deserializedClassifier = (TradNaiveBayesClassifier) AbstractExternalizable.readObject(file); file.delete(); 10.10. TRAINING AND TESTING WITH A CORPUS 187 Here, we are able to cast the deserialized object back to the original class, TradNaiveBayesClassifier. Because deserialization results in a traditional naive Bayes classifier, we may provide more training data. Repeating the serialization and deserialization with a different variable, we can go on to train. String s = "hardy har har"; Classified<CharSequence> trainInstance = new Classified<CharSequence>(s,hisCl); deserializedClassifierTrain.handle(trainInstance);