本文整理汇总了Java中com.aliasi.classify.Classified类的典型用法代码示例。如果您正苦于以下问题:Java Classified类的具体用法?Java Classified怎么用?Java Classified使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Classified类属于com.aliasi.classify包,在下文中一共展示了Classified类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: train
import com.aliasi.classify.Classified; //导入依赖的package包/类
protected void train(ReviewCorpus trainerCorpus)
throws FileNotFoundException, IOException {
HashMap<String, List<String>> categoriesWithSentences = getCategoriesWithSentences(
trainerCorpus);
int numberOfCategories = 0;
int numberOfSentences = 0;
for (String category : classifier.categories()) {
logger.debug("Training: {}", category);
Classification classification = new Classification(category);
numberOfCategories++;
numberOfSentences = 0;
for (String sentence : categoriesWithSentences.get(category)) {
logger.debug("\t sentence: {}", sentence);
Classified<CharSequence> classified = new Classified<CharSequence>(
sentence, classification);
classifier.handle(classified);
numberOfSentences++;
}
logger.debug("Training of {} finished. Number of sentences used: {}",
category, numberOfSentences);
}
logger.debug("Training finished. Number of categories: {}.",
numberOfCategories);
}
示例2: evaluate
import com.aliasi.classify.Classified; //导入依赖的package包/类
public void evaluate(ReviewCorpus evaluatorCorpus) {
JointClassifierEvaluator<CharSequence> evaluator = new JointClassifierEvaluator<CharSequence>(
classifier, classifier.categories(), false);
HashMap<String, List<String>> categoriesWithSentences = getCategoriesWithSentences(
evaluatorCorpus);
int numberOfCategories = 0;
int numberOfSentences = 0;
for (String category : getCategories(evaluatorCorpus)) {
Classification classification = new Classification(category);
numberOfCategories++;
numberOfSentences = 0;
for (String sentence : categoriesWithSentences.get(category)) {
Classified<CharSequence> classified = new Classified<CharSequence>(
sentence, classification);
evaluator.handle(classified);
numberOfSentences++;
}
logger.debug("Evaluation of {} finished. Number of sentences used: {}",
category, numberOfSentences);
}
logger.debug(
"Evaluation of {} finished. Number of categories: {}. Details: {}",
this.getClass(), numberOfCategories, evaluator);
}
示例3: buildSentimentAnalysisModel
import com.aliasi.classify.Classified; //导入依赖的package包/类
public void buildSentimentAnalysisModel() {
out.println("Building Sentiment Model");
File trainingDir = new File("C:\\Jenn Personal\\Packt Data Science\\Chapter 12\\review_polarity\\txt_sentoken");
for (int i = 0; i < labels.length; i++) {
Classification classification = new Classification(labels[i]);
File file = new File(trainingDir, labels[i]);
File[] trainingFiles = file.listFiles();
for (int j = 0; j < trainingFiles.length; j++) {
try {
String review = Files.readFromFile(trainingFiles[j], "ISO-8859-1");
Classified<CharSequence> classified = new Classified<>(review, classification);
classifier.handle(classified);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
// out.println("---saving model");
// try {
// AbstractExternalizable
// .compileTo((Compilable) classifier,
// new File("classifier.model"));
// out.println("---classifer model saved");
// } catch (IOException ex) {
// ex.printStackTrace();
// }
// out.println("---buildSentimentAnalysisModel terminated");
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:31,代码来源:TweetHandler.java
示例4: trainClassifier
import com.aliasi.classify.Classified; //导入依赖的package包/类
private void trainClassifier(Set<String> categorySet, List<String[]> annotatedData){
String[] categories = categorySet.toArray(new String[0]);
classifier = DynamicLMClassifier.createNGramBoundary(categories,maxCharNGram);
for (String[] row: annotatedData) {
String actualClassification = row[0];
String text = row[1];
Classification classification = new Classification(actualClassification);
Classified<CharSequence> classified = new Classified<>(text,classification);
classifier.handle(classified);
}
}
示例5: visitTrain
import com.aliasi.classify.Classified; //导入依赖的package包/类
@Override
public void visitTrain(ObjectHandler<Classified<CharSequence>> classifier) {
for (int i = 0; i < N; i++) {
Classification label = new Classification(y.get(i));
Classified<CharSequence> labeledInstance =
new Classified<CharSequence>(X.get(i), label);
classifier.handle(labeledInstance);
}
}
示例6: train
import com.aliasi.classify.Classified; //导入依赖的package包/类
@Override
public synchronized void train(String category, List<String> reviews) {
Classification classification = new Classification(category);
for (String r : reviews) {
Classified<CharSequence> classified = new Classified<CharSequence>(r, classification);
classifier.handle(classified);
}
trainingSize += reviews.size();
isTrained = true;
}
示例7: visitTest
import com.aliasi.classify.Classified; //导入依赖的package包/类
@Override
public void visitTest(ObjectHandler<Classified<CharSequence>> handler) {
throw new UnsupportedOperationException();
}