Github user ajs6f commented on a diff in the pull request: https://github.com/apache/jena/pull/94#discussion_r44025972 --- Diff: jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/InMemDatasetAssembler.java --- @@ -0,0 +1,67 @@ +package org.apache.jena.sparql.core.assembler; + +import static org.apache.jena.assembler.JA.MemoryDataset; +import static org.apache.jena.assembler.JA.data; +import static org.apache.jena.query.DatasetFactory.createTxnMem; +import static org.apache.jena.riot.RDFDataMgr.loadModel; +import static org.apache.jena.riot.RDFDataMgr.read; +import static org.apache.jena.sparql.core.assembler.AssemblerUtils.setContext; +import static org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.*; +import static org.apache.jena.sparql.util.FmtUtils.stringForRDFNode; +import static org.apache.jena.sparql.util.graph.GraphUtils.*; + +import java.util.function.Predicate; + +import org.apache.jena.assembler.Assembler; +import org.apache.jena.assembler.Mode; +import org.apache.jena.assembler.assemblers.AssemblerBase; +import org.apache.jena.query.Dataset; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.RDFNode; +import org.apache.jena.rdf.model.Resource; + +/** + * An {@link Assembler} that creates in-memory {@link Dataset}s. + * + */ +public class InMemDatasetAssembler extends AssemblerBase { + + @Override + public Dataset open(final Assembler assembler, final Resource root, final Mode mode) { + checkType(root, MemoryDataset); + final Dataset dataset = createTxnMem(); + setContext(root, dataset.getContext()); + // Default graph can be defined with ja:graph or ja:defaultGraph + final Resource defaultGraphDef = root.hasProperty(pDefaultGraph) ? getResourceValue(root, + pDefaultGraph) : root.hasProperty(pGraph) ? getResourceValue(root, pGraph) : null; + if (defaultGraphDef != null) dataset.setDefaultModel(retrieve(defaultGraphDef, assembler, mode)); + // or with ja:data + final Predicate<RDFNode> isResource = n -> { + if (n.isResource()) return true; + throw new DatasetAssemblerException(root, "Not a resource: " + stringForRDFNode(n)); + }; + multiValue(root, data).parallelStream().filter(isResource) + .forEach(defaultGraphNode -> read(dataset, defaultGraphNode.asResource().getURI())); + + // Assemble or load named graphs + multiValue(root, pNamedGraph).parallelStream().filter(isResource).forEach(namedGraphNode -> { + final Resource namedGraphResource = namedGraphNode.asResource(); --- End diff -- Yeah, I wondered about that, but the semantics of what I've got here are actually different. If you look at `isResource`, it throws an exception when the thing is a literal (which would make no sense in an assembler construction). That's what the other assemblers seem to do. I'm happy to just ignore any "weird" constructions like that, but I thought I'd better do what the others did and throw an exception. I'll happily simplify this to ignore instead.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---