void WriteGraph(RdfGraph graph, RdfSourceWrapper sourcewrapper, StatementSink sink) { java.util.Iterator iter = graph.iterator(); while (iter.hasNext()) { GraphStatement stmt = (GraphStatement)iter.next(); Statement s; if (stmt is GraphStatementWrapper) { s = ((GraphStatementWrapper)stmt).s; } else { s = new Statement( sourcewrapper.ToEntity(stmt.getSubject()), sourcewrapper.ToEntity(stmt.getPredicate()), sourcewrapper.ToResource(stmt.getObject()), stmt.getGraphName() == null ? Statement.DefaultMeta : sourcewrapper.ToEntity(stmt.getGraphName())); } if (s.AnyNull) { continue; // unbound variable, or literal in bad position } sink.Add(s); } }
Resource ToRes(object expr, java.util.Map knownValues, bool entities, Hashtable varMap1, Hashtable varMap2, RdfSourceWrapper src, QueryOptions opts, VariableList distinguishedVars, VariableList undistinguishedVars, java.util.Set sparqlDistinguished) { if (expr is SparqlVariable) { Variable v; if (varMap1.ContainsKey(expr)) { v = (Variable)varMap1[expr]; } else { v = new Variable(expr.ToString()); varMap1[expr] = v; varMap2[v] = expr; if (knownValues != null && knownValues.get(expr) != null) { java.util.Set values = (java.util.Set)knownValues.get(expr); VarKnownValuesList values2 = new VarKnownValuesList(); for (java.util.Iterator iter = values.iterator(); iter.hasNext(); ) { Resource r = src.ToResource((name.levering.ryan.sparql.common.Value)iter.next()); if (r != null) values2.Add(r); } opts.VariableKnownValues[v] = values2; } if (sparqlDistinguished != null && sparqlDistinguished.contains(expr)) distinguishedVars.Add(v); else undistinguishedVars.Add(v); } return v; } return entities ? src.ToEntity((name.levering.ryan.sparql.common.Value)expr) : src.ToResource((name.levering.ryan.sparql.common.Value)expr); }
void WriteGraph(RdfGraph graph, RdfSourceWrapper sourcewrapper, StatementSink sink) { if (sink is RdfWriter) ((RdfWriter)sink).Namespaces.AddFrom(GetQueryPrefixes()); java.util.Iterator iter = graph.iterator(); while (iter.hasNext()) { GraphStatement stmt = (GraphStatement)iter.next(); Statement s; if (stmt is GraphStatementWrapper) { s = ((GraphStatementWrapper)stmt).s; } else { s = new Statement( sourcewrapper.ToEntity(stmt.getSubject()), sourcewrapper.ToEntity(stmt.getPredicate()), sourcewrapper.ToResource(stmt.getObject()), stmt.getGraphName() == null ? Statement.DefaultMeta : sourcewrapper.ToEntity(stmt.getGraphName())); } if (s.AnyNull) continue; // unbound variable, or literal in bad position sink.Add(s); } }
public override void Run(SelectableSource source, QueryResultSink resultsink) { if (!(query is SelectQuery)) throw new InvalidOperationException("Only SELECT queries are supported by this method (" + query.GetType() + ")."); // Perform the query SelectQuery squery = (SelectQuery)query; RdfSourceWrapper sourcewrapper = new RdfSourceWrapper(source, QueryMeta, this); MyLogicFactory logic = new MyLogicFactory(); foreach (RdfFunction f in extFunctions) logic.registerExternalFunction( new URIWrapper(f.Uri), new ExtFuncWrapper(sourcewrapper, f)); squery.bindLogic(logic); RdfBindingSet results; try { results = squery.execute(sourcewrapper); } catch (java.lang.Exception e) { throw new QueryExecutionException("Error executing query: " + e.Message, e); } // Prepare binding objects java.util.List vars = results.getVariables(); VariableBinding[] bindings = new VariableBinding[vars.size()]; SparqlVariable[] svars = new SparqlVariable[vars.size()]; SemWebVariable[] vars2 = new SemWebVariable[vars.size()]; for (int i = 0; i < bindings.Length; i++) { svars[i] = (SparqlVariable)vars.get(i); vars2[i] = new SemWebVariable(svars[i].getName()); bindings[i] = new VariableBinding(vars2[i], null); } // Initialize the result sink resultsink.Init(bindings, false, false); // set distinct and ordered // Set the comments resultsink.AddComments(queryString + "\n"); resultsink.AddComments(sourcewrapper.GetLog()); // Iterate the bindings java.util.Iterator iter = results.iterator(); long ctr = -1, ctr2 = 0; while (iter.hasNext()) { RdfBindingRow row = (RdfBindingRow)iter.next(); // Since SPARQL processing may be lazy-delayed, // add any new comments that might have been logged. resultsink.AddComments(sourcewrapper.GetLog()); ctr++; if (ctr < ReturnStart && ReturnStart != -1) continue; for (int i = 0; i < bindings.Length; i++) { Resource r = sourcewrapper.ToResource(row.getValue(svars[i])); r = sourcewrapper.Persist(r); bindings[i] = new VariableBinding(bindings[i].Variable, r); } resultsink.AddComments(sourcewrapper.GetLog()); resultsink.Add(bindings); ctr2++; if (ctr2 >= ReturnLimit && ReturnLimit != -1) break; } resultsink.AddComments(sourcewrapper.GetLog()); // Close the result sink. resultsink.Finished(); }
public override void Run(SelectableSource source, QueryResultSink resultsink) { if (!(query is SelectQuery)) { throw new InvalidOperationException("Only SELECT queries are supported by this method (" + query.GetType() + ")."); } // Perform the query SelectQuery squery = (SelectQuery)query; RdfSourceWrapper sourcewrapper = new RdfSourceWrapper(source, QueryMeta, this); MyLogicFactory logic = new MyLogicFactory(); foreach (RdfFunction f in extFunctions) { logic.registerExternalFunction( new URIWrapper(f.Uri), new ExtFuncWrapper(sourcewrapper, f)); } squery.bindLogic(logic); RdfBindingSet results; try { results = squery.execute(sourcewrapper); } catch (java.lang.Exception e) { throw new QueryExecutionException("Error executing query: " + e.Message, e); } // Prepare binding objects java.util.List vars = results.getVariables(); VariableBinding[] bindings = new VariableBinding[vars.size()]; SparqlVariable[] svars = new SparqlVariable[vars.size()]; SemWebVariable[] vars2 = new SemWebVariable[vars.size()]; for (int i = 0; i < bindings.Length; i++) { svars[i] = (SparqlVariable)vars.get(i); vars2[i] = new SemWebVariable(svars[i].getName()); bindings[i] = new VariableBinding(vars2[i], null); } // Initialize the result sink resultsink.Init(bindings, false, false); // set distinct and ordered // Set the comments resultsink.AddComments(queryString + "\n"); resultsink.AddComments(sourcewrapper.GetLog()); // Iterate the bindings java.util.Iterator iter = results.iterator(); long ctr = -1, ctr2 = 0; while (iter.hasNext()) { RdfBindingRow row = (RdfBindingRow)iter.next(); // Since SPARQL processing may be lazy-delayed, // add any new comments that might have been logged. resultsink.AddComments(sourcewrapper.GetLog()); ctr++; if (ctr < ReturnStart && ReturnStart != -1) { continue; } for (int i = 0; i < bindings.Length; i++) { Resource r = sourcewrapper.ToResource(row.getValue(svars[i])); r = sourcewrapper.Persist(r); bindings[i] = new VariableBinding(bindings[i].Variable, r); } resultsink.AddComments(sourcewrapper.GetLog()); resultsink.Add(bindings); ctr2++; if (ctr2 >= ReturnLimit && ReturnLimit != -1) { break; } } resultsink.AddComments(sourcewrapper.GetLog()); // Close the result sink. resultsink.Finished(); }