当前位置: 首页>>代码示例>>Java>>正文


Java Classified类代码示例

本文整理汇总了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);
}
 
开发者ID:sandor-balazs,项目名称:sentiment-analysis,代码行数:25,代码来源:AbstractClassifier.java

示例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);
}
 
开发者ID:sandor-balazs,项目名称:sentiment-analysis,代码行数:25,代码来源:AbstractClassifier.java

示例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);
    }
}
 
开发者ID:bbejeck,项目名称:kafka-streams,代码行数:12,代码来源:Classifier.java

示例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);
	}
}
 
开发者ID:yangzhou04,项目名称:em-naive-bayes,代码行数:10,代码来源:EmNaiveBayes.java

示例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;
}
 
开发者ID:simon0191,项目名称:MinerPCAdviser,代码行数:11,代码来源:MpcaLingPipeClassifier.java

示例7: visitTest

import com.aliasi.classify.Classified; //导入依赖的package包/类
@Override
public void visitTest(ObjectHandler<Classified<CharSequence>> handler) {
	throw new UnsupportedOperationException();
}
 
开发者ID:yangzhou04,项目名称:em-naive-bayes,代码行数:5,代码来源:EmNaiveBayes.java


注:本文中的com.aliasi.classify.Classified类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。