All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.semanticweb.elk.reasoner.saturation.ClassExpressionSaturation Maven / Gradle / Ivy

There is a newer version: 0.29.0
Show newest version
/*
 * #%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%
 */
package org.semanticweb.elk.reasoner.saturation;

import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;

import org.semanticweb.elk.reasoner.BatchListener;
import org.semanticweb.elk.reasoner.ProgressMonitor;
import org.semanticweb.elk.reasoner.ReasonerComputationWithInputs;
import org.semanticweb.elk.reasoner.indexing.model.IndexedContextRoot;
import org.semanticweb.elk.reasoner.saturation.rules.factories.RuleApplicationFactory;
import org.semanticweb.elk.reasoner.saturation.rules.factories.RuleApplicationInput;
import org.semanticweb.elk.util.concurrent.computation.ConcurrentExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A {@link ReasonerComputationWithInputs} that computes saturation for the
 * input collection of {@link IndexedContextRoot}s
 * 
 * @author Yevgeny Kazakov
 * @param 
 *                the types of {@link IndexedContextRoot}s managed by this
 *                computation
 * 
 */
public class ClassExpressionSaturation
		extends
		ReasonerComputationWithInputs, ClassExpressionSaturationFactory>> {

	// logger for this class
	private static final Logger LOGGER_ = LoggerFactory
			.getLogger(ClassExpressionSaturation.class);

	/*
	 * Takes inputs and uses the default rule application factory and a dummy
	 * listener runs without batches
	 */
	public ClassExpressionSaturation(Collection inputs,
			ConcurrentExecutor executor, int maxWorkers,
			ProgressMonitor progressMonitor,
			RuleApplicationFactory ruleAppFactory) {
		this(inputs, executor, maxWorkers, progressMonitor, ruleAppFactory,
				new DummyClassExpressionSaturationListener>());
	}
	
	/*
	 * Takes inputs and uses the default rule application factory and a dummy
	 * listener, runs in batches
	 */
	public ClassExpressionSaturation(Collection inputs,
			ConcurrentExecutor executor, int maxWorkers,
			ProgressMonitor progressMonitor,
			RuleApplicationFactory ruleAppFactory,
			int batchSize, BatchListener batchListener) {
		this(inputs, executor, maxWorkers, progressMonitor, ruleAppFactory,
				batchSize, batchListener,
				new DummyClassExpressionSaturationListener>());
	}

	/*
	 * Takes inputs and uses the default rule application factory, runs without batches
	 */
	public ClassExpressionSaturation(Collection inputs,
			ConcurrentExecutor executor, int maxWorkers,
			ProgressMonitor progressMonitor,
			RuleApplicationFactory ruleAppFactory,
			ClassExpressionSaturationListener> listener) {
		super(new TodoJobs(inputs),
				new ClassExpressionSaturationFactory>(
						ruleAppFactory, maxWorkers, listener),
				executor, maxWorkers, progressMonitor);
	}
	
	/*
	 * Takes inputs and uses the default rule application factory, runs in batches
	 */
	public ClassExpressionSaturation(Collection inputs,
			ConcurrentExecutor executor, int maxWorkers,
			ProgressMonitor progressMonitor,
			RuleApplicationFactory ruleAppFactory,
			int batchSize, BatchListener batchListener,
			ClassExpressionSaturationListener> listener) {
		super(new TodoJobs(inputs),
				new ClassExpressionSaturationFactory>(
						ruleAppFactory, maxWorkers, listener),
				executor, maxWorkers, progressMonitor, batchSize,
				batchListener);
	}

	/**
	 * Print statistics about the saturation computation
	 */
	public void printStatistics() {
		processorFactory.printStatistics();
	}

	public SaturationStatistics getRuleAndConclusionStatistics() {
		return processorFactory.getRuleAndConclusionStatistics();
	}

	/**
	 * Dynamic collection view for saturation checking jobs that correspond to
	 * the given input of {@link IndexedContextRoot}s.
	 * 
	 * @author "Yevgeny Kazakov"
	 * 
	 */
	private static class TodoJobs extends
			AbstractCollection> {

		private final Collection inputs;

		TodoJobs(Collection inputs) {
			this.inputs = inputs;
		}

		@Override
		public int size() {
			return inputs.size();
		}

		@Override
		public Iterator> iterator() {
			return new Iterator>() {

				final Iterator inputsIterator = inputs.iterator();

				@Override
				public boolean hasNext() {
					return inputsIterator.hasNext();
				}

				@Override
				public SaturationJob next() {
					SaturationJob job = new SaturationJob(
							inputsIterator.next());
					LOGGER_.trace("{}: saturation submitted", job.getInput());
					return job;
				}

				@Override
				public void remove() {
					inputsIterator.remove();
				}
			};
		}
	}
}