diff --git a/sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/OptionsViaCommandLineTest.java b/sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/OptionsViaCommandLineTest.java index d0d5377a..7ce3072a 100644 --- a/sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/OptionsViaCommandLineTest.java +++ b/sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/OptionsViaCommandLineTest.java @@ -32,7 +32,7 @@ public void testOverrideConfigurationWithBGP() throws Exception { String q = "PREFIX fx: SELECT ?v { ?root a fx:root ; ?v . fx:properties fx:content \"cde\" } "; // System.out.println(Algebra.compile(QueryFactory.create(q))); String out = SPARQLAnything.callMain(new String[]{"-q", q, "-c", "content=abc"}); - System.out.println(out); +// System.out.println(out); Assert.assertTrue(out.contains("cde")); } diff --git a/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/FXWorkerOpPropFunc.java b/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/FXWorkerOpPropFunc.java new file mode 100644 index 00000000..a8472807 --- /dev/null +++ b/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/FXWorkerOpPropFunc.java @@ -0,0 +1,92 @@ +package io.github.sparqlanything.engine; + +import org.apache.jena.sparql.algebra.op.OpPropFunc; +import org.apache.jena.sparql.core.DatasetGraph; +import org.apache.jena.sparql.engine.ExecutionContext; +import org.apache.jena.sparql.engine.QueryIterator; +import org.apache.jena.sparql.engine.main.QC; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Properties; + +public class FXWorkerOpPropFunc extends FXWorker { + + private static final Logger logger = LoggerFactory.getLogger(FXWorkerOpPropFunc.class); + + public FXWorkerOpPropFunc(TriplifierRegister tr, DatasetGraphCreator dgc){ + super(tr, dgc); + } + + @Override + public QueryIterator execute(OpPropFunc op, QueryIterator input, ExecutionContext executionContext, DatasetGraph dg, Properties p) { + return QC.execute(op, input, Utils.getFacadeXExecutionContext(executionContext, p, dg)); + } + + @Override + public void extractProperties(Properties p, OpPropFunc op) throws UnboundVariableException { + // Do nop + } + +// @Override +// public QueryIterator execute(OpService op, QueryIterator input, ExecutionContext executionContext, DatasetGraph dg, Properties p) { +// return QC.execute(op.getSubOp(), input, Utils.getFacadeXExecutionContext(executionContext, p, dg)); +// } + +// @Override +// public void extractProperties(Properties properties, OpService opService) throws UnboundVariableException { +// String url = opService.getService().getURI(); +// // Parse IRI only if contains properties +// if (!url.equals(FacadeIRIParser.SPARQL_ANYTHING_URI_SCHEMA)) { +// FacadeIRIParser p = new FacadeIRIParser(url); +// properties.putAll(p.getProperties()); +// } +// +// // Setting defaults +// if (!properties.containsKey(IRIArgument.NAMESPACE.toString())) { +// logger.trace("Setting default value for namespace: {}", Triplifier.XYZ_NS); +// properties.setProperty(IRIArgument.NAMESPACE.toString(), Triplifier.XYZ_NS); +// } +// // Setting silent +// if (opService.getSilent()) { +// // we can only see if silent was specified at the OpService so we need to stash +// // a boolean +// // at this point so we can use it when we triplify further down the Op tree +// properties.setProperty(IRIArgument.OP_SERVICE_SILENT.toString(), "true"); +// } +// +// Op next = opService.getSubOp(); +// FXBGPFinder vis = new FXBGPFinder(); +// next.visit(vis); +// logger.trace("Has Table {}", vis.hasTable()); +// +// if (vis.getBGP() != null) { +// try { +// PropertyExtractor.extractPropertiesFromBGP(properties, vis.getBGP()); +// } catch (UnboundVariableException e) { +// if (vis.hasTable()) { +// logger.trace(vis.getOpTable().toString()); +// logger.trace("BGP {}", vis.getBGP()); +// logger.trace("Contains variable names {}", vis.getOpTable().getTable().getVarNames().contains(e.getVariableName())); +// if (vis.getOpTable().getTable().getVarNames().contains(e.getVariableName())) { +// e.setOpTable(vis.getOpTable()); +// } +// } +// +// if (vis.getOpExtend() != null) { +// logger.trace("OpExtend {}", vis.getOpExtend()); +// for (Var var : vis.getOpExtend().getVarExprList().getVars()) { +// if (var.getName().equals(e.getVariableName())) { +// e.setOpExtend(vis.getOpExtend()); +// } +// } +// } +// +// throw e; +// } +// logger.trace("Number of properties {}: {}", properties.size(), properties); +// } else { +// logger.trace("Couldn't find OpGraph"); +// } +// } +} diff --git a/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/FacadeXOpExecutor.java b/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/FacadeXOpExecutor.java index 2d7e3e02..6df29630 100644 --- a/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/FacadeXOpExecutor.java +++ b/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/FacadeXOpExecutor.java @@ -43,17 +43,31 @@ public class FacadeXOpExecutor extends OpExecutor { private final FXWorkerOpService fxWorkerService; private final FXWorkerOpBGP fxWorkerOpBGP; + private final FXWorkerOpPropFunc fxWorkerOpPropFunc ; + public FacadeXOpExecutor(ExecutionContext execCxt) { super(execCxt); TriplifierRegister triplifierRegister = TriplifierRegister.getInstance(); DatasetGraphCreator dgc = new DatasetGraphCreator(execCxt); fxWorkerService = new FXWorkerOpService(triplifierRegister, dgc); fxWorkerOpBGP = new FXWorkerOpBGP(triplifierRegister, dgc); + fxWorkerOpPropFunc = new FXWorkerOpPropFunc(triplifierRegister, dgc); } protected QueryIterator execute(final OpPropFunc opPropFunc, QueryIterator input){ logger.trace("OpProp {}", opPropFunc); - return super.execute(opPropFunc, input); + if (this.execCxt.getClass() == FacadeXExecutionContext.class) { + + return super.execute(opPropFunc, input); + }else { + try { + return fxWorkerOpPropFunc.execute(opPropFunc, input, this.execCxt); + } catch (ClassNotFoundException | InvocationTargetException | InstantiationException | + IllegalAccessException | NoSuchMethodException | IOException | UnboundVariableException | + TriplifierHTTPException e) { + throw new RuntimeException(e); + } + } } protected QueryIterator execute(final OpBGP opBGP, QueryIterator input) { @@ -61,38 +75,14 @@ protected QueryIterator execute(final OpBGP opBGP, QueryIterator input) { if(hasFXSymbols(this.execCxt) && !this.execCxt.getContext().isDefined(FacadeXExecutionContext.hasServiceClause)){ try { -// // extract properties from service URI -// Properties p = new Properties(); -// -// // first extract from execution context -// PropertyExtractor.extractPropertiesFromExecutionContext(this.execCxt, p); -// PropertyExtractor.extractPropertiesFromOp(opBGP, p); -// -// Triplifier t = PropertyExtractor.getTriplifier(p, triplifierRegister); -// -// // Execute with default, bulk method -// DatasetGraph dg = dgc.getDatasetGraph(t, p, opBGP); -// Utils.ensureReadingTxn(dg); -// -// ExecutionContext newExecContext = Utils.getNewExecutionContext(execCxt, p, dg); -// -// List magicPropertyTriples = Utils.getFacadeXMagicPropertyTriples(opBGP.getPattern()); -// if (!magicPropertyTriples.isEmpty()) { -// return super.execute(Utils.excludeMagicPropertyTriples(Utils.excludeFXProperties(opBGP)), executeMagicProperties(input, magicPropertyTriples, newExecContext)); -// } else { -// return QC.execute(Utils.excludeFXProperties(opBGP), input, newExecContext); -// } - return fxWorkerOpBGP.execute(opBGP, input, this.execCxt); - } catch (IOException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException | UnboundVariableException | TriplifierHTTPException e) { throw new RuntimeException(e); } } - - + // check that the BGP is within a FacadeX-SERVICE clause if (this.execCxt.getClass() == FacadeXExecutionContext.class) { // check that the BGP contains FacadeX Magic properties @@ -148,46 +138,6 @@ protected QueryIterator execute(final OpService opService, QueryIterator input) return super.execute(opService, input); } -// protected QueryIterator executeDefaultFacadeX(OpService opService, QueryIterator input) throws TriplifierHTTPException, IOException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException, UnboundVariableException { -// -// // extract properties from service URI -// Properties p = new Properties(); -// -// // first extract from execution context -// PropertyExtractor.extractPropertiesFromExecutionContext(this.execCxt, p); -// -// //then, from opservice (so that can be overwritten) -// PropertyExtractor.extractPropertiesFromOp(opService, p); -// -// // guess triplifier -// Triplifier t = PropertyExtractor.getTriplifier(p, triplifierRegister); -// -// if (t == null) { -// logger.warn("No triplifier found"); -// return QueryIterNullIterator.create(execCxt); -// } -// -// // check execution with slicing -// if (PropertyUtils.getBooleanProperty(p, IRIArgument.SLICE)) { -// if (t instanceof Slicer) { -// logger.trace("Execute with slicing"); -// return new QueryIterSlicer(execCxt, input, t, p, opService); -// } else { -// logger.warn("Slicing is not supported by triplifier: {}", t.getClass().getName()); -// } -// } -// -// // Execute with default, bulk method -// DatasetGraph dg = dgc.getDatasetGraph(t, p, opService.getSubOp()); -// Utils.ensureReadingTxn(dg); -// -// return QC.execute(opService.getSubOp(), input, Utils.getFacadeXExecutionContext(execCxt, p, dg)); -// -// } - - - - private QueryIterator catchUnboundVariableException(Op op, OpBGP opBGP, QueryIterator input, UnboundVariableException e) { // Proceed with the next operation OpBGP fakeBGP = Utils.extractFakePattern(opBGP);