@Override public void visit(ElementGroup group) { ElementGroup newgroup = new ElementGroup(); for (Element e: group.getElements()) { e.visit(this); newgroup.addElement(result); } result = newgroup; } @Override
public void addFilter(ElementFilter filter) { if (query.getQueryPattern() instanceof ElementTriplesBlock) { ElementGroup group = new ElementGroup(); group.addElement(query.getQueryPattern()); group.addElementFilter(filter); query.setQueryPattern(group); } else { assert query.getQueryPattern() instanceof ElementGroup; ElementGroup group = (ElementGroup) query.getQueryPattern(); group.addElementFilter(filter); } } public void add(Element elt) {
public void addTriplePattern(Triple t) { ensureBGP().addTriple(t) ; }
@Override public Var evaluate(NodeSelector nodeSelector, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) { GroupedSelector groupedSelector = (GroupedSelector) nodeSelector; ElementGroup newGroup = new ElementGroup(); elementGroup.addElement(newGroup); return LDPathEvaluator.evaluate(groupedSelector.getContent(), newGroup, var, evaluatorConfiguration); } }
protected Element compressGroupOfOneGroup(ElementGroup elg) { // remove group of one group. if ( elg.getElements().size() == 1 ) { Element e1 = elg.getElements().get(0) ; if ( e1 instanceof ElementGroup ) return e1 ; } return elg ; }
public void addElementFilter(ElementFilter el) { addElement(el) ; }
protected void add(ElementGroup targetGroup,ElementPathBlock targetGroupPathBlock, ElementGroup newGroup) { // add the subgroup content directly for (Element subelt: newGroup.getElements()) { if (subelt instanceof ElementPathBlock) { add(targetGroupPathBlock, (ElementPathBlock) subelt); } else if (subelt instanceof ElementTriplesBlock) { add(targetGroupPathBlock, (ElementTriplesBlock) subelt); } else if (subelt instanceof ElementGroup) { assert false : subelt+"\n"+newGroup ; //add(targetGroup, targetGroupPathBlock, (ElementGroup) subelt); } else { targetGroup.addElement(subelt); } } } protected void add(ElementPathBlock targetPathBlock, ElementPathBlock newPaths) {
public Converter(Query query) { this.query = query ; currentGroup = new ElementGroup() ; }
private void makeElementConstraints(Query q, ElementGroup g ,RDQL_Node node) { Q_ConstraintClause qcc = (Q_ConstraintClause)node ; int n = qcc.jjtGetNumChildren() ; for ( int j = 0 ; j < n ; j++ ) { Object obj = qcc.jjtGetChild(j) ; if ( ! ( obj instanceof ExprRDQL ) ) throw new ARQInternalErrorException("Parse node in AND clause isn't a Constraint") ; ElementFilter f = new ElementFilter((ExprRDQL)obj) ; g.addElementFilter(f) ; } }
public void visit(OpSequence opSequence) { ElementGroup g = currentGroup() ; boolean nestGroup = ! g.isEmpty() ; if ( nestGroup ) { startSubGroup() ; g = currentGroup() ; } Iterator<Op> iter = opSequence.iterator() ; for ( ; iter.hasNext() ; ) { Op op = iter.next() ; Element e = asElement(op) ; g.addElement(e) ; } if ( nestGroup ) endSubGroup() ; return ; }
@Override public Var evaluate(NodeSelector nodeSelector, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) { PropertySelector propertySelector = (PropertySelector) nodeSelector; if (propertySelector instanceof WildcardSelector) { throw new IllegalStateException(propertySelector.getClass() + " is not supported."); } Var id = Var.alloc(VarIDGenerator.createID()); elementGroup.addTriplePattern(new Triple(var.asNode(), NodeFactory.createURI(propertySelector.getProperty().toString()), id.asNode())); return id; } }
public static <T extends ResourceObject> Query evaluate(QueryServiceConfiguration queryServiceDTO, URI rootType) throws ParseException { Query query = QueryFactory.make(); query.setQuerySelectType(); ElementGroup elementGroup = new ElementGroup(); Var objectVar = Var.alloc("root"); // Creating and adding the first triple - could be something like: "?objectVar rdf:type oa:Annotation Triple t1 = new Triple(objectVar, RDF.type.asNode(), NodeFactory.createURI(rootType.toString())); elementGroup.addTriplePattern(t1); // Evaluating the criteria for (Criteria c : queryServiceDTO.getCriteria()) { SesameValueBackend backend = new SesameValueBackend(); LdPathParser parser = new LdPathParser(backend, queryServiceDTO.getConfiguration(), new StringReader(c.getLdpath())); Var var = LDPathEvaluator.evaluate(parser.parseSelector(queryServiceDTO.getPrefixes()), elementGroup, objectVar, queryServiceDTO.getEvaluatorConfiguration()); if (c.getConstraint() != null) { String resolvedConstraint = resolveConstraintPrefix(c.getConstraint(), queryServiceDTO, parser); EvalComparison.evaluate(elementGroup, c, var, resolvedConstraint); } } // Adding all generated patterns to the query object query.setQueryPattern(elementGroup); // Choose what we want so select - SELECT ?annotation in this case query.addResultVar(objectVar); // Setting the default prefixes, like rdf: or dc: query.getPrefixMapping().setNsPrefixes(queryServiceDTO.getPrefixes()); return query; }
@Override public Var evaluate(NodeSelector nodeSelector, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) { TestingSelector testingSelector = (TestingSelector) nodeSelector; FunctionTest functionTest = (FunctionTest) testingSelector.getTest(); if(functionTest.getArgSelectors().get(0) instanceof PropertySelector) { PropertySelector arg = (PropertySelector) functionTest.getArgSelectors().get(0); PropertySelector delegate = (PropertySelector) testingSelector.getDelegate(); Var target = Var.alloc(VarIDGenerator.createID()); elementGroup.addTriplePattern(new Triple(var.asNode(), NodeFactory.createURI(delegate.getProperty().toString()), target)); Var selector = Var.alloc(VarIDGenerator.createID()); elementGroup.addTriplePattern(new Triple(target.asNode(), NodeFactory.createURI(arg.getProperty().toString()), selector.asNode())); elementGroup.addElementFilter(new ElementFilter(new E_IsLiteral(new ExprVar(selector)))); return selector; } else { throw new IllegalStateException("Argument of function isLiteral has to be a PropertySelector"); } } }
private static boolean emptyGroup(Element element) { if ( ! ( element instanceof ElementGroup ) ) return false ; ElementGroup eg = (ElementGroup)element ; return eg.isEmpty() ; }
public void add(Element elt) { if (query.getQueryPattern() instanceof ElementTriplesBlock) { ElementGroup group = new ElementGroup(); group.addElement(query.getQueryPattern()); group.addElement(elt); query.setQueryPattern(group); } else { assert query.getQueryPattern() instanceof ElementGroup; ElementGroup group = (ElementGroup) query.getQueryPattern(); group.addElement(elt); } }
private Element lastElement() { ElementGroup g = currentGroup ; if ( g == null || g.getElements().size() == 0 ) return null ; int len = g.getElements().size() ; return g.getElements().get(len-1) ; }
public void addElementFilter(ElementFilter el) { addElement(el) ; }
private void startSubGroup() { push(currentGroup) ; ElementGroup g = new ElementGroup() ; currentGroup = g ; }
@Override public Var evaluate(NodeSelector nodeSelector, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) { TestingSelector testingSelector = (TestingSelector) nodeSelector; Var delVar = LDPathEvaluator.evaluate(testingSelector.getDelegate(), elementGroup, var, evaluatorConfiguration); elementGroup.addElementFilter(new ElementFilter(evaluate(testingSelector.getTest(), elementGroup, delVar, evaluatorConfiguration))); return delVar; } }