@Override protected final VarPattern varPatternForAtom(Var varName, Var typeVariable) { return varName.isa(typeVariable); }
public static IsaAtom create(Var var, Var predicateVar, @Nullable ConceptId predicateId, boolean isDirect, ReasonerQuery parent) { VarPatternAdmin pattern = isDirect ? var.isaExplicit(predicateVar).admin() : var.isa(predicateVar).admin(); return new AutoValue_IsaAtom(var, predicateId, predicateVar, pattern, parent); }
/** * 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 IsaAtom create(Var var, Var predicateVar, SchemaConcept type, boolean isDirect, ReasonerQuery parent) { VarPatternAdmin pattern = isDirect ? var.isaExplicit(predicateVar).admin() : var.isa(predicateVar).admin(); return new AutoValue_IsaAtom(var, type.id(), predicateVar, pattern, parent); } private static IsaAtom create(IsaAtom a, ReasonerQuery parent) {
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(); } }
@Override protected Pattern createCombinedPattern(){ if (getPredicateVariable().isUserDefinedName()) return super.createCombinedPattern(); return getSchemaConcept() == null? getVarName().isa(getPredicateVariable()) : isDirect()? getVarName().isaExplicit(getSchemaConcept().label().getValue()) : getVarName().isa(getSchemaConcept().label().getValue()) ; }
public Pattern pattern(Entity concept) { Var entityVar = Graql.var().asUserDefined(); return entityVar .isa(Graql.label(concept.type().label())) .id(concept.id()); } }
/** * Given an thing, return a var with the type. * @param thing thing to map * @return var patterns representing given thing */ private static VarPattern base(Thing thing){ VarPattern var = var(thing.id().getValue()).isa(Graql.label(thing.type().label())); return hasResources(var, thing); }
/** * 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(); }
/** * if any {@link Role} variable of the parent is user defined rewrite ALL {@link Role} variables to user defined (otherwise unification is problematic) * @param parentAtom parent atom that triggers rewrite * @return new relation atom with user defined {@link Role} variables if necessary or this */ private RelationshipAtom rewriteWithVariableRoles(Atom parentAtom){ if (!parentAtom.requiresRoleExpansion()) return this; VarPattern relVar = getPattern().admin().getProperty(IsaProperty.class) .map(prop -> getVarName().isa(prop.type())).orElse(getVarName()); for (RelationPlayer rp: getRelationPlayers()) { VarPatternAdmin rolePattern = rp.getRole().orElse(null); if (rolePattern != null) { Var roleVar = rolePattern.var(); Label roleLabel = rolePattern.getTypeLabel().orElse(null); relVar = relVar.rel(roleVar.asUserDefined().label(roleLabel), rp.getRolePlayer()); } else { relVar = relVar.rel(rp.getRolePlayer()); } } return create(relVar.admin(), this.getPredicateVariable(), this.getTypeId(), this.getPossibleTypes(), this.getParentQuery()); }