bool Select(Entity[] subjects, Entity[] predicates, Resource[] objects, Entity[] metas, LiteralFilter[] litFilters, int limit, StatementSink sink, bool ask) { // TODO: Change meta into named graphs. Anything but a null or DefaultMeta // meta returns no statements immediately. if (metas != null && (metas.Length != 1 || metas[0] != Statement.DefaultMeta)) return false; string query; bool nonull = false; if (subjects != null && subjects.Length == 1 && predicates != null && predicates.Length == 1 && objects != null && objects.Length == 1) { query = "ASK WHERE { " + S(subjects[0], null) + " " + S(predicates[0], null) + " " + S(objects[0], null) + "}"; nonull = true; } else { if (ask) query = "ASK { "; else query = "SELECT * WHERE { "; query += S(subjects, "?subject"); query += " "; query += S(predicates, "?predicate"); query += " "; query += S(objects, "?object"); query += " . "; query += SL(subjects, "?subject", false); query += SL(predicates, "?predicate", false); query += SL(objects, "?object", false); query += " }"; // TODO: Pass literal filters to server. } if (limit >= 1) query += " LIMIT " + limit; Statement d = new Statement( (subjects != null && subjects.Length == 1) ? subjects[0] : null, (predicates != null && predicates.Length == 1) ? predicates[0] : null, (objects != null && objects.Length == 1) ? objects[0] : null); if (ask || nonull) { BooleanWrap bw = new BooleanWrap(); Load(query, bw); if (ask) return bw.value; else if (bw.value) sink.Add(new Statement(subjects[0], predicates[0], objects[0])); return false; } else { Load(query, new QueryToStatements(sink, litFilters, d)); return true; } }
public void Select(SelectFilter filter, StatementSink result) { ResSet s = filter.Subjects == null ? null : new ResSet(filter.Subjects), p = filter.Predicates == null ? null : new ResSet(filter.Predicates), o = filter.Objects == null ? null : new ResSet(filter.Objects), m = filter.Metas == null ? null : new ResSet(filter.Metas); foreach (Statement st in statements) { if (s != null && !s.Contains(st.Subject)) { continue; } if (p != null && !p.Contains(st.Predicate)) { continue; } if (o != null && !o.Contains(st.Object)) { continue; } if (m != null && !m.Contains(st.Meta)) { continue; } if (filter.LiteralFilters != null && !LiteralFilter.MatchesFilters(st.Object, filter.LiteralFilters, this)) { continue; } if (!result.Add(st)) { return; } } }
private static bool MatchesFilters(Literal literal, LiteralFilter[] filters, SelectableSource targetModel) { foreach (LiteralFilter filter in filters) if (!filter.Filter(literal, targetModel)) return false; return true; }
public static bool MatchesFilters(Resource literal, LiteralFilter[] filters, SelectableSource targetModel) { if (literal is Literal) return MatchesFilters((Literal)literal, filters, targetModel); return false; }
public QueryToStatements(StatementSink sink, LiteralFilter[] litFilters, Statement d) { this.sink = sink; this.litFilters = litFilters; this.d = d; }
public void AddValueFilter(Entity entity, LiteralFilter filter) { SetupValueFilter d = new SetupValueFilter(); d.a = entity; d.b = filter; setupValueFilters.Add(d); }