/** * @inheritDoc */ @Override public void meet(final ExtensionElem theExtensionElem) throws Exception { mExtensions.put(theExtensionElem.getName(), theExtensionElem.getExpr()); }
/** * @inheritDoc */ @Override public void meet(final ExtensionElem theExtensionElem) throws Exception { mExtensions.put(theExtensionElem.getName(), theExtensionElem.getExpr()); }
@Override public boolean equals(Object other) { if (other instanceof ExtensionElem) { ExtensionElem o = (ExtensionElem)other; return name.equals(o.getName()) && expr.equals(o.getExpr()); } return false; }
@Override public Set<String> getBindingNames() { Set<String> bindingNames = new LinkedHashSet<>(arg.getBindingNames()); for (ExtensionElem pe : elements) { bindingNames.add(pe.getName()); } return bindingNames; }
/** * @inheritDoc */ @Override public void meet(final ExtensionElem theExtensionElem) throws Exception { mExtensions.put(theExtensionElem.getName(), theExtensionElem.getExpr()); }
@Override public boolean equals(Object other) { if (other instanceof ExtensionElem) { ExtensionElem o = (ExtensionElem)other; return name.equals(o.getName()) && expr.equals(o.getExpr()); } return false; }
@Override public Set<String> getBindingNames() { Set<String> bindingNames = new LinkedHashSet<String>(arg.getBindingNames()); for (ExtensionElem pe : elements) { bindingNames.add(pe.getName()); } return bindingNames; }
@Override public void meet(final ExtensionElem node) { if(node.getExpr() instanceof AbstractAggregateOperator) { bindingNames.remove(node.getName()); } }
@Override public void meet(Extension node) { extension = node; List<ExtensionElem> elements = node.getElements(); // NB: preserve ExtensionElem order extensionExprs = new LinkedHashMap<String, ValueExpr>(elements.size()); for (ExtensionElem elem : elements) { extensionExprs.put(elem.getName(), elem.getExpr()); } }
@Override public void meet(Extension e) { super.meet(e); for (ExtensionElem elem: e.getElements()) { res.add(elem.getName()); } } // TODO maybe stop tree traversal in nested SERVICE?
@Override public void meet(Extension e) { super.meet(e); for (ExtensionElem elem: e.getElements()) { res.add(elem.getName()); } } // TODO maybe stop tree traversal in nested SERVICE?
/** * Constructs an instance of {@link ProjectionEvaluator}. * * @param projectionElems - Defines the structure of the resulting value. (not null) * @param extensions - Extra information about the projection elements when there are anonymous constants or blank * nodes within the projection elements. (not null) */ public ProjectionEvaluator(final ProjectionElemList projectionElems, final Optional<Extension> extensions) { this.projectionElems = requireNonNull(projectionElems); requireNonNull(extensions); // Find all extensions that represent constant insertions. if(extensions.isPresent()) { for(final ExtensionElem extensionElem : extensions.get().getElements()) { final ValueExpr valueExpr = extensionElem.getExpr(); // If the extension is a ValueConstant, store it so that they may be added to the binding sets. if(valueExpr instanceof ValueConstant) { final String sourceName = extensionElem.getName(); final Value targetValue = ((ValueConstant) valueExpr).getValue(); constantSources.put(sourceName, targetValue); } // If the extension is a BNodeGenerator, keep track of the name so that we know we have to generate an ID for it. else if(valueExpr instanceof BNodeGenerator) { final String sourceName = extensionElem.getName(); anonymousSources.add( sourceName ); } } } }
/** * Make a {@link MultiProjectionEvaluator} that processes the logic of a {@link MultiProjection}. * * @param multiProjection - Defines the projections that will be processed. (not null) * @param bNodeIdFactory - Creates the IDs for Blank Nodes. (not null) * @return A {@link MultiProjectionEvaluator} for the provided {@link MultiProjection}. */ public static MultiProjectionEvaluator make(final MultiProjection multiProjection, final BNodeIdFactory bNodeIdFactory) { requireNonNull(multiProjection); // Figure out if there are extensions. final TupleExpr arg = multiProjection.getArg(); final Optional<Extension> extension = (arg instanceof Extension) ? Optional.of((Extension)arg): Optional.empty(); // If there are, iterate through them and find any blank node source names. final Set<String> blankNodeSourceNames = new HashSet<>(); if(extension.isPresent()) { for(final ExtensionElem elem : extension.get().getElements()) { if(elem.getExpr() instanceof BNodeGenerator) { blankNodeSourceNames.add( elem.getName() ); } } } // Create a ProjectionEvaluator for each projection that is part of the multi. final Set<ProjectionEvaluator> projections = new HashSet<>(); for(final ProjectionElemList projectionElemList : multiProjection.getProjections()) { projections.add( new ProjectionEvaluator(projectionElemList, extension) ); } return new MultiProjectionEvaluator(projections, blankNodeSourceNames, bNodeIdFactory); }
private ConstructGraph getConstructGraph(final List<ProjectionElemList> projections, final List<ExtensionElem> extensionElems) { final Map<String, Value> valueMap = new HashMap<>(); //create valueMap to associate source names with Values for(final ExtensionElem elem: extensionElems) { final String name = elem.getName(); final ValueExpr expr = elem.getExpr(); if(expr instanceof ValueConstant) { final Value value = ((ValueConstant) expr).getValue(); valueMap.put(name, value); } else if(expr instanceof BNodeGenerator) { valueMap.put(name, VF.createBNode(UUID.randomUUID().toString())); } } final Set<ConstructProjection> constructProj = new HashSet<>(); //build ConstructProjection for each ProjectionElemList for(final ProjectionElemList list: projections) { validateProjectionElemList(list); final List<Var> vars = new ArrayList<>(); for(final ProjectionElem elem: list.getElements()) { final String sourceName = elem.getSourceName(); final Var var = new Var(sourceName); if(valueMap.containsKey(sourceName)) { var.setValue(valueMap.get(sourceName)); } vars.add(var); } constructProj.add(new ConstructProjection(vars.get(0), vars.get(1), vars.get(2))); } return new ConstructGraph(constructProj); }
@Override public void meet(Extension node) { Set<String> argBindings = node.getArg().getBindingNames(); if (typeRequirement != null) { node.getElements().removeIf(elem -> { if (varName.equals(elem.getName())) { ValueExpr expr = elem.getExpr(); if (expr == null) { return true; } else if (expr instanceof Var) { String fromName = ((Var) expr).getName(); if (getVarValue((Var) expr) == null && !argBindings.contains(fromName)) { return true; } } } return false; }); meetUnaryTupleOperator(node); } } @Override
public DefaultSimpleGraphResultSet(TupleResultSet tupleResultSet, ConstructTemplate constructTemplate, boolean storeResults, TermFactory termFactory, org.apache.commons.rdf.api.RDF rdfFactory) throws OntopResultConversionException, OntopConnectionException { this.tupleResultSet = tupleResultSet; this.constructTemplate = constructTemplate; this.termFactory = termFactory; this.rdfFactory = rdfFactory; Extension ex = constructTemplate.getExtension(); if (ex != null) { extMap = ex.getElements().stream() .collect(ImmutableCollectors.toMap(e -> e.getName(), e -> e.getExpr())); } else extMap = null; this.storeResults = storeResults; if (storeResults) { //process current result set into local buffer, //since additional results will be collected while (tupleResultSet.hasNext()) { results.addAll(processResults(tupleResultSet.next())); } } }
@Override public void meet(ExtensionElem node) throws RDFHandlerException { listEntry(); handler.handleStatement(valueFactory.createStatement(subject, RDF.TYPE, SP.BIND_CLASS)); Resource var = getVar(node.getName()); handler.handleStatement(valueFactory.createStatement(subject, SP.VARIABLE_PROPERTY, var)); meet(node.getExpr()); }