本文整理汇总了Java中com.aliasi.classify.Classification类的典型用法代码示例。如果您正苦于以下问题:Java Classification类的具体用法?Java Classification怎么用?Java Classification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Classification类属于com.aliasi.classify包,在下文中一共展示了Classification类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: train
import com.aliasi.classify.Classification; //导入依赖的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);
}
开发者ID:sandor-balazs,项目名称:sentiment-analysis,代码行数:25,代码来源:AbstractClassifier.java
示例2: evaluate
import com.aliasi.classify.Classification; //导入依赖的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);
}
开发者ID:sandor-balazs,项目名称:sentiment-analysis,代码行数:25,代码来源:AbstractClassifier.java
示例3: buildSentimentAnalysisModel
import com.aliasi.classify.Classification; //导入依赖的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.Classification; //导入依赖的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);
}
}
开发者ID:bbejeck,项目名称:kafka-streams,代码行数:12,代码来源:Classifier.java
示例5: visitTrain
import com.aliasi.classify.Classification; //导入依赖的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);
}
}
开发者ID:yangzhou04,项目名称:em-naive-bayes,代码行数:10,代码来源:EmNaiveBayes.java
示例6: train
import com.aliasi.classify.Classification; //导入依赖的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;
}
开发者ID:simon0191,项目名称:MinerPCAdviser,代码行数:11,代码来源:MpcaLingPipeClassifier.java
示例7: bestMatch
import com.aliasi.classify.Classification; //导入依赖的package包/类
@Override
public String bestMatch(String text) throws MpcaClassifierNotTrainedException {
if(!isTrained()) {
throw new MpcaClassifierNotTrainedException();
}
Classification classification = classifier.classify(text);
return classification.bestCategory();
}
开发者ID:simon0191,项目名称:MinerPCAdviser,代码行数:9,代码来源:MpcaLingPipeClassifier.java
示例8: performSentimentAnalysis
import com.aliasi.classify.Classification; //导入依赖的package包/类
public TweetHandler performSentimentAnalysis() {
Classification classification = classifier.classify(this.text);
String bestCategory = classification.bestCategory();
this.category = bestCategory;
return this;
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:7,代码来源:TweetHandler.java
注:本文中的com.aliasi.classify.Classification类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论