ASK query returning weird result

Hi I am using the stardog java client to perform an ask query. My code is as follows

public boolean ask(String sparql, Map<String, Object> args) {
    Connection connection = dataSource.getConnection();
    Boolean result = null;
    try {
        BooleanQuery query = connection.ask(sparql);

        if (args != null) {
            for (Map.Entry<String, Object> arg : args.entrySet()) {
                query.parameter(arg.getKey(), arg.getValue());
            }
        }

        result = query.execute();
    } catch (StardogException e) {
        log.error("Error sending query to Stardog", e);
        throw new RuntimeException(e);
    } finally {
        dataSource.releaseConnection(connection);
    }
    return result;
}

The sparql parameter is : ASK {http://www.things.com/something/resources#unknownforsure ?p ?o}

when I run the query in stardog webconsole it returns FALSE as expected. But when I run the same query using client method : BooleanQuery ask(String var1) throws StardogException; It returns true.

Could this be a bug in

com.complexible.stardog
client-http
5.2.2
pom

Regards,

What sort of object is dataSource? Does it work if you use com.complexible.stardog.api.ConnectionConfiguration to retrieve your Connection object?

Hi thx for your response.
My datasource object is a wrapper for ConnectionConfiguration (see below)
import com.complexible.stardog.StardogException;
import com.complexible.stardog.api.Connection;
import com.complexible.stardog.api.ConnectionConfiguration;
import com.complexible.stardog.api.ConnectionPool;
import com.complexible.stardog.api.ConnectionPoolConfig;

public class DataSource {
final Logger log = LoggerFactory.getLogger(DataSource.class);

private ConnectionPool pool;

private ConnectionConfiguration connectionConfig;

private ConnectionPoolConfig poolConfig;

public DataSource() { }

public DataSource(ConnectionConfiguration configuration) {
    connectionConfig = configuration;
    poolConfig = ConnectionPoolConfig.using(configuration);
}

public DataSource(ConnectionConfiguration configuration, ConnectionPoolConfig poolConfiguration) {
    connectionConfig = configuration;
    poolConfig = poolConfiguration;
}

public void afterPropertiesSet() {
    log.debug("Creating Stardog connection pool");
    pool = poolConfig.create();
}

/**
 * <code>getConnection</code>
 * Similar to javax.sql.DataSource
 *
 * Also serves as a place to weave in Spring transaction support
 *
 * @return Stardog Connection
 */
public Connection getConnection() {
    try {
        if (pool == null)
            afterPropertiesSet();
        return pool.obtain();
    } catch (StardogException e) {
        log.error("Error obtaining connection from Stardog pool", e);
        throw new RuntimeException(e);
    }
}

/**
 * <code>releaseConnection</code>
 * @param connection Stardog Connection
 */
public void releaseConnection(Connection connection) {
    try {
        if (pool == null)
            afterPropertiesSet();
        pool.release(connection);
    } catch (StardogException e) {
        log.error("Error releasing connection from Stardog pool", e);
        throw new RuntimeException(e);
    }
}


/**
 * <code>destroy</code>
 * Called by Spring
 */
public void destroy() {
    try {
        if (pool == null)
            afterPropertiesSet();
        pool.shutdown();
    } catch (StardogException e) {
        log.error("Error shutting down Stardog pool", e);
    }
    poolConfig = null;
    connectionConfig = null;
    pool = null;
}

}

Can you share your ConnectionConfiguration / ConnectionPoolConfig? I am unable to reproduce this issue with 5.2.2, running the same commands in a main

1 Like

Hi Stephen,
I added a screenshot of my connection and poolconfig.

To give some more info:
when I do following queries with my setup:
ASK{?s someknownpredicate ?o } returns true
ASK{?s someunknownpredicate ?o } returns false

it is only when I do
in code:
ASK{someknownsubject ?p ?o } returns true
ASK{someunknownsubject ?p ?o } returns true

but in stardog webconsole:
ASK{someknownsubject ?p ?o } returns true
ASK{someunknownsubject ?p ?o } returns false

Regards,

Hi Stephen, I am answering my own question but I found that the reasoning parameter was causing the issue.
Although I am not sure why this would be a factor in this specific query.
Would you have an idea why this is the case.

Regards,

This happens because, as can be seen by running a SELECT * {someunknownsubject ?p ?o} query, enabling reasoning causes a [:X rdf:type owl:Thing] triple to be inferred for any given subject, causing your very general ASK to return true.

To get around this, you can either disable reasoning or add a filter to your ask: ASK {someunknownsubject ?p ?o . FILTER (?p != rdf:type)}

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.