diff --git a/src/main/java/fr/inria/corese/core/query/QueryProcess.java b/src/main/java/fr/inria/corese/core/query/QueryProcess.java index 40306761d..54bc89fb9 100755 --- a/src/main/java/fr/inria/corese/core/query/QueryProcess.java +++ b/src/main/java/fr/inria/corese/core/query/QueryProcess.java @@ -3,13 +3,10 @@ import fr.inria.corese.core.Event; import fr.inria.corese.core.EventManager; import fr.inria.corese.core.Graph; -import fr.inria.corese.core.api.DataBroker; -import fr.inria.corese.core.api.DataBrokerConstruct; import fr.inria.corese.core.api.Loader; import fr.inria.corese.core.api.Log; import fr.inria.corese.core.compiler.eval.Interpreter; import fr.inria.corese.core.compiler.eval.QuerySolver; -import fr.inria.corese.core.compiler.eval.QuerySolverVisitor; import fr.inria.corese.core.compiler.federate.FederateVisitor; import fr.inria.corese.core.compiler.parser.Transformer; import fr.inria.corese.core.kgram.api.core.Node; @@ -26,7 +23,6 @@ import fr.inria.corese.core.load.Service; import fr.inria.corese.core.logic.Entailment; import fr.inria.corese.core.print.LogManager; -import fr.inria.corese.core.print.TripleFormat; import fr.inria.corese.core.producer.DataBrokerConstructExtern; import fr.inria.corese.core.query.update.GraphManager; import fr.inria.corese.core.sparql.api.IDatatype; @@ -39,13 +35,10 @@ import fr.inria.corese.core.sparql.triple.parser.*; import fr.inria.corese.core.sparql.triple.parser.Access.Feature; import fr.inria.corese.core.sparql.triple.parser.Access.Level; -import fr.inria.corese.core.sparql.triple.parser.context.ContextLog; import fr.inria.corese.core.storage.api.dataManager.DataManager; -import fr.inria.corese.core.transform.TemplateVisitor; import fr.inria.corese.core.util.Extension; import fr.inria.corese.core.util.Property; import jakarta.ws.rs.client.ResponseProcessingException; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,7 +93,7 @@ public class QueryProcess extends QuerySolver { boolean isMatch = false; private QueryProcessUpdate queryProcessUpdate; private ProducerImpl localProducer; - private DataBrokerConstruct dataBrokerUpdate; + // true: execute start/end transaction before query // false: case where we execute a subquery (e.g. xt:sparql) // or a query within rule engine @@ -281,12 +274,6 @@ static ProducerImpl createProducer(Graph g, String factory, String db) { return ProducerImpl.create(g); } - public static QueryProcess create(Graph g, Graph g2) { - QueryProcess qp = QueryProcess.create(g); - qp.add(g2); - return qp; - } - /** * Create an Eval initialized with a query q that contains function * definitions This Eval can be used to call these functions: @@ -316,10 +303,6 @@ public static Interpreter createInterpreter(Producer p, Matcher m) { return eval; } - static boolean isOverwrite() { - return isReentrant(); - } - public static void setOverwrite(boolean b) { setReentrant(b); } @@ -347,10 +330,6 @@ public static void setVisitorName(String aSolverVisitorName) { solverVisitorName = aSolverVisitorName; } - public static String getServerVisitorName() { - return serverVisitorName; - } - public static void setServerVisitorName(String name) { serverVisitorName = name; } @@ -409,14 +388,6 @@ DataManager getDataManager(Producer p) { return null; } - public Loader getLoader() { - return load; - } - - public void setLoader(Loader ld) { - load = ld; - } - public boolean isMatch() { return isMatch; } @@ -466,40 +437,12 @@ QueryProcess focusFrom(Query q) { * *************************************************************** */ - public Mappings update(String squery) throws EngineException { - return doQuery(squery, null, null); - } @Override public Mappings query(String squery) throws EngineException { return doQuery(squery, null, null); } - // rdf is a turtle document - // parse it as sparql query graph pattern (where bnode are variable) - public Mappings queryTurtle(String rdf) throws EngineException { - return doQuery(rdf, null, Dataset.create().setLoad(true)); - } - - // translate graph g as turtle ast query graph pattern - public Mappings queryTurtle(Graph g) throws EngineException { - String rdf = TripleFormat.create(g).setGraphQuery(true).toString(); - return doQuery(rdf, null, Dataset.create().setLoad(true)); - } - - // translate graph g as trig ast query graph pattern - public Mappings queryTrig(Graph g) throws EngineException { - // trig where default graph kg:default is printed - // in turtle without embedding graph kg:default { } - String rdf = TripleFormat.create(g, true).setGraphQuery(true).toString(); - return doQuery(rdf, null, Dataset.create().setLoad(true)); - } - - // translate graph g as trig ast query graph pattern - public Mappings query(Graph g) throws EngineException { - return queryTrig(g); - } - /** * defaut and named specify a Dataset if the query has no from/using (resp. * named), kgram use defaut (resp. named) if it exist for update, defaut is @@ -515,14 +458,6 @@ public Mappings query(String squery, Dataset ds) throws EngineException { return query(squery, null, ds); } - public Mappings query(String squery, Context c) throws EngineException { - return query(squery, null, Dataset.create(c)); - } - - public Mappings query(String squery, AccessRight access) throws EngineException { - return query(squery, new Context(access)); - } - @Override public Mappings query(String squery, Mapping map) throws EngineException { return query(squery, map, null); @@ -532,14 +467,6 @@ public Mappings query(String squery, Binding b) throws EngineException { return query(squery, Mapping.create(b), null); } - public Mappings query(String squery, Context c, Binding b) throws EngineException { - return query(squery, Mapping.create(b), Dataset.create(c)); - } - - public Mappings query(String squery, ProcessVisitor vis) throws EngineException { - return query(squery, null, Dataset.create(vis)); - } - Mappings doQuery(String squery, Mapping map, Dataset ds) throws EngineException { Query q = compile(squery, ds); return query(null, q, map, ds); @@ -558,11 +485,6 @@ public Query compile(String squery, Dataset ds) throws EngineException { return q; } - public Mappings modifier(String str, Mappings map) throws SparqlException { - Query q = compile(str, new Context().setAST(map.getAST())); - return modifier(q, map); - } - @Override public Query compile(String squery) throws EngineException { return compile(squery, (Dataset) null); @@ -642,10 +564,6 @@ public Mappings sparql(String squery, Dataset ds) throws EngineException { return sparqlQueryUpdate(squery, ds, RDFS_ENTAILMENT); } - public Mappings sparql(String squery, Dataset ds, int entail) throws EngineException { - return sparqlQueryUpdate(squery, ds, entail); - } - public Mappings query(ASTQuery ast) throws EngineException { if (ast.isUpdate()) { return update(ast); @@ -686,13 +604,6 @@ public Mappings update(ASTQuery ast) throws EngineException { * ***************************************** */ - public Mappings sparqlQuery(String squery) throws EngineException { - Query q = compile(squery); - if (q.isUpdate()) { - throw new EngineException("Unauthorized Update in SPARQL Query:\n" + squery); - } - return query(q); - } public Mappings sparqlQuery(String squery, Mapping map, Dataset ds) throws EngineException { Query q = compile(squery, ds); @@ -706,18 +617,6 @@ public Mappings sparqlQuery(Query q, Mapping map, Dataset ds) throws EngineExcep return query(null, q, map, ds); } - public Mappings sparqlUpdate(String squery) throws EngineException { - Query q = compile(squery); - if (!q.isUpdate()) { - throw new EngineException("Unauthorized Query in SPARQL Update:\n" + squery); - } - return query(q); - } - - public Mappings sparqlQueryUpdate(String squery) throws EngineException { - return query(squery); - } - /* * ************************************************************************* * @@ -875,40 +774,6 @@ void processLog(Query q, Mappings map) { } } - // translate log header into Mappings - // use case: gui display log header as query results - public Mappings log2Mappings(ContextLog log) throws EngineException { - return log2Mappings(log, false); - } - - public Mappings log2Mappings(ContextLog log, boolean blog) throws EngineException { - String str = "select * where {?s ?p ?o}"; - Query q = compile(str); - Mappings map = Mappings.create(q); - map.init(q); - Collection nameList = log.getLabelList(); - - for (String url : log.getSubjectMap().getKeys()) { - if (blog) { - nameList = log.getPropertyMap(url).keySet(); - } - for (String name : nameList) { - IDatatype value = log.getLabel(url, name); - - if (value != null) { - ArrayList valueList = new ArrayList<>(); - valueList.add(DatatypeMap.newResource(url)); - valueList.add(DatatypeMap.newResource(name)); - valueList.add(value); - Mapping m = Mapping.create(q.getSelect(), valueList); - map.add(m); - } - } - } - - return map; - } - Mappings synQuery(Node gNode, Query query, Mapping m) throws EngineException { Mappings map = null; try { @@ -1153,28 +1018,6 @@ public void afterLoad(IDatatype dt, boolean b) { ************************************************************************ */ - /** - * skolemize the blank nodes of the result Mappings - */ - public Mappings skolem(Mappings map) { - Graph g = getGraph(); - if (map.getGraph() != null) { - // result of construct where - g = (Graph) map.getGraph(); - } - for (Mapping m : map) { - Node[] nodes = m.getNodes(); - int i = 0; - for (Node n : nodes) { - if (n.isBlank()) { - nodes[i] = g.skolem(n); - } - i++; - } - } - return map; - } - public void logStart(Query query) { if (getGraph() != null) { getGraph().logStart(query); @@ -1187,13 +1030,6 @@ public void logFinish(Query query, Mappings m) { } } - public void close() { - if (dbProducer != null) { - dbProducer.close(); - dbProducer = null; - } - } - /** * Logger xt:method(us:start, us:Event, event, obj) * Use case: event logger @@ -1235,10 +1071,6 @@ public IDatatype funcall(String name, Binding b, IDatatype... param) throws Engi return funcall(name, null, b, param); } - public IDatatype funcall(String name, Context c, IDatatype... param) throws EngineException { - return funcall(name, c, null, param); - } - public IDatatype funcall(String name, Context c, Binding b, IDatatype... param) throws EngineException { Function function = getLinkedFunction(name, param); if (function == null) { @@ -1283,20 +1115,6 @@ public void init(Query q, Mapping m) { getCurrentEval().getVisitor().setActive(false); } - /** - * call @public @prepare function us:prepare() {} before lock graph - * to complete initialization before query processing - * to be called explicitely by user - * use case: GUI QueryExec call prepare() - * use case: xt:entailment() - */ - public void prepare() { - try { - new QuerySolverVisitor(getCreateEval()).prepare(); - } catch (EngineException ex) { - } - } - // Default Visitor to execute @event functions public ProcessVisitor getDefaultVisitor() { try { @@ -1315,10 +1133,6 @@ public ProcessVisitor getVisitor() { return getCurrentEval().getVisitor(); } - public TemplateVisitor getTemplateVisitor() { - return (TemplateVisitor) getCreateBinding().getTransformerVisitor(); - } - @Override public ProcessVisitor createProcessVisitor(Eval eval) { if (getVisitorName() == null) { @@ -1386,14 +1200,6 @@ public ASTQuery parse(String path, Level level) throws EngineException { return t.parse(str); } - /** - * 1- Linked Function 2- owl:imports - */ - @Override - public Query parseQuery(String path) throws EngineException { - return parseQuery(path, Level.USER_DEFAULT); - } - @Override public Query parseQuery(String path, Level level) throws EngineException { String str = QueryLoad.create().basicParse(path); @@ -1426,10 +1232,6 @@ public void getLinkedFunction(String label) throws EngineException { getTransformer().getLinkedFunction(label); } - void getLinkedFunctionBasic(String label) throws EngineException { - getTransformer().getLinkedFunctionBasic(label); - } - public Graph defineFederation(String path) throws IOException, EngineException, LoadException { Graph g = Graph.create(); Load ld = Load.create(g); @@ -1458,10 +1260,6 @@ public void defineFederation(String name, List list) { FederateVisitor.defineFederation(name, list); } - public void defineFederation(String name, String... list) { - FederateVisitor.defineFederation(name, Arrays.asList(list)); - } - Transformer getTransformer() { if (transformer == null) { transformer = Transformer.create(); @@ -1472,10 +1270,6 @@ Transformer getTransformer() { //*********************************************************************** - public Graph getExceptionGraph(Mappings map) throws LoadException { - LogManager te = getLogManager(map); - return te.parse(); - } /** * Manager for local and remote endpoint log @@ -1493,22 +1287,6 @@ public LogManager getLogManager(Mappings map) { return new LogManager(getLog(map)); } - public JSONObject getMessage(Mappings map) { - String text = getStringMessage(map); - if (text == null) { - return null; - } - return new JSONObject(text); - } - - public String getStringMessage(Mappings map) { - String url = map.getLastLink(URLParam.MES); - if (url == null) { - return null; - } - return new Service().getString(url); - } - public QueryProcessUpdate getQueryProcessUpdate() { return queryProcessUpdate; } @@ -1534,18 +1312,6 @@ public boolean hasDataManager() { return getDataManager() != null; } - public DataBroker getDataBroker() { - return getLocalProducer().getDataBroker(); - } - - public DataBrokerConstruct getDataBrokerUpdate() { - return dataBrokerUpdate; - } - - public void setDataBrokerUpdate(DataBrokerConstruct dataBrokerUpdate) { - this.dataBrokerUpdate = dataBrokerUpdate; - } - public boolean isProcessTransaction() { return processTransaction; }