Search in sources :

Example 11 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class SchemaConceptPropertyTest method whenSettingTheDirectSuperToAnIndirectSub_Throw.

// TODO
@Ignore("Test fails due to incorrect error message")
@Property
public void whenSettingTheDirectSuperToAnIndirectSub_Throw(@NonMeta SchemaConcept concept, long seed) {
    SchemaConcept newSuperConcept = PropertyUtil.choose(concept.subs(), seed);
    // Check if the mutation can be performed in a valid manner
    if (newSuperConcept.isType())
        assumeThat(newSuperConcept.asType().plays().collect(Collectors.toSet()), is(empty()));
    exception.expect(GraknTxOperationException.class);
    exception.expectMessage(GraknTxOperationException.loopCreated(concept, newSuperConcept).getMessage());
    setDirectSuper(concept, newSuperConcept);
}
Also used : SchemaConcept(ai.grakn.concept.SchemaConcept) Ignore(org.junit.Ignore) Property(com.pholser.junit.quickcheck.Property)

Example 12 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class JsonPrinter method build.

@Override
public Json build(Concept concept) {
    Json json = Json.object("id", concept.getId().getValue());
    if (concept.isSchemaConcept()) {
        json.set("name", concept.asSchemaConcept().getLabel().getValue());
        SchemaConcept superConcept = concept.asSchemaConcept().sup();
        if (superConcept != null)
            json.set("sub", superConcept.getLabel().getValue());
    } else if (concept.isThing()) {
        json.set("isa", concept.asThing().type().getLabel().getValue());
    } else {
        throw CommonUtil.unreachableStatement("Unrecognised concept " + concept);
    }
    if (concept.isAttribute()) {
        json.set("value", concept.asAttribute().getValue());
    }
    if (concept.isRule()) {
        Pattern when = concept.asRule().getWhen();
        if (when != null) {
            json.set("when", when.toString());
        }
        Pattern then = concept.asRule().getThen();
        if (then != null) {
            json.set("then", then.toString());
        }
    }
    return json;
}
Also used : Pattern(ai.grakn.graql.Pattern) SchemaConcept(ai.grakn.concept.SchemaConcept) Json(mjson.Json)

Example 13 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class InsertQueryImpl method getSchemaConcepts.

@Override
public Set<SchemaConcept> getSchemaConcepts() {
    GraknTx theGraph = getTx().orElseThrow(GraqlQueryException::noTx);
    Set<SchemaConcept> types = allVarPatterns().map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream).map(theGraph::<Type>getSchemaConcept).collect(Collectors.toSet());
    match().ifPresent(mq -> types.addAll(mq.admin().getSchemaConcepts()));
    return types;
}
Also used : GraknTx(ai.grakn.GraknTx) CommonUtil(ai.grakn.util.CommonUtil) Type(ai.grakn.concept.Type) GraqlQueryException(ai.grakn.exception.GraqlQueryException) SchemaConcept(ai.grakn.concept.SchemaConcept)

Example 14 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class RelationshipProperty method checkValidProperty.

@Override
public void checkValidProperty(GraknTx graph, VarPatternAdmin var) throws GraqlQueryException {
    Set<Label> roleTypes = relationPlayers().stream().map(RelationPlayer::getRole).flatMap(CommonUtil::optionalToStream).map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream).collect(toSet());
    Optional<Label> maybeLabel = var.getProperty(IsaProperty.class).map(IsaProperty::type).flatMap(VarPatternAdmin::getTypeLabel);
    maybeLabel.ifPresent(label -> {
        SchemaConcept schemaConcept = graph.getSchemaConcept(label);
        if (schemaConcept == null || !schemaConcept.isRelationshipType()) {
            throw GraqlQueryException.notARelationType(label);
        }
    });
    // Check all role types exist
    roleTypes.forEach(roleId -> {
        SchemaConcept schemaConcept = graph.getSchemaConcept(roleId);
        if (schemaConcept == null || !schemaConcept.isRole()) {
            throw GraqlQueryException.notARoleType(roleId);
        }
    });
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept) RelationPlayer(ai.grakn.graql.admin.RelationPlayer)

Example 15 with SchemaConcept

use of ai.grakn.concept.SchemaConcept in project grakn by graknlabs.

the class TinkerComputeQueryRunner method run.

