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

org.semanticweb.elk.reasoner.saturation.rules.subsumers.ContradictionFromOwlNothingRule Maven / Gradle / Ivy

package org.semanticweb.elk.reasoner.saturation.rules.subsumers;

/*
 * #%L
 * ELK Reasoner
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2011 - 2016 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 org.semanticweb.elk.owl.predefined.PredefinedElkIris;
import org.semanticweb.elk.reasoner.indexing.model.IndexedClass;
import org.semanticweb.elk.reasoner.indexing.model.IndexedClassExpression;
import org.semanticweb.elk.reasoner.indexing.model.ModifiableIndexedClass;
import org.semanticweb.elk.reasoner.indexing.model.ModifiableOntologyIndex;
import org.semanticweb.elk.reasoner.saturation.conclusions.model.ClassInconsistency;
import org.semanticweb.elk.reasoner.saturation.context.ContextPremises;
import org.semanticweb.elk.reasoner.saturation.inferences.ClassInconsistencyOfOwlNothing;
import org.semanticweb.elk.reasoner.saturation.rules.ClassInferenceProducer;
import org.semanticweb.elk.util.collections.chains.Chain;
import org.semanticweb.elk.util.collections.chains.Matcher;
import org.semanticweb.elk.util.collections.chains.ReferenceFactory;
import org.semanticweb.elk.util.collections.chains.SimpleTypeBasedMatcher;

/**
 * A {@link ChainableSubsumerRule} producing {@link ClassInconsistency} when
 * processing an {@link IndexedClassExpression} that corresponds to
 * {@code owl:Nothing}.
 * 
 * @author "Yevgeny Kazakov"
 */
public class ContradictionFromOwlNothingRule extends
		AbstractChainableSubsumerRule {

	// TODO: move to a decomposition rule
	
	public static final String NAME = "Owl:Nothing Contradiction Introduction";

	private ContradictionFromOwlNothingRule(ChainableSubsumerRule tail) {
		super(tail);
	}

	private ContradictionFromOwlNothingRule() {
		this((ChainableSubsumerRule) null);
	}

	private static void checkOwlNothing(IndexedClass candidate) {
		if (!candidate.getElkEntity().getIri().equals(PredefinedElkIris.OWL_NOTHING)) {		
			throw new IllegalArgumentException(
					"The rule can be registered only for owl:Nothing and not for " + candidate);
		}	
	}

	public static boolean addRuleFor(ModifiableIndexedClass owlNothing,
			ModifiableOntologyIndex index) {
		checkOwlNothing(owlNothing);
		return index.add(owlNothing, new ContradictionFromOwlNothingRule());
	}

	public static boolean removeRuleFor(ModifiableIndexedClass owlNothing,
			ModifiableOntologyIndex index) {
		checkOwlNothing(owlNothing);
		return index.remove(owlNothing, new ContradictionFromOwlNothingRule());
	}

	@Override
	public String toString() {
		return NAME;
	}

	@Override
	public void apply(IndexedClassExpression premise, ContextPremises premises,
			ClassInferenceProducer producer) {
		producer.produce(new ClassInconsistencyOfOwlNothing(premises.getRoot(),
				(IndexedClass) premise));
	}

	@Override
	public boolean isTracingRule() {
		return true;
	}

	@Override
	public boolean addTo(Chain ruleChain) {
		ContradictionFromOwlNothingRule rule = ruleChain.find(MATCHER_);
		if (rule != null) {
			// the rule is already registered
			return false;
		}
		// else will create and add to the chain
		ruleChain.getCreate(MATCHER_, FACTORY_);
		return true;
	}

	@Override
	public boolean removeFrom(Chain ruleChain) {
		ContradictionFromOwlNothingRule previous = ruleChain.remove(MATCHER_);
		if (previous == null) {
			// the rule was not registered
			return false;
		}
		// else
		return true;
	}

	@Override
	public void accept(LinkedSubsumerRuleVisitor visitor,
			IndexedClassExpression premise, ContextPremises premises,
			ClassInferenceProducer producer) {
		visitor.visit(this, premise, premises, producer);
	}

	private static Matcher MATCHER_ = new SimpleTypeBasedMatcher(
			ContradictionFromOwlNothingRule.class);

	private static ReferenceFactory FACTORY_ = new ReferenceFactory() {
		@Override
		public ContradictionFromOwlNothingRule create(ChainableSubsumerRule tail) {
			return new ContradictionFromOwlNothingRule(tail);
		}
	};

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy