final ATermAppl s = arguments.get( 0 );
final ATermAppl p = arguments.get( 1 );
final ATermAppl o = arguments.get( 2 );
if( ATermUtils.isVar( p ) ) {
throw new UnsupportedQueryException(
"NegativePropertyValue atom with a variable property not supported" );
}
if( ATermUtils.isVar( o ) && kb.isDatatypeProperty( p ) ) {
throw new UnsupportedQueryException(
"NegativePropertyValue atom with a datatype property and variable object not supported" );
}
if( ATermUtils.isVar( s ) ) {
Set<ATermAppl> oValues = ATermUtils.isVar( o )
? kb.getIndividuals()
: Collections.singleton( o );
for( ATermAppl oValue : oValues ) {
Set<ATermAppl> sValues = kb.getInstances( not( hasValue( p, oValue ) ) );
for( ATermAppl sValue : sValues ) {
runNext( binding, arguments, sValue, p, oValue );
}
}
}
else if( ATermUtils.isVar( o ) ) {
Set<ATermAppl> oValues = kb.getInstances( not( hasValue( inv( p ), o ) ) );
for( ATermAppl oValue : oValues ) {
runNext( binding, arguments, s, p, oValue );
}
}
else {
if( kb.isType( s, hasValue( p, o ) ) ) {
exec( binding );
}
}
break;
}
case NotKnown: {
Query newQuery = new QueryImpl( kb, true );
for( QueryAtom atom : ((NotKnownQueryAtom) current).getAtoms() ) {
newQuery.add( atom.apply( binding ) );
}
for( ATermAppl var : newQuery.getUndistVars() ) {
newQuery.addDistVar( var, VarType.INDIVIDUAL );
}
QueryExec newEngine = new CombinedQueryEngine();
boolean isNegationTrue = newEngine.exec( newQuery ).isEmpty();
if( isNegationTrue ) {
exec( binding );
}
break;
}
case Union: {
for( List<QueryAtom> atoms : ((UnionQueryAtom) current).getUnion() ) {
Query newQuery = new QueryImpl( kb, true );
for( QueryAtom atom : atoms ) {
newQuery.add( atom.apply( binding ) );
}
for( ATermAppl var : newQuery.getUndistVars() ) {
newQuery.addDistVar( var, VarType.INDIVIDUAL );
newQuery.addResultVar( var );
}
QueryExec newEngine = new CombinedQueryEngine();
QueryResult newResult = newEngine.exec( newQuery );
for( ResultBinding newBinding : newResult ) {
newBinding.setValues( binding );
exec( newBinding );
}
}
break;
}
case Datatype:
throw new UnsupportedQueryException( "Datatype atom not ground: "
+ current );
case propertyDisjointWith:
final ATermAppl dwLHSp = arguments.get( 0 );
final ATermAppl dwRHSp = arguments.get( 1 );
if( !dwLHSp.equals( dwRHSp ) ) {
// TODO optimizeTBox
for( final ATermAppl known : getSymmetricCandidates( VarType.PROPERTY, dwLHSp,
dwRHSp ) ) {
for( final Set<ATermAppl> dependents : kb.getDisjointProperties( known ) ) {
for( final ATermAppl dependent : dependents ) {
runSymetricCheck( current, dwLHSp, known, dwRHSp, dependent, binding );
}
}
}
}
else {
log.finer( "Atom " + current
+ "cannot be satisfied in any consistent ontology." );
}
break;
default:
throw new UnsupportedQueryException( "Unknown atom type '"
+ current.getPredicate() + "'." );
}
}