/** * @param patterns a collection of patterns to match in the graph * @return a {@link Match} that will find matches of the given patterns */ @CheckReturnValue public static Match match(Collection<? extends Pattern> patterns) { return withoutGraph().match(patterns); }
/** * @param patterns an array of patterns to match in the graph * @return a {@link Match} that will find matches of the given patterns */ @CheckReturnValue public static Match match(Pattern... patterns) { return withoutGraph().match(patterns); }
public static void assertNotExists(QueryBuilder qb, Pattern... patterns) { assertNotExists(qb.match(patterns)); }
public static void assertExists(QueryBuilder qb, Pattern... patterns) { assertExists(qb.match(patterns)); }
@Override public Match visitMatchBase(GraqlParser.MatchBaseContext ctx) { Collection<Pattern> patterns = visitPatterns(ctx.patterns()); return queryBuilder.match(patterns); }
/** * Helper method to check whether the concept types in the scope have any instances * * @return */ private boolean scopeContainsInstance() { if (scopeTypeLabels().isEmpty()) return false; List<Pattern> checkSubtypes = scopeTypeLabels().stream() .map(type -> Graql.var("x").isa(Graql.label(type))).collect(Collectors.toList()); return tx.graql().infer(false).match(Graql.or(checkSubtypes)).iterator().hasNext(); }
public static void printWholeCompletionMessage(MigrationOptions options){ System.out.println("Migration complete."); if(options.isVerbose()) { System.out.println("Gathering information about migrated data. If in a hurry, you can ctrl+c now."); GraknTx tx = new Grakn(options.getUri()).session(options.getKeyspace()).transaction(GraknTxType.WRITE); QueryBuilder qb = tx.graql(); StringBuilder builder = new StringBuilder(); builder.append("Graph schema contains:\n"); builder.append("\t ").append(tx.admin().getMetaEntityType().instances().count()).append(" entity types\n"); builder.append("\t ").append(tx.admin().getMetaRelationType().instances().count()).append(" relation types\n"); builder.append("\t ").append(tx.admin().getMetaRole().subs().count()).append(" roles\n\n"); builder.append("\t ").append(tx.admin().getMetaAttributeType().instances().count()).append(" resource types\n"); builder.append("\t ").append(tx.admin().getMetaRule().subs().count()).append(" rules\n\n"); builder.append("Graph data contains:\n"); builder.append("\t ").append(qb.match(var("x").isa(label(ENTITY.getLabel()))).aggregate(count()).execute()).append(" entities\n"); builder.append("\t ").append(qb.match(var("x").isa(label(RELATIONSHIP.getLabel()))).aggregate(count()).execute()).append(" relations\n"); builder.append("\t ").append(qb.match(var("x").isa(label(ATTRIBUTE.getLabel()))).aggregate(count()).execute()).append(" resources\n"); builder.append("\t ").append(qb.match(var("x").isa(label(RULE.getLabel()))).aggregate(count()).execute()).append(" rules\n\n"); System.out.println(builder); tx.close(); } }
public GetQuery getQuery() { return tx.graql().infer(false).match(getPattern()).get(); }
/** * Get the resource edge id if there is one. Return null if not. */ public static ConceptId getResourceEdgeId(GraknTx graph, ConceptId conceptId1, ConceptId conceptId2) { if (mayHaveResourceEdge(graph, conceptId1, conceptId2)) { Optional<Concept> firstConcept = graph.graql().match( var("x").id(conceptId1), var("y").id(conceptId2), var("z").rel(var("x")).rel(var("y"))) .get("z") .stream().map(answer -> answer.get("z")) .findFirst(); if (firstConcept.isPresent()) { return firstConcept.get().id(); } } return null; }
Stream<ConceptMap> answerStream = conjQuery.isRuleResolvable() ? conjQuery.resolve() : embeddedTx.graql().infer(false).match(conj).stream(); while (conjIt.hasNext()) { conj = conjIt.next(); conjQuery = ReasonerQueries.create(conj, embeddedTx).rewrite(); Stream<ConceptMap> localStream = conjQuery.isRuleResolvable() ? conjQuery.resolve() : embeddedTx.graql().infer(false).match(conj).stream(); answerStream = Stream.concat(answerStream, localStream);
/** * Helper method to check whether the concept types in the target have any instances * * @return true if they exist, false if they don't */ private boolean targetContainsInstance() { for (Label attributeType : targetTypeLabels()) { for (Label type : scopeTypeLabels()) { Boolean patternExist = tx.graql().infer(false).match( Graql.var("x").has(attributeType, Graql.var()), Graql.var("x").isa(Graql.label(type)) ).iterator().hasNext(); if (patternExist) return true; } } return false; //TODO: should use the following ask query when ask query is even lazier // List<Pattern> checkResourceTypes = statisticsResourceTypes.stream() // .map(type -> var("x").has(type, var())).collect(Collectors.toList()); // List<Pattern> checkSubtypes = inTypes.stream() // .map(type -> var("x").isa(Graql.label(type))).collect(Collectors.toList()); // // return tx.get().graql().infer(false) // .match(or(checkResourceTypes), or(checkSubtypes)).aggregate(ask()).execute(); }