<commit_before>/*
 * #%L
 * elk-reasoner
 * 
 * $Id$
 * $HeadURL$
 * %%
 * Copyright (C) 2011 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.properties;

import java.io.IOException;
import java.io.Writer;
import java.util.Collections;
import java.util.Set;

import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedBinaryPropertyChain;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedObjectProperty;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedPropertyChain;
import org.semanticweb.elk.reasoner.indexing.visitors.IndexedPropertyChainVisitor;
import org.semanticweb.elk.reasoner.saturation.conclusions.BackwardLink;
import org.semanticweb.elk.reasoner.saturation.conclusions.ForwardLink;
import org.semanticweb.elk.util.collections.AbstractHashMultimap;
import org.semanticweb.elk.util.collections.Multimap;
import org.semanticweb.elk.util.collections.Operations;

/**
 * 
 * This object is used for fast retrieval of property inclusions and
 * compositions which are needed during saturation of class expressions.
 * 
 * @author <NAME>
 * @author "<NAME>"
 * 
 */
public class SaturatedPropertyChain {

	/**
	 * If set to true, then binary property chains that do not occur on the
	 * right of another chain are skipped in the derivation and replaced
	 * directly by all their told super-properties. For example, given an
	 * inclusion SubObjectPropertyOf(ObjectPropertyChain(R1 R2) R), the
	 * composition of R1 and R2 derives directly R skipping the auxiliary binary
	 * chain representing [R1 R2].
	 */
	public static final boolean REPLACE_CHAINS_BY_TOLD_SUPER_PROPERTIES = true;

	/**
	 * If set to true, then compositions between each pair of R1 and R2 are
	 * reduced under role hierarchies. For example, given
	 * 
	 * SubObjectPropertyOf(ObjectPropertyChain(R1 R2) S1),
	 * SubObjectPropertyOf(ObjectPropertyChain(R1 R2) S2), and
	 * SubObjectPropertyOf(S1 S2),
	 * 
	 * the composition of R1 and R2 derives only S1 and not S2. Note that this
	 * only makes sense if REPLACE_CHAINS_BY_TOLD_SUPER_PROPERTIES is also on.
	 */
	public static final boolean ELIMINATE_IMPLIED_COMPOSITIONS = true;

	/**
	 * the {@code IndexedPropertyChain} for which this saturation is computed
	 */
	final IndexedPropertyChain root;

	/**
	 * {@code true} if {@link #root} is derived reflexive
	 */
	private volatile boolean isDerivedReflexive_ = false;

	/**
	 * the {@code IndexedPropertyChain}s which are subsumed by {@link #root}
	 */
	Set<IndexedPropertyChain> derivedSubProperties;

	/**
	 * A {@link Multimap} from R to S such that ObjectPropertyChain(R, root)
	 * implies S
	 */
	AbstractHashMultimap<IndexedPropertyChain, IndexedPropertyChain> compositionsByLeftSubProperty;

	/**
	 * A {@link Multimap} from R to S such that ObjectPropertyChain(root, R)
	 * implies S
	 */
	AbstractHashMultimap<IndexedPropertyChain, IndexedPropertyChain> compositionsByRightSubProperty;

	public SaturatedPropertyChain(IndexedPropertyChain ipc) {
		this.root = ipc;
	}

	/**
	 * Clear all derived information for this {@link SaturatedPropertyChain}
	 */
	public void clear() {
		isDerivedReflexive_ = false;
		derivedSubProperties = null;
		compositionsByLeftSubProperty = null;
		compositionsByRightSubProperty = null;
	}

	/**
	 * @return {@code true} if there is no derived information in this
	 *         {@link SaturatedPropertyChain}, that is, its state is the same as
	 *         after applying {{@link #clear()}
	 */
	public boolean isClear() {
		return isDerivedReflexive_ == false && derivedSubProperties == null
				&& compositionsByLeftSubProperty == null
				&& compositionsByRightSubProperty == null;
	}

