public Iterator<Map<String,Object>> query(String query, Map<String,Object> params) { return cypher.execute(query,params==null ? Collections.<String,Object>emptyMap() : params).iterator(); }
@Override public CloseableIterator<Term> termsByPredicatePosition(Predicate p, int position) throws AtomSetException { StringBuilder sb = new StringBuilder(); sb.append("MATCH "); predicateToCypher(sb, p); sb.append("<-[rel_predicate:PREDICATE]-(atom)-[:TERM { index: ").append(position).append(" }]->(term) "); sb.append("RETURN DISTINCT term"); String query = sb.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(query); } ResourceIterator<Map<String, Object>> result = this.cypherEngine.execute(query).iterator(); return new Neo4jTermIterator(this.getTransaction(), result); }
@Override public CloseableIterator<Atom> atomsByPredicate(Predicate p) throws AtomSetException { StringBuilder sb = new StringBuilder(); sb.append("MATCH "); predicateToCypher(sb, p); sb.append("<-[rel_predicate:PREDICATE]-(atom)"); sb.append("RETURN atom"); String query = sb.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(query); } ResourceIterator<Map<String, Object>> result = this.cypherEngine.execute(query).iterator(); return new Neo4jAtomIterator(this.getTransaction(), result); }
@Override public CloseableIterator<Atom> match(Atom atom) { String query = matchAtomIntoCypherQuery(atom); if (LOGGER.isDebugEnabled()) { LOGGER.debug(query); } ResourceIterator<Map<String, Object>> result = this.cypherEngine.execute(query).iterator(); return new Neo4jAtomIterator(this.getTransaction(), result); }
@Override @Deprecated public CloseableIterator<Term> termsIterator(Type type) throws AtomSetException { Map<String, Object> params = new TreeMap<String, Object>(); params.put("type", type.toString()); this.checkTransaction(); return new Neo4jTermIterator(this.getTransaction(), this.cypherEngine.execute( "match (term:TERM {type : { type }}) return term", params) .iterator()); }
@Override public CloseableIterator<Atom> iterator() { this.checkTransaction(); return new Neo4jAtomIterator(this.getTransaction(), this.cypherEngine.execute( "match (atom:ATOM) return atom").iterator()); }
@Override public CloseableIterator<Predicate> predicatesIterator() throws AtomSetException { this.checkTransaction(); return new Neo4jPredicateIterator(this.getTransaction(), this.cypherEngine .execute("match (predicate:PREDICATE) return predicate") .iterator()); }
@Override public CloseableIterator<Term> termsIterator() throws AtomSetException { this.checkTransaction(); return new Neo4jTermIterator(this.getTransaction(), this.cypherEngine.execute( "match (term:TERM) return term").iterator()); }
@Override public void link() { LinkProgress progress = new LinkProgress(LOG::info, 10); progress.start(); boolean done; ExecutionEngine engine = new ExecutionEngine(graphDb); do { ExecutionResult result = engine.execute("START dataset = node:datasets('*:*')\n" + "MATCH dataset<-[:IN_DATASET]-study-[:REFUTES|SUPPORTS]->specimen\n" + "WHERE not(specimen<-[:HAS_PARTICIPANT]-())\n" + "WITH specimen, study, dataset LIMIT {batchSize}\n" + "MATCH specimen-[i:" + InteractUtil.allInteractionsCypherClause() + "]->otherSpecimen\n" + "WHERE not(has(i.inverted))\n" + "CREATE specimen<-[:HAS_PARTICIPANT]-interaction-[:DERIVED_FROM]->study" + ", interaction-[:HAS_PARTICIPANT]->otherSpecimen " + ", interaction-[:ACCESSED_AT]->dataset\n" + "RETURN id(interaction)", MapUtil.map("batchSize", this.batchSize)); done = !result.iterator().hasNext(); result.iterator().close(); progress.progress(); } while (!done); }