org.semanticweb.elk.reasoner.indexing.classes.StructuralIndexedObjectPropertyEntryImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elk-reasoner Show documentation
Show all versions of elk-reasoner Show documentation
The core ELK Reasoner package
/*
* #%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.indexing.classes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.semanticweb.elk.owl.interfaces.ElkAxiom;
import org.semanticweb.elk.owl.interfaces.ElkObjectProperty;
import org.semanticweb.elk.reasoner.indexing.model.IndexedClassExpression;
import org.semanticweb.elk.reasoner.indexing.model.IndexedComplexPropertyChain;
import org.semanticweb.elk.reasoner.indexing.model.IndexedEntity;
import org.semanticweb.elk.reasoner.indexing.model.IndexedPropertyChain;
import org.semanticweb.elk.reasoner.indexing.model.StructuralIndexedObjectPropertyEntry;
import org.semanticweb.elk.reasoner.indexing.model.StructuralIndexedSubObject;
import org.semanticweb.elk.util.hashing.HashGenerator;
/**
* Implements {@link StructuralIndexedObjectPropertyEntry}
*
* @author "Yevgeny Kazakov"
*
*/
class StructuralIndexedObjectPropertyEntryImpl extends
ModifiableIndexedPropertyChainImpl>
implements
StructuralIndexedObjectPropertyEntry {
private final ElkObjectProperty elkEntity_;
/**
* Collections of all binary role chains in which this
* {@link IndexedPropertyChain} occurs on the left.
*/
private Collection leftChains_;
/**
* The {@link IndexedPropertyChain} that are subsumed by this
* {@link IndexedComplexPropertyChain} according to axioms
*/
private ArrayList toldSubChains_;
/**
* The corresponding {@link ElkAxiom}s that resulted for the sub property
* chains
*/
private ArrayList toldSubChainsReasons_;
/**
* The {@link IndexedClassExpression} from range axioms with this property
*/
private ArrayList toldRanges_;
/**
* The corresponding {@link ElkAxiom}s that resulted for the ranges
*/
private ArrayList toldRangesReasons_;
StructuralIndexedObjectPropertyEntryImpl(ElkObjectProperty elkEntity) {
super(structuralHashCode(elkEntity));
this.elkEntity_ = elkEntity;
}
@Override
public final ElkObjectProperty getElkEntity() {
return elkEntity_;
}
@Override
public final ArrayList getToldSubChains() {
if (toldSubChains_ == null)
return emptyArrayList();
// else
return toldSubChains_;
}
@Override
public final ArrayList getToldSubChainsReasons() {
if (toldSubChainsReasons_ == null)
return emptyArrayList();
// else
return toldSubChainsReasons_;
}
@Override
public final ArrayList getToldRanges() {
if (toldRanges_ == null)
return emptyArrayList();
// else
return toldRanges_;
}
@Override
public final ArrayList getToldRangesReasons() {
if (toldRangesReasons_ == null)
return emptyArrayList();
// else
return toldRangesReasons_;
}
@Override
public final Collection getLeftChains() {
if (leftChains_ == null)
return Collections.emptySet();
// else
return Collections.unmodifiableCollection(leftChains_);
}
@Override
public final boolean addLeftChain(IndexedComplexPropertyChain chain) {
if (leftChains_ == null)
leftChains_ = new ArrayList(1);
return leftChains_.add(chain);
}
@Override
public final boolean removeLeftChain(IndexedComplexPropertyChain chain) {
boolean success = false;
if (leftChains_ != null) {
success = leftChains_.remove(chain);
if (leftChains_.isEmpty())
leftChains_ = null;
}
return success;
}
@Override
public final boolean addToldSubPropertyChain(IndexedPropertyChain subChain,
ElkAxiom reason) {
if (toldSubChains_ == null) {
toldSubChains_ = new ArrayList(1);
}
if (toldSubChainsReasons_ == null) {
toldSubChainsReasons_ = new ArrayList(1);
}
toldSubChains_.add(subChain);
toldSubChainsReasons_.add(reason);
return true;
}
@Override
public final boolean removeToldSubPropertyChain(
IndexedPropertyChain subChain, ElkAxiom reason) {
int i = indexOf(subChain, reason);
if (i < 0)
return false;
// else success
toldSubChains_.remove(i);
toldSubChainsReasons_.remove(i);
if (toldSubChains_.isEmpty())
toldSubChains_ = null;
if (toldSubChainsReasons_.isEmpty())
toldSubChainsReasons_ = null;
return true;
}
@Override
public final boolean addToldRange(IndexedClassExpression range,
ElkAxiom reason) {
if (toldRanges_ == null) {
toldRanges_ = new ArrayList(1);
}
if (toldRangesReasons_ == null) {
toldRangesReasons_ = new ArrayList(1);
}
toldRanges_.add(range);
toldRangesReasons_.add(reason);
return true;
}
@Override
public final boolean removeToldRange(IndexedClassExpression range,
ElkAxiom reason) {
int i = indexOf(range, reason);
if (i < 0)
return false;
// else success
toldRanges_.remove(i);
toldRangesReasons_.remove(i);
if (toldRanges_.isEmpty())
toldRanges_ = null;
if (toldRangesReasons_.isEmpty())
toldRangesReasons_ = null;
return true;
}
// TODO: create a generic method for this operation (used in other places)
private int indexOf(IndexedPropertyChain subChain, ElkAxiom reason) {
for (int i = 0; i < toldSubChains_.size(); i++) {
if (toldSubChains_.get(i).equals(subChain)
&& toldSubChainsReasons_.get(i).equals(reason))
return i;
}
// else not found
return -1;
}
private int indexOf(IndexedClassExpression range, ElkAxiom reason) {
for (int i = 0; i < toldRanges_.size(); i++) {
if (toldRanges_.get(i).equals(range)
&& toldRangesReasons_.get(i).equals(reason))
return i;
}
// else not found
return -1;
}
static int structuralHashCode(ElkObjectProperty elkEntity) {
return HashGenerator.combinedHashCode(
StructuralIndexedObjectPropertyEntryImpl.class, elkEntity.getIri());
}
@Override
public StructuralIndexedObjectPropertyEntryImpl structuralEquals(Object other) {
if (this == other) {
return this;
}
if (other instanceof StructuralIndexedObjectPropertyEntryImpl) {
StructuralIndexedObjectPropertyEntryImpl secondEntry = (StructuralIndexedObjectPropertyEntryImpl) other;
if (getElkEntity().getIri()
.equals(secondEntry.getElkEntity().getIri()))
return secondEntry;
}
// else
return null;
}
@Override
public final O accept(IndexedEntity.Visitor visitor) {
return visitor.visit(this);
}
@Override
public final O accept(IndexedPropertyChain.Visitor visitor) {
return visitor.visit(this);
}
@Override
public O accept(StructuralIndexedSubObject.Visitor visitor) {
return visitor.visit(this);
}
}