public string CreateQuery(ISparqlQuery query) { StringBuilder queryBuilder = new StringBuilder(); // Add Virtuoso specific describe mode for Describe queries. if (query.QueryType == SparqlQueryType.Describe) { // http://docs.openlinksw.com/virtuoso/rdfsparql.html: sql:describe-mode "SPO". // This pair of procedures searches for all triples where the input IRIs are used // as subjects; they are faster than the default routine which searches for all // triples where the input IRIs are used as subjects or objects. queryBuilder.Append("DEFINE sql:describe-mode \"SPO\" \n"); } // Add Virtuoso specific inferencing DEFINEs. // The models which can be used for inferencing is Virtuoso specific and // are therefore added here in the store. if (query.IsInferenceEnabled) { if (string.IsNullOrEmpty(_defaultInferenceRule)) { throw new Exception("You tried to query with inferencing but the inference rule is empty or not set."); } queryBuilder.Append("DEFINE input:inference '" + _defaultInferenceRule + "' \n"); } queryBuilder.Append(query.ToString()); return(string.Format("SPARQL {0}", queryBuilder)); }
public ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction transaction = null) { string q = query.ToString(); Log?.Invoke(q); SparqlQueryParser p = new SparqlQueryParser(); var x = p.ParseFromString(q); x.ClearNamedGraphs(); x.ClearDefaultGraphs(); SparqlEndpointQueryResult result = null; if (query.QueryType == SparqlQueryType.Describe || query.QueryType == SparqlQueryType.Construct) { var r = _endpoint.QueryWithResultGraph(x.ToString()); result = new SparqlEndpointQueryResult(r, query); } else { var r = _endpoint.QueryWithResultSet(x.ToString()); result = new SparqlEndpointQueryResult(r, query); } return(result); }
/// <summary> /// Executes a SparqlQuery on the store. /// </summary> /// <param name="query"></param> /// <param name="transaction"></param> /// <returns></returns> public override ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction transaction = null) { if (query.IsInferenceEnabled && _reasoner != null) { _store.AddInferenceEngine(_reasoner); } else { _store.ClearInferenceEngines(); } string q = query.ToString(); object results = ExecuteQuery(q); if (results is IGraph) { return(new dotNetRDFQueryResult(this, query, results as IGraph)); } else if (results is SparqlResultSet) { return(new dotNetRDFQueryResult(this, query, results as SparqlResultSet)); } return(null); }
/// <summary> /// Executes a <c>SparqlQuery</c> on the store. /// </summary> /// <param name="query">SPARQL query to be executed.</param> /// <param name="transaction">An optional transaction.</param> /// <returns></returns> public override ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction transaction = null) { string q = query.ToString(); Log?.Invoke(q); StardogResultHandler resultHandler = new StardogResultHandler(); _connector.Query(_rdfHandler, resultHandler, q, query.IsInferenceEnabled); return(new StardogQueryResult(this, query, resultHandler)); }