<commit_before>package pl.edu.icm.cermine.evaluation;

import java.io.IOException;
import java.util.List;
import libsvm.svm_parameter;
import org.apache.commons.cli.ParseException;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.cermine.metadata.zoneclassification.tools.BxDocsToHMMConverter;
import pl.edu.icm.cermine.structure.ZoneClassifier;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.classification.features.FeatureVectorBuilder;
import pl.edu.icm.cermine.tools.classification.hmm.training.TrainingElement;
import pl.edu.icm.cermine.tools.classification.sampleselection.OversamplingSelector;
import pl.edu.icm.cermine.tools.classification.sampleselection.SampleSelector;
import pl.edu.icm.cermine.tools.classification.svm.SVMZoneClassifier;

public class SVMInitialZoneClassificationEvaluator extends CrossvalidatingZoneClassificationEvaluator{ 
	@Override
	protected ZoneClassifier getZoneClassifier(List<BxDocument> trainingDocuments) throws IOException
	{
		FeatureVectorBuilder<BxZone, BxPage> featureVectorBuilder = getFeatureVectorBuilder();
//		for(BxDocument doc: trainingDocuments)
//			for(BxZone zone: doc.asZones())
//				if(zone.getLabel().getGeneralLabel() == BxZoneLabel.GEN_OTHER)
//					zone.setLabel(BxZoneLabel.GEN_BODY);
		
        BxDocsToHMMConverter node = new BxDocsToHMMConverter(featureVectorBuilder, BxZoneLabel.getLabelToGeneralMap());
        
        List<TrainingElement<BxZoneLabel>> trainingElements;
        try {
        	trainingElements = node.process(trainingDocuments);
        } catch(Exception e) {
        	System.out.println(e.getCause());
        	e.printStackTrace();
			throw new RuntimeException("Unable to process the delivered training documents!");
		}

        // Filter the training documents
        // so that in the learning examples all classes are
        // represented equally

        double inequalityFactor = 1.5;
        SampleSelector<BxZoneLabel> selector = new OversamplingSelector<BxZoneLabel>(1.0);
        trainingElements = selector.pickElements(trainingElements);

        SVMZoneClassifier zoneClassifier = new SVMZoneClassifier(featureVectorBuilder);<commit_msg>unused variable removed<commit_after>package pl.edu.icm.cermine.evaluation;

import java.io.IOException;
import java.util.List;
import libsvm.svm_parameter;
import org.apache.commons.cli.ParseException;
import pl.edu.icm.cermine.exception.AnalysisException;
import pl.edu.icm.cermine.metadata.zoneclassification.tools.BxDocsToHMMConverter;
import pl.edu.icm.cermine.structure.ZoneClassifier;
import pl.edu.icm.cermine.structure.model.BxDocument;
import pl.edu.icm.cermine.structure.model.BxPage;
import pl.edu.icm.cermine.structure.model.BxZone;
import pl.edu.icm.cermine.structure.model.BxZoneLabel;
import pl.edu.icm.cermine.tools.classification.features.FeatureVectorBuilder;
import pl.edu.icm.cermine.tools.classification.hmm.training.TrainingElement;
import pl.edu.icm.cermine.tools.classification.sampleselection.OversamplingSelector;
import pl.edu.icm.cermine.tools.classification.sampleselection.SampleSelector;
import pl.edu.icm.cermine.tools.classification.svm.SVMZoneClassifier;

public class SVMInitialZoneClassificationEvaluator extends CrossvalidatingZoneClassificationEvaluator{ 
	@Override
	protected ZoneClassifier getZoneClassifier(List<BxDocument> trainingDocuments) throws IOException
	{
		FeatureVectorBuilder<BxZone, BxPage> featureVectorBuilder = getFeatureVectorBuilder();
//		for(BxDocument doc: trainingDocuments)
//			for(BxZone zone: doc.asZones())
//				if(zone.getLabel().getGeneralLabel() == BxZoneLabel.GEN_OTHER)
//					zone.setLabel(BxZoneLabel.GEN_BODY);
		
        BxDocsToHMMConverter node = new BxDocsToHMMConverter(featureVectorBuilder, BxZoneLabel.getLabelToGeneralMap());
        
        List<TrainingElement<BxZoneLabel>> trainingElements;
        try {
        	trainingElements = node.process(trainingDocuments);
        } catch(Exception e) {
        	System.out.println(e.getCause());
        	e.printStackTrace();
			throw new RuntimeException("Unable to process the delivered training documents!");
		}

        // Filter the training documents
        // so that in the learning examples all classes are
        // represented equally

        SampleSelector<BxZoneLabel> selector = new OversamplingSelector<BxZoneLabel>(1.0);
        trainingElements = selector.pickElements(trainingElements);

        SVMZoneClassifier zoneClassifier = new SVMZoneClassifier(featureVectorBuilder);
{'fraction_non_alphanumeric': 0.09563365282215122, 'fraction_numerical': 0.0012779552715654952, 'mean_word_length': 4.929292929292929, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '539468', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1373, 'n_words': 218}