T apply(int max, T init, Function super T, ? extends T> fn) {
+ T result = init;
+
+ int i = 0;
+ for(; i < max; ++i) {
+ T tmp = fn.apply(result);
+ if(Objects.equals(tmp, result)) {
+ break;
+ }
+ result = tmp;
+ }
+
+ if(i >= max) {
+ logger.warn("Fixpoint iteration reached iteration threshold");
+ }
+
+ return result;
+ }
}
diff --git a/jena-sparql-api-algebra/src/main/java/org/aksw/jena_sparql_api/algebra/utils/VirtualPartitionedQuery.java b/jena-sparql-api-algebra/src/main/java/org/aksw/jena_sparql_api/algebra/utils/VirtualPartitionedQuery.java
index c8ce6190c..42215f52b 100644
--- a/jena-sparql-api-algebra/src/main/java/org/aksw/jena_sparql_api/algebra/utils/VirtualPartitionedQuery.java
+++ b/jena-sparql-api-algebra/src/main/java/org/aksw/jena_sparql_api/algebra/utils/VirtualPartitionedQuery.java
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +18,7 @@
import org.aksw.jena_sparql_api.concepts.RelationUtils;
import org.aksw.jena_sparql_api.concepts.TernaryRelation;
import org.aksw.jena_sparql_api.concepts.TernaryRelationImpl;
+import org.aksw.jena_sparql_api.concepts.UnaryRelation;
import org.aksw.jena_sparql_api.concepts.XExpr;
import org.aksw.jena_sparql_api.utils.ElementUtils;
import org.aksw.jena_sparql_api.utils.NodeTransformRenameMap;
@@ -46,7 +48,7 @@
//class Contrib {
// protected BinaryRelation reachingRelation;
// protected TernaryRelation graphRelation;
-//
+//
// public Contrib(BinaryRelation reachingRelation, TernaryRelation graphRelation) {
// super();
// this.reachingRelation = reachingRelation;
@@ -83,7 +85,7 @@
//class PathResolverSimple>
// implements PathResolver
//{
-//
+//
// @Override
// public P parent() {
// // TODO Auto-generated method stub
@@ -97,12 +99,12 @@
//
// @Override
// public BinaryRelation value() {
-//
-//
+//
+//
// // TODO Auto-generated method stub
// return null;
// }
-//
+//
//}
@@ -123,46 +125,46 @@
* In a virtual RDF graph, the naming of the variables are meaningless anyway,
* as the rewriting system on top just cares about subject, predicate and object positions
* but not how they are named.
- *
- *
+ *
+ *
* @author raven
*
*/
public class VirtualPartitionedQuery {
- private static final Logger logger = LoggerFactory.getLogger(VirtualPartitionedQuery.class);
-
+ private static final Logger logger = LoggerFactory.getLogger(VirtualPartitionedQuery.class);
+
//
// public static void rewrite(Collection views, Iterable> aliasedPath) {
// // Rewrite a path over a collection of partitioned query views
-//
-//
-//
+//
+//
+//
// //return null;
// }
-//
+//
// public void step(Collection views, P_Path0 step, String alias) {
// for(PartitionedQuery1 pq : views) {
-//
+//
// }
// }
//
-//
+//
// // Note: The code below may not work with literals in the template due to
// // jena not allowing literals to act as resources
// // but actually its a pointless limitation for our purposes
// public Resolver createResolver(PartitionedQuery1 pq, Iterable extends P_Path0> path) {
// Node rootNode = pq.getPartitionVar();
-//
+//
// Query query = pq.getQuery();
// Template template = query.getConstructTemplate();
// GraphVar graphVar = new GraphVarImpl(GraphFactory.createDefaultGraph());
// GraphUtil.add(graphVar, template.getTriples());
// Model model = ModelFactory.createModelForGraph(graphVar);
-//
+//
// Resource root = model.getRDFNode(rootNode).asResource();
// System.out.println(root.listProperties().toList());
//
-// Collection starts = Collections.singleton(root);
+// Collection starts = Collections.singleton(root);
// for(P_Path0 step : path) {
//// Property p = ResourceUtils.getProperty(step);
// List targets =
@@ -171,120 +173,167 @@ public class VirtualPartitionedQuery {
// .collect(Collectors.toList());
// starts = targets;
// }
-//
-//
+//
+//
// //Element basePattern = query.getQueryPattern();
//
// Set result = starts.stream().map(RDFNode::asNode).collect(Collectors.toSet());
// return result;
// }
-//
+//
//// public static Set resolve(PartitionedQuery1 pq, Collection startVars, P_Path0 step) {
-////
+////
//// }
-//
-//
+//
+//
// public static Set resolve() {
// //Relation baseRelation = RelationImpl.create(basePattern, PatternVars.vars(basePattern));
//
// //FacetedQueryGenerator.createRelationForPath(PathToRelationMapper mapper, PathAccessor
pathAccessor, P childPath, boolean includeAbsent) {
//
-//
+//
// List trs;
// for(RDFNode target : targets) {
// // Generate the triple pattern (target, p, o)
// Var var = (Var)target.asNode();
// System.out.println(var);
-//
+//
// BinaryRelation br =
// BinaryRelationImpl.create(var, Vars.p, Vars.o, isFwd)
// .joinOn(var).with(new Concept(basePattern, var))
// .toBinaryRelation();
-//
-// }
+//
+// }
// }
-//
-//
-
-
+//
+//
+
+
// public static Resolver createResolver(PartitionedQuery1 pq) {
// RDFNode node = toRdfModel(pq);
// Resolver result = new ResolverTemplate(pq, Collections.singleton(node));
// return result;
// }
-
-
+
+
// public void step(SimplePath basePath, PartitionedQuery1 pq, P_Path0 step, boolean isFwd, String alias) {
// System.out.println(root.listProperties().toList());
-//
+//
// Property p = ResourceUtils.getProperty(step);
// List targets = ResourceUtils.listPropertyValues(root, step).toList();
-//
+//
// Element basePattern = query.getQueryPattern();
// //Relation baseRelation = RelationImpl.create(basePattern, PatternVars.vars(basePattern));
//
// //FacetedQueryGenerator.createRelationForPath(PathToRelationMapper mapper, PathAccessor
pathAccessor, P childPath, boolean includeAbsent) {
//
-//
+//
// List trs;
// for(RDFNode target : targets) {
// // Generate the triple pattern (target, p, o)
// Var var = (Var)target.asNode();
// System.out.println(var);
-//
+//
// BinaryRelation br =
// BinaryRelationImpl.create(var, Vars.p, Vars.o, isFwd)
// .joinOn(var).with(new Concept(basePattern, var))
// .toBinaryRelation();
-//
+//
// }
-//
-//// // Resolve the path to a
+//
+//// // Resolve the path to a
//// PathAccessorRdf pathAccessor = new PathAccessorSimplePath();
//// PathToRelationMapper mapper = new PathToRelationMapper<>(pathAccessor, "w");
////
//// basePath.
//// mapper.getOverallRelation(path);
-//
+//
//// BinaryRelation br =
//// BinaryRelationImpl.create(var, Vars.p, Vars.o, isFwd)
//// .joinOn(var).with(new Concept(basePattern, var))
//// .toBinaryRelation();
-//
-//
-//
+//
+//
+//
// System.out.println(ResourceUtils.listPropertyValues(root, step).toList());
// }
- public static TernaryRelation unionTernary(Collection extends TernaryRelation> items) {
- Relation tmp = union(items, Arrays.asList(Vars.s, Vars.p, Vars.o));
- TernaryRelation result = tmp.toTernaryRelation();
- return result;
- }
-
-
- public static Relation union(Collection extends Relation> items, List proj) {
- List elements = items.stream()
- .map(e -> RelationUtils.rename(e, proj))
- .map(Relation::getElement)
- .collect(Collectors.toList());
-
- Element e = ElementUtils.unionIfNeeded(elements);
-
- Relation result = new RelationImpl(e, proj);
- return result;
- }
-
-
+ public static TernaryRelation unionTernary(Collection extends TernaryRelation> items) {
+ Relation tmp = union(items, Arrays.asList(Vars.s, Vars.p, Vars.o));
+ TernaryRelation result = tmp.toTernaryRelation();
+ return result;
+ }
+
+ /**
+ * Create a union from a given collection of unary relations
+ * If the collection is empty, return a relation with an empty (unit) table.
+ *
+ * TODO Move to ConceptUtils
+ *
+ * @param relations
+ * @return
+ */
+ public static UnaryRelation unionUnary(Collection extends UnaryRelation> relations) {
+ Relation tmp = VirtualPartitionedQuery.union(relations, Collections.singletonList(Vars.s));
+ UnaryRelation result = tmp.toUnaryRelation();
+ return result;
+
+// Set mentionedVars = relations.stream()
+// .map(Relation::getVarsMentioned)
+// .flatMap(Collection::stream)
+// .collect(Collectors.toSet());
+// UnaryRelation result;
+//
+// if (relations.isEmpty()) {
+// result = new Concept(new ElementData(), Vars.x);
+// } else {
+//
+// UnaryRelation first = relations.iterator().next();
+// Var tgtVar = first.getVar();
+// List tgtVars = Collections.singletonList(tgtVar);
+//
+// result = VirtualPartitionedQuery.union(relations, tgtVars).toUnaryRelation();
+
+// List elements = relations.stream()
+// .map(r -> RelationUtils.rename(r, tgtVars))
+// .map(Relation::toUnaryRelation)
+// .map(Relation::getElement)
+// .collect(Collectors.toList());
+
+// Element e = ElementUtils.unionIfNeeded(elements);
+
+// result = new Concept(e, tgtVar);
+// }
+// return result;
+ }
+
+ public static Relation union(Collection extends Relation> items, List proj) {
+
+ // TODO Handle the case where items is empty
+ // Option 1: Inject FILTER(false) (but this does not project vars)
+ // Option 2: Inject VALUES(proj) { }
+
+ List elements = items.stream()
+ .map(e -> RelationUtils.rename(e, proj))
+ .map(Relation::getElement)
+ .collect(Collectors.toList());
+
+ Element e = ElementUtils.unionIfNeeded(elements);
+
+ Relation result = new RelationImpl(e, proj);
+ return result;
+ }
+
+
// public static Query rewrite(Resolver resolver, boolean isFwd, Query query) {
// Collection views = resolver.getContrib(true);
//
// TernaryRelation tr = unionTernary(views);
//// System.out.println(tr);
-//
+//
// GenericLayer layer = GenericLayer.create(tr);
-//
+//
// Query raw = ElementTransformTripleRewrite.transform(query, layer, true);
// Query result = DataQueryImpl.rewrite(raw, DataQueryImpl.createDefaultRewriter()::rewrite);
//
@@ -297,241 +346,241 @@ public static Relation union(Collection extends Relation> items, List pro
//
// return result;
// }
-//
-
- public static Query rewrite(Collection views, Query query) {
+//
+
+ public static Query rewrite(Collection views, Query query) {
// Resolver resolver = createResolver(view, viewVar);
// Query result = rewrite(resolver, true, query);
- TernaryRelation tr = unionTernary(views);
+ TernaryRelation tr = unionTernary(views);
// System.out.println(tr);
-
- GenericLayer layer = GenericLayer.create(tr);
-
- Query raw = ElementTransformTripleRewrite.transform(query, layer, true);
- logger.debug("Query over View: Raw rewritten query:\n" + raw);
-
- Query result = QueryUtils.rewrite(raw, AlgebraUtils.createDefaultRewriter()::rewrite);
- logger.debug("Query over View: Final rewritten query:\n" + result);
-
- return result;
- }
-
-
- /**
- *
- * @return The updated partitioned query with the variable set to the target of the path
- *
- * TODO Maybe we want to return a PartitionedQuery2 - with source and target var
- */
- /*
- public static PartitionedQuery1 extendQueryWithPath(PartitionedQuery1 base, AliasedPath path) {
- Var targetVar = Var.alloc("todo-fresh-var");
-
- ResolverNode node = ResolverNodeImpl.from(base, null);
- ResolverNode target = node.walk(path);
-
- Collection rawBrs = target.getPaths();
-
- // Set the target variable of the paths to the desired alias
+
+ GenericLayer layer = GenericLayer.create(tr);
+
+ Query raw = ElementTransformTripleRewrite.transform(query, layer, true);
+ logger.debug("Query over View: Raw rewritten query:\n" + raw);
+
+ Query result = QueryUtils.rewrite(raw, AlgebraUtils.createDefaultRewriter()::rewrite);
+ logger.debug("Query over View: Final rewritten query:\n" + result);
+
+ return result;
+ }
+
+
+ /**
+ *
+ * @return The updated partitioned query with the variable set to the target of the path
+ *
+ * TODO Maybe we want to return a PartitionedQuery2 - with source and target var
+ */
+ /*
+ public static PartitionedQuery1 extendQueryWithPath(PartitionedQuery1 base, AliasedPath path) {
+ Var targetVar = Var.alloc("todo-fresh-var");
+
+ ResolverNode node = ResolverNodeImpl.from(base, null);
+ ResolverNode target = node.walk(path);
+
+ Collection rawBrs = target.getPaths();
+
+ // Set the target variable of the paths to the desired alias
// Collection brs = rawBrs.stream()
// .map(br -> RelationUtils.rename(br, Arrays.asList(br.getSourceVar(), targetVar)).toBinaryRelation())
// .collect(Collectors.toList());
-
- for(BinaryRelation br : rawBrs) {
- System.out.println("Relation: " + br);
- }
-
- return null;
- }
- */
-
- /**
- * Convert each triple pattern occuring in the template of a SPARQL construct query
- * into a ternary relation. This is a somewhat poor-man's approach to creating views over rdf data:
- * An improved rewriter would not treat the triple patterns in isolation, but rather take care of
- * doing self-join elimination if multiple triple patterns of a view match that of a query.
- *
- *
- */
- public static Collection toViews(Query query) {
- if(!query.isConstructType() || query.isConstructQuad()) {
- throw new RuntimeException("Construct query (without quads) expected");
- }
-
- Op op = Algebra.compile(query);
-
- Set visibleVars = OpVars.visibleVars(op);
- Generator gen = VarGeneratorBlacklist.create(visibleVars);
-
- Collection result = new ArrayList<>();
- Template template = query.getConstructTemplate();
- //BasicPattern bgp = template.getBGP();
- //TransformReplaceConstants.transform(new OpBGP(bgp));
-
-
- Element pattern = query.getQueryPattern();
- for(Triple t : template.getTriples()) {
- List nodes = TripleUtils.tripleToList(t);
- Map nodeToVar = new HashMap<>();
- Map substs = TransformReplaceConstants.transform(nodeToVar, nodes, gen);
-
- Triple newT = NodeTransformLib.transform(new NodeTransformRenameMap(substs), t);
-
- Element newE;
- if(substs.isEmpty()) {
- newE = pattern;
- } else {
- ElementGroup tgt = new ElementGroup();
- ElementUtils.copyElements(tgt, pattern);
-
- // Add the BINDs afterwards in order to get a nicer algebra:
- // We get extend(subOp, bindings) instead of join(extend(unit, bindings), subOp)
- for(Entry e : substs.entrySet()) {
- tgt.addElement(new ElementBind(e.getValue(), NodeValue.makeNode(e.getKey())));
- }
-
- newE = tgt;
- }
-
-
- TernaryRelation tr = new TernaryRelationImpl(newE,
- (Var)newT.getSubject(),
- (Var)newT.getPredicate(),
- (Var)newT.getObject());
-
- result.add(tr);
- }
-
- return result;
- }
-
-
-/*
- public static void main(String[] args) {
+
+ for(BinaryRelation br : rawBrs) {
+ System.out.println("Relation: " + br);
+ }
+
+ return null;
+ }
+ */
+
+ /**
+ * Convert each triple pattern occuring in the template of a SPARQL construct query
+ * into a ternary relation. This is a somewhat poor-man's approach to creating views over rdf data:
+ * An improved rewriter would not treat the triple patterns in isolation, but rather take care of
+ * doing self-join elimination if multiple triple patterns of a view match that of a query.
+ *
+ *
+ */
+ public static Collection toViews(Query query) {
+ if(!query.isConstructType() || query.isConstructQuad()) {
+ throw new RuntimeException("Construct query (without quads) expected");
+ }
+
+ Op op = Algebra.compile(query);
+
+ Set visibleVars = OpVars.visibleVars(op);
+ Generator gen = VarGeneratorBlacklist.create(visibleVars);
+
+ Collection result = new ArrayList<>();
+ Template template = query.getConstructTemplate();
+ //BasicPattern bgp = template.getBGP();
+ //TransformReplaceConstants.transform(new OpBGP(bgp));
+
+
+ Element pattern = query.getQueryPattern();
+ for(Triple t : template.getTriples()) {
+ List nodes = TripleUtils.tripleToList(t);
+ Map nodeToVar = new HashMap<>();
+ Map substs = TransformReplaceConstants.transform(nodeToVar, nodes, gen);
+
+ Triple newT = NodeTransformLib.transform(new NodeTransformRenameMap(substs), t);
+
+ Element newE;
+ if(substs.isEmpty()) {
+ newE = pattern;
+ } else {
+ ElementGroup tgt = new ElementGroup();
+ ElementUtils.copyElements(tgt, pattern);
+
+ // Add the BINDs afterwards in order to get a nicer algebra:
+ // We get extend(subOp, bindings) instead of join(extend(unit, bindings), subOp)
+ for(Entry e : substs.entrySet()) {
+ tgt.addElement(new ElementBind(e.getValue(), NodeValue.makeNode(e.getKey())));
+ }
+
+ newE = tgt;
+ }
+
+
+ TernaryRelation tr = new TernaryRelationImpl(newE,
+ (Var)newT.getSubject(),
+ (Var)newT.getPredicate(),
+ (Var)newT.getObject());
+
+ result.add(tr);
+ }
+
+ return result;
+ }
+
+
+/*
+ public static void main(String[] args) {
//CONSTRUCT { ?s ?p ?o } WHERE {?x ?s . ?x ?p ?o }
-
-
- if(true) {
- List views = Arrays.asList(
- //new TernaryRelationImpl(Concept.parseElement("{ ?s ?p ?o }", null), Vars.s, Vars.p, Vars.o),
- new TernaryRelationImpl(Concept.parseElement(
- "{ ?x ?s"
- + ". ?x ?p ?o }", null), Vars.s, Vars.p, Vars.o)
- );
-
- //Query view = QueryFactory.create("CONSTRUCT {?s ?p ?o } { ?s ?pRaw ?o . BIND(URI(CONCAT('http://foobar', STR(?pRaw))) AS ?p) }");
- //PartitionedQuery1 pq = PartitionedQuery1.from(view, Vars.s);
- //Resolver resolver = Resolvers.from(pq);
+
+
+ if(true) {
+ List views = Arrays.asList(
+ //new TernaryRelationImpl(Concept.parseElement("{ ?s ?p ?o }", null), Vars.s, Vars.p, Vars.o),
+ new TernaryRelationImpl(Concept.parseElement(
+ "{ ?x ?s"
+ + ". ?x ?p ?o }", null), Vars.s, Vars.p, Vars.o)
+ );
+
+ //Query view = QueryFactory.create("CONSTRUCT {?s ?p ?o } { ?s ?pRaw ?o . BIND(URI(CONCAT('http://foobar', STR(?pRaw))) AS ?p) }");
+ //PartitionedQuery1 pq = PartitionedQuery1.from(view, Vars.s);
+ //Resolver resolver = Resolvers.from(pq);
// FILTER(?s = )
- String queryStr = "SELECT ?s ?o { ?s a ; ?o . FILTER(?s = )}";
-
- Query example1 = rewrite(
- views,
- QueryFactory.create(queryStr));
- System.out.println("Example 1\n" + example1);
-
- try(RDFConnection conn = RDFConnectionFactory.connect("https://query.wikidata.org/sparql")) {
-
- //example1 = DataQueryImpl.rewrite(example1, DataQueryImpl.createDefaultRewriter()::rewrite);
- try(QueryExecution qe = conn.query(example1)) {
- System.out.println(ResultSetFormatter.asText(qe.execSelect()));
- }
- }
-
- return;
- }
-
-
- Query view = QueryFactory.create("CONSTRUCT { ?p ?c } { { SELECT ?p (COUNT(?o) AS ?c) { ?s ?p ?o } GROUP BY ?p } }");
- PartitionedQuery1 pq = PartitionedQuery1.from(view, Vars.p);
- Resolver resolver = Resolvers.from(pq);
-
- if(false) {
-
- Query example1 = rewrite(
- resolver
- .getRdfGraphSpec(true),
- QueryFactory.create("SELECT ?x ?y ?z { ?x ?y ?z }"));
- System.out.println("Example 1\n" + example1);
-
- Query example2 = rewrite(
- resolver
- .getRdfGraphSpec(true),
- QueryFactory.create("SELECT DISTINCT ?y { ?x ?y ?z }"));
- System.out.println("Example 2\n" + example2);
-
- Query example3 = rewrite(
- resolver
- .resolve(new P_Link(NodeFactory.createURI("http://facetCount")))
- .getRdfGraphSpec(true),
- QueryFactory.create("SELECT ?x ?y ?z { ?x ?y ?z }"));
- System.out.println("Example 3\n" + example3);
-
- Query example4a = rewrite(
- resolver
- .resolve(new P_Link(NodeFactory.createURI("http://facetCount")))
- .getRdfGraphSpec(true),
- QueryFactory.create("SELECT DISTINCT ?y { ?x ?y ?z }"));
- System.out.println("Example 4a\n" + example4a);
- Query example4b = rewrite(
- resolver
- .resolve(new P_Link(NodeFactory.createURI("http://facetCount")), "someAlias")
- .getRdfGraphSpec(true),
- QueryFactory.create("SELECT DISTINCT ?y { ?x ?y ?z }"));
- System.out.println("Example 4b\n" + example4b);
- }
-
- // TODO We may need to tag alias as whether it corresponds to a fixed var name
- // or a relative path id
+ String queryStr = "SELECT ?s ?o { ?s a ; ?o . FILTER(?s = )}";
+
+ Query example1 = rewrite(
+ views,
+ QueryFactory.create(queryStr));
+ System.out.println("Example 1\n" + example1);
+
+ try(RDFConnection conn = RDFConnectionFactory.connect("https://query.wikidata.org/sparql")) {
+
+ //example1 = DataQueryImpl.rewrite(example1, DataQueryImpl.createDefaultRewriter()::rewrite);
+ try(QueryExecution qe = conn.query(example1)) {
+ System.out.println(ResultSetFormatter.asText(qe.execSelect()));
+ }
+ }
+
+ return;
+ }
+
+
+ Query view = QueryFactory.create("CONSTRUCT { ?p ?c } { { SELECT ?p (COUNT(?o) AS ?c) { ?s ?p ?o } GROUP BY ?p } }");
+ PartitionedQuery1 pq = PartitionedQuery1.from(view, Vars.p);
+ Resolver resolver = Resolvers.from(pq);
+
+ if(false) {
+
+ Query example1 = rewrite(
+ resolver
+ .getRdfGraphSpec(true),
+ QueryFactory.create("SELECT ?x ?y ?z { ?x ?y ?z }"));
+ System.out.println("Example 1\n" + example1);
+
+ Query example2 = rewrite(
+ resolver
+ .getRdfGraphSpec(true),
+ QueryFactory.create("SELECT DISTINCT ?y { ?x ?y ?z }"));
+ System.out.println("Example 2\n" + example2);
+
+ Query example3 = rewrite(
+ resolver
+ .resolve(new P_Link(NodeFactory.createURI("http://facetCount")))
+ .getRdfGraphSpec(true),
+ QueryFactory.create("SELECT ?x ?y ?z { ?x ?y ?z }"));
+ System.out.println("Example 3\n" + example3);
+
+ Query example4a = rewrite(
+ resolver
+ .resolve(new P_Link(NodeFactory.createURI("http://facetCount")))
+ .getRdfGraphSpec(true),
+ QueryFactory.create("SELECT DISTINCT ?y { ?x ?y ?z }"));
+ System.out.println("Example 4a\n" + example4a);
+ Query example4b = rewrite(
+ resolver
+ .resolve(new P_Link(NodeFactory.createURI("http://facetCount")), "someAlias")
+ .getRdfGraphSpec(true),
+ QueryFactory.create("SELECT DISTINCT ?y { ?x ?y ?z }"));
+ System.out.println("Example 4b\n" + example4b);
+ }
+
+ // TODO We may need to tag alias as whether it corresponds to a fixed var name
+ // or a relative path id
// System.out.println(
// resolver
-// .resolve(new P_Link(NodeFactory.createURI("http://facetCount")), "p")
-// .resolve(new P_Link(NodeFactory.createURI("http://label")), "labelAlias")
+// .resolve(new P_Link(NodeFactory.createURI("http://facetCount")), "p")
+// .resolve(new P_Link(NodeFactory.createURI("http://label")), "labelAlias")
// .getPaths());
- AliasedPath path = PathBuilderNode.start()
- .fwd("http://facetCount").viaAlias("a")
- .fwd("http://label").one()//viaAlias("b")
- .aliasedPath();
-
- if(false) {
- path = PathBuilderNode.start()
- .fwd("http://facetCount").one()
- .fwd("http://label").one()
- .aliasedPath();
- }
-
- System.out.println("built path: " + path);
-
-
- // High level API:
+ AliasedPath path = PathBuilderNode.start()
+ .fwd("http://facetCount").viaAlias("a")
+ .fwd("http://label").one()//viaAlias("b")
+ .aliasedPath();
+
+ if(false) {
+ path = PathBuilderNode.start()
+ .fwd("http://facetCount").one()
+ .fwd("http://label").one()
+ .aliasedPath();
+ }
+
+ System.out.println("built path: " + path);
+
+
+ // High level API:
// System.out.println("Paths: " + (ResolverNode.from(resolver)
// .fwd("http://facetCount").viaAlias("a")
// .fwd("http://label").viaAlias("b")
// .getPaths());
-
- System.out.println(pq);
- extendQueryWithPath(pq, path);
-
+
+ System.out.println(pq);
+ extendQueryWithPath(pq, path);
+
//
// System.out.println(resolver
-// .resolve(new P_Link(NodeFactory.createURI("http://facetCount")))
+// .resolve(new P_Link(NodeFactory.createURI("http://facetCount")))
// .getPaths());
- }
- */
-
- static class GeneralizedStep {
- boolean isFwd;
- XExpr expr;
- }
-
- //processor.step(pq, new P_Link(NodeFactory.createURI("http://facetCount")), true, "a");
-
-
- //VirtualPartitionedQuery processor = new VirtualPartitionedQuery();
-
+ }
+ */
+
+ static class GeneralizedStep {
+ boolean isFwd;
+ XExpr expr;
+ }
+
+ //processor.step(pq, new P_Link(NodeFactory.createURI("http://facetCount")), true, "a");
+
+
+ //VirtualPartitionedQuery processor = new VirtualPartitionedQuery();
+
// Query query = QueryFactory.create("CONSTRUCT { ?city ?mayor . ?mayor ?party } { ?city ?mayor . ?mayor ?party }");
diff --git a/jena-sparql-api-algebra/src/test/java/org/aksw/jena_sparql_api/core/utils/QueryGenerationUtilsTests.java b/jena-sparql-api-algebra/src/test/java/org/aksw/jena_sparql_api/core/utils/QueryGenerationUtilsTests.java
index 65deda13d..7f47691a4 100644
--- a/jena-sparql-api-algebra/src/test/java/org/aksw/jena_sparql_api/core/utils/QueryGenerationUtilsTests.java
+++ b/jena-sparql-api-algebra/src/test/java/org/aksw/jena_sparql_api/core/utils/QueryGenerationUtilsTests.java
@@ -102,6 +102,7 @@ public void testProject2() {
public void testOptimizeAggToDistinctX() {
Query query = QueryFactory.create("SELECT (?s AS ?x) ?o { ?s ?p ?o } GROUP BY ?s ?o");
// QueryGenerationUtils.optimizeAggregationToDistinct(query);
+ System.out.println("TODO Validate testOptimizeAggToDistinctX");
System.out.println(QueryGenerationUtils.analyzeDistinctVarSets(query));
System.out.println(query);
}
@@ -160,8 +161,6 @@ public void testCountQueryGenerationA1() {
eval(
"SELECT ?s ?o { ?s ?p ?o }",
input -> {
- Collection vars = Arrays.asList(s);
- // Expected SELECT (COUNT(*) AS ?c_1) { ?s ?p ?o }
Entry count = QueryGenerationUtils.createQueryCountCore(input, null, null);
return count.getValue();
},
@@ -199,7 +198,6 @@ public void testCountQueryGenerationA4() {
eval(
"SELECT ?s (AVG(?o) AS ?c) { ?s ?p ?o } GROUP BY ?s ?p",
input -> {
- Collection vars = Arrays.asList(s, Var.alloc("c"));
Entry count = QueryGenerationUtils.createQueryCountCore(input, null, null);
return count.getValue();
},
@@ -306,4 +304,33 @@ public void testCountQueryGenerationForLsqBug() {
);
}
+ @Test
+ public void testCountQueryGenerationForLimitBug() {
+ eval(
+ "SELECT * { ?s ?p ?o } LIMIT 100 OFFSET 5",
+ input -> {
+ Entry count = QueryGenerationUtils.createQueryCountCore(input, 50l, null);
+ return count.getValue();
+ },
+ "SELECT (COUNT(*) AS ?c_1) { SELECT * { ?s ?p ?o } LIMIT 50 OFFSET 5 }"
+ );
+ }
+
+ /**
+ * Queries only with constants caused an exception in the rewrite stating that there need to be
+ * variables
+ *
+ */
+ @Test
+ public void testCountQueryGenerationForLsqBug2() {
+ eval(
+ "SELECT * { }",
+ input -> {
+ Entry count = QueryGenerationUtils.createQueryCountCore(input, 1000l, null);
+ return count.getValue();
+ },
+ "SELECT (COUNT(*) AS ?c_1) { SELECT * { } LIMIT 1000 }"
+ );
+ }
+
}
diff --git a/jena-sparql-api-batch/pom.xml b/jena-sparql-api-batch/pom.xml
index 73bc8cf4b..de74a6bc7 100644
--- a/jena-sparql-api-batch/pom.xml
+++ b/jena-sparql-api-batch/pom.xml
@@ -11,7 +11,7 @@
org.aksw.jena-sparql-api
jena-sparql-api-parent
- 3.16.0-1
+ 3.16.0-2
diff --git a/jena-sparql-api-batch/src/main/java/org/aksw/jena_sparql_api/batch/cli/main/DatasetGraphDiff.java b/jena-sparql-api-batch/src/main/java/org/aksw/jena_sparql_api/batch/cli/main/DatasetGraphDiff.java
deleted file mode 100644
index 248d7c45f..000000000
--- a/jena-sparql-api-batch/src/main/java/org/aksw/jena_sparql_api/batch/cli/main/DatasetGraphDiff.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package org.aksw.jena_sparql_api.batch.cli.main;
-
-import java.util.Iterator;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-import org.apache.jena.graph.Graph;
-import org.apache.jena.graph.Node;
-import org.apache.jena.query.ReadWrite;
-import org.apache.jena.query.TxnType;
-import org.apache.jena.sparql.core.DatasetGraph;
-import org.apache.jena.sparql.core.DatasetGraphBase;
-import org.apache.jena.sparql.core.Quad;
-
-class PredicateIfQuadExists
- implements Predicate
-{
- protected DatasetGraph datasetGraph;
-
- public PredicateIfQuadExists(DatasetGraph datasetGraph) {
- super();
- this.datasetGraph = datasetGraph;
- }
-
- @Override
- public boolean apply(Quad quad) {
- boolean result = datasetGraph.contains(quad);
- return result;
- }
-}
-
-public class DatasetGraphDiff
- extends DatasetGraphBase
-{
- protected DatasetGraph core;
-
- protected DatasetGraph added;
- protected DatasetGraph removed;
-
-
- @Override
- public Iterator find(Node g, Node s, Node p, Node o) {
- Predicate pred = new PredicateIfQuadExists(removed);
-
- Iterator itAdded = added.find(g, s, p, o);
-
- Iterator result = core.find(g, s, p, o);
- result = Iterators.filter(result, pred);
- result = Iterators.concat(result, itAdded);
-
- return result;
- }
-
- @Override
- public Iterator findNG(Node g, Node s, Node p, Node o) {
- Predicate pred = new PredicateIfQuadExists(removed);
-
- Iterator itAdded = added.findNG(g, s, p, o);
-
- Iterator result = core.findNG(g, s, p, o);
- result = Iterators.filter(result, pred);
- result = Iterators.concat(result, itAdded);
-
- return result;
- }
-
- @Override
- public Iterator listGraphNodes() {
- Iterator result = core.listGraphNodes();
- return result;
- }
-
- @Override
- public void addGraph(Node arg0, Graph arg1) {
- }
-
- @Override
- public Graph getDefaultGraph() {
- return null;
-// Graph result = core.getDefaultGraph();
-// return result;
- }
-
- @Override
- public Graph getGraph(Node arg0) {
- return null;
-// Graph result = core.getDefaultGraph();
-// return result;
- }
-
- @Override
- public void removeGraph(Node arg0) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean supportsTransactions() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void abort() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void begin(ReadWrite arg0) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void commit() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void end() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean isInTransaction() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void begin(TxnType type) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean promote(Promote mode) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public ReadWrite transactionMode() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public TxnType transactionType() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
diff --git a/jena-sparql-api-batch/src/main/java/org/aksw/jena_sparql_api/spring/conversion/C_StringToMappedQuery.java b/jena-sparql-api-batch/src/main/java/org/aksw/jena_sparql_api/spring/conversion/C_StringToMappedQuery.java
index 937ededde..b065cc77c 100644
--- a/jena-sparql-api-batch/src/main/java/org/aksw/jena_sparql_api/spring/conversion/C_StringToMappedQuery.java
+++ b/jena-sparql-api-batch/src/main/java/org/aksw/jena_sparql_api/spring/conversion/C_StringToMappedQuery.java
@@ -3,14 +3,14 @@
import org.aksw.jena_sparql_api.mapper.MappedQuery;
import org.aksw.jena_sparql_api.mapper.MappedQueryUtils;
import org.aksw.jena_sparql_api.mapper.PartitionedQuery1;
+import org.aksw.jena_sparql_api.mapper.PartitionedQuery1Impl;
import org.aksw.jena_sparql_api.stmt.SparqlQueryParser;
import org.aksw.jena_sparql_api.utils.VarUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.convert.converter.Converter;
-
import org.apache.jena.query.Query;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.Var;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.convert.converter.Converter;
@AutoRegistered
@@ -39,7 +39,7 @@ public static PartitionedQuery1 parse(String str, SparqlQueryParser parser) {
Var var = VarUtils.parseVar(splits[0]);
Query query = parser.apply(splits[1]);
- PartitionedQuery1 result = new PartitionedQuery1(query, var);
+ PartitionedQuery1 result = new PartitionedQuery1Impl(query, var);
return result;
}
diff --git a/jena-sparql-api-cache-h2/pom.xml b/jena-sparql-api-cache-h2/pom.xml
index 2148b401d..efe76ae0d 100644
--- a/jena-sparql-api-cache-h2/pom.xml
+++ b/jena-sparql-api-cache-h2/pom.xml
@@ -10,7 +10,7 @@
org.aksw.jena-sparql-api
jena-sparql-api-parent
- 3.16.0-1
+ 3.16.0-2
diff --git a/jena-sparql-api-cache/pom.xml b/jena-sparql-api-cache/pom.xml
index bd8fc6cd3..51a555eda 100644
--- a/jena-sparql-api-cache/pom.xml
+++ b/jena-sparql-api-cache/pom.xml
@@ -10,7 +10,7 @@
org.aksw.jena-sparql-api
jena-sparql-api-parent
- 3.16.0-1
+ 3.16.0-2
diff --git a/jena-sparql-api-collections/pom.xml b/jena-sparql-api-collections/pom.xml
index 77ceeb4ea..1bb4325bd 100644
--- a/jena-sparql-api-collections/pom.xml
+++ b/jena-sparql-api-collections/pom.xml
@@ -13,7 +13,7 @@
org.aksw.jena-sparql-api
jena-sparql-api-parent
- 3.16.0-1
+ 3.16.0-2
diff --git a/jena-sparql-api-collections/src/main/java/org/aksw/jena_sparql_api/rdf/collections/ConverterFromObjectToLexicalFormViaRDFDatatype.java b/jena-sparql-api-collections/src/main/java/org/aksw/jena_sparql_api/rdf/collections/ConverterFromObjectToLexicalFormViaRDFDatatype.java
new file mode 100644
index 000000000..71a07ece2
--- /dev/null
+++ b/jena-sparql-api-collections/src/main/java/org/aksw/jena_sparql_api/rdf/collections/ConverterFromObjectToLexicalFormViaRDFDatatype.java
@@ -0,0 +1,34 @@
+package org.aksw.jena_sparql_api.rdf.collections;
+
+import org.apache.jena.datatypes.RDFDatatype;
+
+import com.google.common.base.Converter;
+
+/**
+ * A converter between Objects and lexical forms (Strings) via {@link RDFDatatype}.
+ *
+ * @author raven
+ *
+ */
+public class ConverterFromObjectToLexicalFormViaRDFDatatype
+ extends Converter