Search in sources :

Example 1 with ResourceStatementResults

use of com.inova8.intelligentgraph.results.ResourceStatementResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Thing method getFacts.

/**
 * Gets the facts.
 *
 * @param predicatePattern the predicate pattern
 * @param customQueryOptions the custom query options
 * @return the facts
 */
public ResourceResults getFacts(String predicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getFacts{}\n", predicatePattern);
    this.getEvaluationContext().getTracer().traceFacts(this, predicatePattern);
    SimpleDataset dataset = IntelligentGraphRepository.getDataset(customQueryOptions);
    dataset.addDefaultGraph(this.graphName);
    org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
    ResourceStatementResults results = null;
    IRI predicate = IntelligentGraphRepository.preparePredicate(PATHQL.getFacts, predicatePattern);
    if (this.getSource().getRepository() == null) {
        CloseableIteration<? extends Statement, QueryEvaluationException> localStatementIterator = this.getSource().getTripleSource().getStatements(this.getIRI(), predicate, null, contextArray);
        results = new ResourceStatementResults(localStatementIterator, this, null, customQueryOptions);
    } else {
        CloseableIteration<Statement, RepositoryException> statementIterator = this.getSource().getRepository().getConnection().getStatements(this.getIRI(), predicate, null, contextArray);
        results = new ResourceStatementResults(statementIterator, this, null, customQueryOptions);
    }
    return results;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Statement(org.eclipse.rdf4j.model.Statement) ResourceStatementResults(com.inova8.intelligentgraph.results.ResourceStatementResults) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException)

Example 2 with ResourceStatementResults

use of com.inova8.intelligentgraph.results.ResourceStatementResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Thing method traceFact.

/**
 * Trace fact.
 *
 * @param predicatePattern the predicate pattern
 * @param customQueryOptions the custom query options
 * @return the trace
 */
public Trace traceFact(String predicatePattern, CustomQueryOptions customQueryOptions) {
    SimpleDataset dataset = IntelligentGraphRepository.getDataset(customQueryOptions);
    dataset.addDefaultGraph(this.graphName);
    org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
    ResourceStatementResults results = null;
    IRI predicate = IntelligentGraphRepository.preparePredicate(PATHQL.traceFacts, predicatePattern);
    CloseableIteration<Statement, RepositoryException> statementIterator = this.getSource().getRepository().getConnection().getStatements(this.getIRI(), predicate, null, contextArray);
    results = new ResourceStatementResults(statementIterator, this, null, customQueryOptions);
    for (Resource result : results) {
        String resultString = result.stringValue();
        results.close();
        return new Trace(resultString);
    }
    results.close();
    return new Trace("results");
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Statement(org.eclipse.rdf4j.model.Statement) ResourceStatementResults(com.inova8.intelligentgraph.results.ResourceStatementResults) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) Trace(com.inova8.intelligentgraph.evaluator.Trace)

Example 3 with ResourceStatementResults

use of com.inova8.intelligentgraph.results.ResourceStatementResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphRepository method getFacts.

public ResourceResults getFacts(String boundPredicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getFacts{}\n", boundPredicatePattern);
    // this.getEvaluationContext().getTracer().traceFacts(this, queryPattern);
    SimpleDataset dataset = getDataset(customQueryOptions);
    // dataset.addDefaultGraph(this.graphName);
    org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
    ResourceStatementResults results = null;
    IRI predicate = preparePredicate(PATHQL.getFacts, boundPredicatePattern);
    if (this.getRepository() == null) {
        CloseableIteration<? extends Statement, QueryEvaluationException> localStatementIterator = this.getTripleSource().getStatements(null, predicate, null);
        results = new ResourceStatementResults(localStatementIterator, this, null, customQueryOptions);
    } else {
        CloseableIteration<Statement, RepositoryException> statementIterator = this.getRepository().getConnection().getStatements(null, predicate, null, contextArray);
        results = new ResourceStatementResults(statementIterator, this, null, customQueryOptions);
    }
    return results;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource) ResourceStatementResults(com.inova8.intelligentgraph.results.ResourceStatementResults) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException)

Aggregations

ResourceStatementResults (com.inova8.intelligentgraph.results.ResourceStatementResults)3 IRI (org.eclipse.rdf4j.model.IRI)3 Statement (org.eclipse.rdf4j.model.Statement)3 SimpleDataset (org.eclipse.rdf4j.query.impl.SimpleDataset)3 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)3 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)2 Trace (com.inova8.intelligentgraph.evaluator.Trace)1 Resource (org.eclipse.rdf4j.model.Resource)1