	public SaturatedPropertyChain clone() {
		SaturatedPropertyChain result = new SaturatedPropertyChain(root);
		result.isDerivedReflexive_ = this.isDerivedReflexive_;
		result.derivedSubProperties = this.derivedSubProperties;
		result.compositionsByLeftSubProperty = this.compositionsByLeftSubProperty;
		result.compositionsByRightSubProperty = this.compositionsByRightSubProperty;
		return result;<commit_msg>add missing @Override<commit_after>/*
 * #%L
 * elk-reasoner
 * 
 * $Id$
 * $HeadURL$
 * %%
 * Copyright (C) 2011 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.properties;

import java.io.IOException;
import java.io.Writer;
import java.util.Collections;
import java.util.Set;

import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedBinaryPropertyChain;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedObjectProperty;
import org.semanticweb.elk.reasoner.indexing.hierarchy.IndexedPropertyChain;
import org.semanticweb.elk.reasoner.indexing.visitors.IndexedPropertyChainVisitor;
import org.semanticweb.elk.reasoner.saturation.conclusions.BackwardLink;
import org.semanticweb.elk.reasoner.saturation.conclusions.ForwardLink;
import org.semanticweb.elk.util.collections.AbstractHashMultimap;
import org.semanticweb.elk.util.collections.Multimap;
import org.semanticweb.elk.util.collections.Operations;

/**
 * 
 * This object is used for fast retrieval of property inclusions and
 * compositions which are needed during saturation of class expressions.
 * 
 * @author <NAME>
 * @author "<NAME>"
 * 
 */
public class SaturatedPropertyChain {

	/**
	 * If set to true, then binary property chains that do not occur on the
	 * right of another chain are skipped in the derivation and replaced
	 * directly by all their told super-properties. For example, given an
	 * inclusion SubObjectPropertyOf(ObjectPropertyChain(R1 R2) R), the
	 * composition of R1 and R2 derives directly R skipping the auxiliary binary
	 * chain representing [R1 R2].
	 */
	public static final boolean REPLACE_CHAINS_BY_TOLD_SUPER_PROPERTIES = true;

	/**
	 * If set to true, then compositions between each pair of R1 and R2 are
	 * reduced under role hierarchies. For example, given
	 * 
	 * SubObjectPropertyOf(ObjectPropertyChain(R1 R2) S1),
	 * SubObjectPropertyOf(ObjectPropertyChain(R1 R2) S2), and
	 * SubObjectPropertyOf(S1 S2),
	 * 
	 * the composition of R1 and R2 derives only S1 and not S2. Note that this
	 * only makes sense if REPLACE_CHAINS_BY_TOLD_SUPER_PROPERTIES is also on.
	 */
	public static final boolean ELIMINATE_IMPLIED_COMPOSITIONS = true;

	/**
	 * the {@code IndexedPropertyChain} for which this saturation is computed
	 */
	final IndexedPropertyChain root;

	/**
	 * {@code true} if {@link #root} is derived reflexive
	 */
	private volatile boolean isDerivedReflexive_ = false;

	/**
	 * the {@code IndexedPropertyChain}s which are subsumed by {@link #root}
	 */
	Set<IndexedPropertyChain> derivedSubProperties;

	/**
	 * A {@link Multimap} from R to S such that ObjectPropertyChain(R, root)
	 * implies S
	 */
	AbstractHashMultimap<IndexedPropertyChain, IndexedPropertyChain> compositionsByLeftSubProperty;

	/**
	 * A {@link Multimap} from R to S such that ObjectPropertyChain(root, R)
	 * implies S
	 */
	AbstractHashMultimap<IndexedPropertyChain, IndexedPropertyChain> compositionsByRightSubProperty;

	public SaturatedPropertyChain(IndexedPropertyChain ipc) {
		this.root = ipc;
	}

	/**
	 * Clear all derived information for this {@link SaturatedPropertyChain}
	 */
	public void clear() {
		isDerivedReflexive_ = false;
		derivedSubProperties = null;
		compositionsByLeftSubProperty = null;
		compositionsByRightSubProperty = null;
	}

	/**
	 * @return {@code true} if there is no derived information in this
	 *         {@link SaturatedPropertyChain}, that is, its state is the same as
	 *         after applying {{@link #clear()}
	 */
	public boolean isClear() {
		return isDerivedReflexive_ == false && derivedSubProperties == null
				&& compositionsByLeftSubProperty == null
				&& compositionsByRightSubProperty == null;
	}

	@Override
	public SaturatedPropertyChain clone() {
		SaturatedPropertyChain result = new SaturatedPropertyChain(root);
		result.isDerivedReflexive_ = this.isDerivedReflexive_;
		result.derivedSubProperties = this.derivedSubProperties;
		result.compositionsByLeftSubProperty = this.compositionsByLeftSubProperty;
		result.compositionsByRightSubProperty = this.compositionsByRightSubProperty;
		return result;
{'fraction_non_alphanumeric': 0.0847294845800875, 'fraction_numerical': 0.005975883043431864, 'mean_word_length': 4.615338526063511, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3115855', 'n_tokens_mistral': 2894, 'n_tokens_neox': 2654, 'n_words': 834}