public ComputeJob<Map<Long, Set<String>>> run(DegreeQuery query) {
    return runCompute(query, tinkerComputeQuery -> {
        Set<Label> ofLabels;
        // Check if ofType is valid before returning emptyMap
        if (query.targetLabels().isEmpty()) {
            ofLabels = tinkerComputeQuery.subLabels();
        } else {
            ofLabels = query.targetLabels().stream().flatMap(typeLabel -> {
                Type type = tx.getSchemaConcept(typeLabel);
                if (type == null)
                    throw GraqlQueryException.labelNotFound(typeLabel);
                return type.subs();
            }).map(SchemaConcept::getLabel).collect(Collectors.toSet());
        }
        Set<Label> subLabels = Sets.union(tinkerComputeQuery.subLabels(), ofLabels);
        if (!tinkerComputeQuery.selectedTypesHaveInstance()) {
            return Collections.emptyMap();
        }
        Set<LabelId> subLabelIds = convertLabelsToIds(subLabels);
        Set<LabelId> ofLabelIds = convertLabelsToIds(ofLabels);
        ComputerResult result = tinkerComputeQuery.compute(new DegreeVertexProgram(ofLabelIds), new DegreeDistributionMapReduce(ofLabelIds, DegreeVertexProgram.DEGREE), subLabelIds);
        return result.memory().get(DegreeDistributionMapReduce.class.getName());
    });
}
Also used : MaxMapReduce(ai.grakn.graql.internal.analytics.MaxMapReduce) LoggerFactory(org.slf4j.LoggerFactory) ConnectedComponentQuery(ai.grakn.graql.analytics.ConnectedComponentQuery) Type(ai.grakn.concept.Type) KCoreVertexProgram(ai.grakn.graql.internal.analytics.KCoreVertexProgram) CountMapReduceWithAttribute(ai.grakn.graql.internal.analytics.CountMapReduceWithAttribute) Label(ai.grakn.concept.Label) LabelId(ai.grakn.concept.LabelId) Map(java.util.Map) CorenessVertexProgram(ai.grakn.graql.internal.analytics.CorenessVertexProgram) ComputeQuery(ai.grakn.graql.ComputeQuery) ConceptId(ai.grakn.concept.ConceptId) MinQuery(ai.grakn.graql.analytics.MinQuery) CorenessQuery(ai.grakn.graql.analytics.CorenessQuery) MaxQuery(ai.grakn.graql.analytics.MaxQuery) ConnectedComponentVertexProgram(ai.grakn.graql.internal.analytics.ConnectedComponentVertexProgram) Set(java.util.Set) DegreeStatisticsVertexProgram(ai.grakn.graql.internal.analytics.DegreeStatisticsVertexProgram) GraknMapReduce(ai.grakn.graql.internal.analytics.GraknMapReduce) MeanMapReduce(ai.grakn.graql.internal.analytics.MeanMapReduce) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SumMapReduce(ai.grakn.graql.internal.analytics.SumMapReduce) Serializable(java.io.Serializable) List(java.util.List) Memory(org.apache.tinkerpop.gremlin.process.computer.Memory) MedianVertexProgram(ai.grakn.graql.internal.analytics.MedianVertexProgram) Optional(java.util.Optional) DegreeDistributionMapReduce(ai.grakn.graql.internal.analytics.DegreeDistributionMapReduce) DegreeQuery(ai.grakn.graql.analytics.DegreeQuery) ComputeJob(ai.grakn.ComputeJob) StdQuery(ai.grakn.graql.analytics.StdQuery) Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) StatisticsQuery(ai.grakn.graql.StatisticsQuery) ConnectedComponentsVertexProgram(ai.grakn.graql.internal.analytics.ConnectedComponentsVertexProgram) ClusterSizeMapReduce(ai.grakn.graql.internal.analytics.ClusterSizeMapReduce) PathQuery(ai.grakn.graql.analytics.PathQuery) AttributeType(ai.grakn.concept.AttributeType) NoResultException(ai.grakn.graql.internal.analytics.NoResultException) GraknComputer(ai.grakn.GraknComputer) MeanQuery(ai.grakn.graql.analytics.MeanQuery) ComputerResult(org.apache.tinkerpop.gremlin.process.computer.ComputerResult) GraknVertexProgram(ai.grakn.graql.internal.analytics.GraknVertexProgram) SumQuery(ai.grakn.graql.analytics.SumQuery) GraqlQueryException(ai.grakn.exception.GraqlQueryException) DegreeVertexProgram(ai.grakn.graql.internal.analytics.DegreeVertexProgram) Logger(org.slf4j.Logger) ShortestPathVertexProgram(ai.grakn.graql.internal.analytics.ShortestPathVertexProgram) MedianQuery(ai.grakn.graql.analytics.MedianQuery) MinMapReduce(ai.grakn.graql.internal.analytics.MinMapReduce) CountVertexProgram(ai.grakn.graql.internal.analytics.CountVertexProgram) ClusterMemberMapReduce(ai.grakn.graql.internal.analytics.ClusterMemberMapReduce) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) CountQuery(ai.grakn.graql.analytics.CountQuery) PathsQuery(ai.grakn.graql.analytics.PathsQuery) KCoreQuery(ai.grakn.graql.analytics.KCoreQuery) MapReduce(org.apache.tinkerpop.gremlin.process.computer.MapReduce) StdMapReduce(ai.grakn.graql.internal.analytics.StdMapReduce) Collections(java.util.Collections) Type(ai.grakn.concept.Type) AttributeType(ai.grakn.concept.AttributeType) DegreeDistributionMapReduce(ai.grakn.graql.internal.analytics.DegreeDistributionMapReduce) ComputerResult(org.apache.tinkerpop.gremlin.process.computer.ComputerResult) Label(ai.grakn.concept.Label) DegreeVertexProgram(ai.grakn.graql.internal.analytics.DegreeVertexProgram) SchemaConcept(ai.grakn.concept.SchemaConcept) LabelId(ai.grakn.concept.LabelId)

Aggregations

SchemaConcept (ai.grakn.concept.SchemaConcept)51 Label (ai.grakn.concept.Label)19 Set (java.util.Set)15 Type (ai.grakn.concept.Type)14 GraknTx (ai.grakn.GraknTx)12 HashSet (java.util.HashSet)12 ConceptId (ai.grakn.concept.ConceptId)11 Stream (java.util.stream.Stream)11 Test (org.junit.Test)11 AttributeType (ai.grakn.concept.AttributeType)10 Property (com.pholser.junit.quickcheck.Property)10 Role (ai.grakn.concept.Role)9 Concept (ai.grakn.concept.Concept)8 Sets (com.google.common.collect.Sets)8 Optional (java.util.Optional)8 RelationshipType (ai.grakn.concept.RelationshipType)7 Rule (ai.grakn.concept.Rule)7 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)7 ErrorMessage (ai.grakn.util.ErrorMessage)7 Var (ai.grakn.graql.Var)6