/** * use case: exists {} in aggregate select (count(if (exists { BGP }, ?x, * ?y)) as ?c) Env is a Mapping Copy Mapping into fresh Memory in order to * evaluate exists {} in Memory TODO: optimize by storing mem * * */ public Memory getMemory(Mapping map, Exp exp) { Memory mem = new Memory(match, evaluator); getEvaluator().init(mem); mem.init(query); mem.copy(map, exp); return mem; }
/** * copy memory for sub query * copy sub query select variables that are * already bound in current memory * Use case: subquery and exists */ private Memory copyMemory(Memory memory, Query query, Query sub, Exp exp) { Memory mem = new Memory(match, evaluator); getEvaluator().init(mem); if (sub == null) { mem.init(query); } else { mem.init(sub); } memory.copyInto(sub, mem, exp); if (hasEvent) { memory.setEventManager(manager); } return mem; }
void init(Memory env) { mem = new Memory(matcher, evaluator); mem.init(env.getQuery()); mem.init(env); mem.setFake(true); evaluator.init(mem); mem.share(mem.getBind(), env.getBind()); mem.setEval(kgram); }
void initMemory(Query q) { if (memory == null) { // when subquery, memory is already assigned // assign stack index to EDGE and NODE q.complete(producer);//service while1 / Query memory = new Memory(match, evaluator); memory.setEval(this); getEvaluator().init(memory); // create memory bind stack memory.init(q); if (hasEvent) { memory.setEventManager(manager); } producer.init(q); evaluator.start(memory); debug = q.isDebug(); if (q.isAlgebra()){ complete(q); } if (debug){ System.out.println(q); } } }
Mappings subEval(Producer p, Node gNode, Node node, Exp exp, Exp main, Mappings map, Mapping m, boolean bind) { Memory mem = new Memory(match, evaluator); getEvaluator().init(mem); mem.share(memory); mem.init(query); mem.setAppxSearchEnv(this.memory.getAppxSearchEnv()); Eval eval = copy(mem, p); graphNode(gNode, node, mem); bind(mem, exp, main, map, m, bind); Mappings lMap = eval.subEval(query, node, Stack.create(exp), 0); return lMap; }
/** * use case: result of st:apply-templates-all() list = list of ?out results * of templates create Mappings (?out = value) apply st:aggregate(?out) on * Mappings Use the st:aggregate of the query q that called * st:apply-templates-all() if q is member of this transformation, otherwise * get the st:profile of this transformation to get the appropriate * st:aggregate definition if any */ IDatatype result(Environment env, List<Node> list) { Query q = (env == null) ? null : env.getQuery(); Query tq = (q != null && contains(q)) ? q : qe.getTemplate(); Memory mem = new Memory(exec.getMatcher(), exec.getEvaluator()); exec.getEvaluator().init(mem); if (env != null){ mem.share(mem.getBind(), env.getBind()); mem.setEval(env.getEval()); } mem.init(tq); Node out = tq.getExtNode(OUT, true); Mappings map = Mappings.create(tq); for (Node node : list) { map.add(Mapping.create(out, node)); } mem.setResults(map); // execute st:aggregate(?out) Node node = map.apply(exec.getEvaluator(), tq.getTemplateGroup(), mem, exec.getProducer()); return (IDatatype) node.getDatatypeValue(); }
/** * use case: result of st:apply-templates-all() list = list of ?out results * of templates create Mappings (?out = value) apply st:aggregate(?out) on * Mappings Use the st:aggregate of the query q that called * st:apply-templates-all() if q is member of this transformation, otherwise * get the st:profile of this transformation to get the appropriate * st:aggregate definition if any */ IDatatype result(Environment env, List<Node> list) { Query q = (env == null) ? null : env.getQuery(); Query tq = (q != null && contains(q)) ? q : qe.getTemplate(); Memory mem = new Memory(exec.getMatcher(), exec.getEvaluator()); exec.getEvaluator().init(mem); if (env != null){ mem.share(mem.getBind(), env.getBind()); mem.setEval(env.getEval()); } mem.init(tq); Node out = tq.getExtNode(OUT, true); Mappings map = Mappings.create(tq); for (Node node : list) { map.add(Mapping.create(out, node)); } mem.setResults(map); // execute st:aggregate(?out) Node node = map.apply(exec.getEvaluator(), tq.getTemplateGroup(), mem, exec.getProducer()); return (IDatatype) node.getDatatypeValue(); }