<commit_before>/**
 * 
 */
package org.semanticweb.elk.reasoner.stages;

/*
 * #%L
 * ELK Reasoner
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2011 - 2012 Department of Computer Science, University of Oxford
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.Collections;
import java.util.Iterator;

import org.apache.log4j.Logger;
import org.semanticweb.elk.reasoner.incremental.IncrementalStages;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedClassExpression;
import org.semanticweb.elk.reasoner.saturation.SaturationState;
import org.semanticweb.elk.reasoner.saturation.SaturationStatistics;
import org.semanticweb.elk.reasoner.saturation.conclusions.ConclusionStatistics;
import org.semanticweb.elk.reasoner.saturation.conclusions.ConclusionVisitor;
import org.semanticweb.elk.reasoner.saturation.conclusions.CountingConclusionVisitor;
import org.semanticweb.elk.util.collections.Operations;

/**
 * @author <NAME>
 * 
 *         <EMAIL>
 */
abstract class BaseIncrementalContextInitializationStage extends
		AbstractReasonerStage {

	// logger for this class
	static final Logger LOGGER_ = Logger
			.getLogger(BaseIncrementalContextInitializationStage.class);

	static final boolean COLLECT_CONCLUSION_COUNTS = true;// LOGGER_.isDebugEnabled();

	protected final SaturationStatistics stageStatistics_ = new SaturationStatistics();

	/**
	 * The counter for deleted contexts
	 */
	protected int initContexts_;
	/**
	 * The number of contexts
	 */
	protected int maxContexts_;

	/**
	 * The state of the iterator of the input to be processed
	 */
	protected Iterator<IndexedClassExpression> todo = null;

	public BaseIncrementalContextInitializationStage(
			AbstractReasonerState reasoner) {
		super(reasoner);
	}

	@Override
	public String getName() {
		return stage().toString();
	}

	@Override
	public boolean done() {
		return reasoner.incrementalState.getStageStatus(stage());
	}

	protected ConclusionVisitor<?> getConclusionVisitor(
			ConclusionStatistics conclusionStatistics) {

		return COLLECT_CONCLUSION_COUNTS ? new CountingConclusionVisitor(
				conclusionStatistics.getProducedConclusionCounts())
				: ConclusionVisitor.DUMMY;
	}

	@Override
	public void execute() throws ElkInterruptedException {

		final ConclusionVisitor<?> visitor = getConclusionVisitor(stageStatistics_
				.getConclusionStatistics());
		final SaturationState.ExtendedWriter writer = reasoner.saturationState
				.getExtendedWriter(visitor);

		if (todo == null) {
			initComputation();
		}

		try {
			progressMonitor.start(getName());
			for (;;) {
				if (!todo.hasNext())
					break;
				IndexedClassExpression ice = todo.next();

				if (ice.getContext() != null) {
					writer.initContext(ice.getContext());
				}

				initContexts_++;
				progressMonitor.report(initContexts_, maxContexts_);

				if (interrupted()) {
					continue;
				}
			}
		} finally {
			progressMonitor.finish();
		}
		reasoner.doneContextReset = true;
	}

	@Override
	public void printInfo() {
		if (initContexts_ > 0 && LOGGER_.isDebugEnabled())
			LOGGER_.debug("Contexts init:" + initContexts_);
	}

	protected abstract IncrementalStages stage();
}
<commit_msg>forgot to add the stage's stats to the overall stats<commit_after>/**
 * 
 */
package org.semanticweb.elk.reasoner.stages;

/*
 * #%L
 * ELK Reasoner
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2011 - 2012 Department of Computer Science, University of Oxford
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.Collections;
import java.util.Iterator;

import org.apache.log4j.Logger;
import org.semanticweb.elk.reasoner.incremental.IncrementalStages;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedClassExpression;
import org.semanticweb.elk.reasoner.saturation.SaturationState;
import org.semanticweb.elk.reasoner.saturation.SaturationStatistics;
import org.semanticweb.elk.reasoner.saturation.conclusions.ConclusionStatistics;
import org.semanticweb.elk.reasoner.saturation.conclusions.ConclusionVisitor;
import org.semanticweb.elk.reasoner.saturation.conclusions.CountingConclusionVisitor;
import org.semanticweb.elk.util.collections.Operations;

/**
 * @author <NAME>
 * 
 *         <EMAIL>
 */
abstract class BaseIncrementalContextInitializationStage extends
		AbstractReasonerStage {

	// logger for this class
	static final Logger LOGGER_ = Logger
			.getLogger(BaseIncrementalContextInitializationStage.class);

	static final boolean COLLECT_CONCLUSION_COUNTS = true;// LOGGER_.isDebugEnabled();

	protected final SaturationStatistics stageStatistics_ = new SaturationStatistics();

	/**
	 * The counter for deleted contexts
	 */
	protected int initContexts_;
	/**
	 * The number of contexts
	 */
	protected int maxContexts_;

	/**
	 * The state of the iterator of the input to be processed
	 */
	protected Iterator<IndexedClassExpression> todo = null;

	public BaseIncrementalContextInitializationStage(
			AbstractReasonerState reasoner) {
		super(reasoner);
	}

	@Override
	public String getName() {
		return stage().toString();
	}

	@Override
	public boolean done() {
		return reasoner.incrementalState.getStageStatus(stage());
	}

	protected ConclusionVisitor<?> getConclusionVisitor(
			ConclusionStatistics conclusionStatistics) {

		return COLLECT_CONCLUSION_COUNTS ? new CountingConclusionVisitor(
				conclusionStatistics.getProducedConclusionCounts())
				: ConclusionVisitor.DUMMY;
	}

	@Override
	public void execute() throws ElkInterruptedException {

		final ConclusionVisitor<?> visitor = getConclusionVisitor(stageStatistics_
				.getConclusionStatistics());
		final SaturationState.ExtendedWriter writer = reasoner.saturationState
				.getExtendedWriter(visitor);

		if (todo == null) {
			initComputation();
		}

		try {
			progressMonitor.start(getName());
			for (;;) {
				if (!todo.hasNext())
					break;
				IndexedClassExpression ice = todo.next();

				if (ice.getContext() != null) {
					writer.initContext(ice.getContext());
				}

				initContexts_++;
				progressMonitor.report(initContexts_, maxContexts_);

				if (interrupted()) {
					continue;
				}
			}
		} finally {
			progressMonitor.finish();
		}
		
		reasoner.doneContextReset = true;
		reasoner.ruleAndConclusionStats.add(stageStatistics_);
	}

	@Override
	public void printInfo() {
		if (initContexts_ > 0 && LOGGER_.isDebugEnabled())
			LOGGER_.debug("Contexts init:" + initContexts_);
	}

	protected abstract IncrementalStages stage();
}

{'fraction_non_alphanumeric': 0.09865351286495135, 'fraction_numerical': 0.0037328356219170776, 'mean_word_length': 4.4520348837209305, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2150105', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2126, 'n_words': 542}