Search in sources :

Example 1 with Label

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

the class MigratorTestUtils method getResources.

public static Stream<Attribute> getResources(GraknTx graph, Thing thing, Label label) {
    Role roleOwner = graph.getSchemaConcept(Schema.ImplicitType.HAS_OWNER.getLabel(label));
    Role roleOther = graph.getSchemaConcept(Schema.ImplicitType.HAS_VALUE.getLabel(label));
    Stream<Relationship> relations = thing.relationships(roleOwner);
    return relations.flatMap(r -> r.rolePlayers(roleOther)).map(Concept::asAttribute);
}
Also used : Role(ai.grakn.concept.Role) InvalidKBException(ai.grakn.exception.InvalidKBException) Role(ai.grakn.concept.Role) Concept(ai.grakn.concept.Concept) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) HashSet(java.util.HashSet) Label(ai.grakn.concept.Label) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Files(com.google.common.io.Files) GraknTx(ai.grakn.GraknTx) Relationship(ai.grakn.concept.Relationship) GraknTxType(ai.grakn.GraknTxType) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) GraknSession(ai.grakn.GraknSession) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) Stream(java.util.stream.Stream) Thing(ai.grakn.concept.Thing) Schema(ai.grakn.util.Schema) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Concept(ai.grakn.concept.Concept) Relationship(ai.grakn.concept.Relationship)

Example 2 with Label

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

the class EntityTest method whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated.

@Test
public void whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated() {
    Label resourceLabel = Label.of("A Attribute Thing");
    EntityType entityType = tx.putEntityType("A Thing");
    AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
    entityType.attribute(attributeType);
    Entity entity = entityType.addEntity();
    Attribute attribute = attributeType.putAttribute("A attribute thing");
    entity.attribute(attribute);
    Relationship relationship = entity.relationships().iterator().next();
    checkImplicitStructure(attributeType, relationship, entity, Schema.ImplicitType.HAS, Schema.ImplicitType.HAS_OWNER, Schema.ImplicitType.HAS_VALUE);
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) Relationship(ai.grakn.concept.Relationship) Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 3 with Label

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

the class RelationshipAtom method validateRelationPlayers.

private Set<String> validateRelationPlayers(Rule rule) {
    Set<String> errors = new HashSet<>();
    getRelationPlayers().forEach(rp -> {
        VarPatternAdmin role = rp.getRole().orElse(null);
        if (role == null) {
            errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.getThen(), rule.getLabel()));
        } else {
            Label roleLabel = role.getTypeLabel().orElse(null);
            if (roleLabel == null) {
                errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.getThen(), rule.getLabel()));
            } else {
                if (Schema.MetaSchema.isMetaLabel(roleLabel)) {
                    errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_AMBIGUOUS_ROLE.getMessage(rule.getThen(), rule.getLabel()));
                }
                Role roleType = tx().getRole(roleLabel.getValue());
                if (roleType != null && roleType.isImplicit()) {
                    errors.add(ErrorMessage.VALIDATION_RULE_ILLEGAL_HEAD_RELATION_WITH_IMPLICIT_ROLE.getMessage(rule.getThen(), rule.getLabel()));
                }
            }
        }
    });
    return errors;
}
Also used : Role(ai.grakn.concept.Role) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Label(ai.grakn.concept.Label) HashSet(java.util.HashSet)

Example 4 with Label

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

the class ConceptBuilder method putSchemaConcept.

private SchemaConcept putSchemaConcept() {
    SchemaConcept superConcept = use(SUPER_CONCEPT);
    Label label = use(LABEL);
    SchemaConcept concept;
    if (superConcept.isEntityType()) {
        concept = executor.tx().putEntityType(label);
    } else if (superConcept.isRelationshipType()) {
        concept = executor.tx().putRelationshipType(label);
    } else if (superConcept.isRole()) {
        concept = executor.tx().putRole(label);
    } else if (superConcept.isAttributeType()) {
        AttributeType attributeType = superConcept.asAttributeType();
        AttributeType.DataType<?> dataType = useOrDefault(DATA_TYPE, attributeType.getDataType());
        concept = executor.tx().putAttributeType(label, dataType);
    } else if (superConcept.isRule()) {
        concept = executor.tx().putRule(label, use(WHEN), use(THEN));
    } else {
        throw GraqlQueryException.insertMetaType(label, superConcept);
    }
    setSuper(concept, superConcept);
    return concept;
}
Also used : AttributeType(ai.grakn.concept.AttributeType) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept)

Example 5 with Label

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

the class QueryVisitor method visitPropHas.

@Override
public UnaryOperator<VarPattern> visitPropHas(GraqlParser.PropHasContext ctx) {
    Label type = visitLabel(ctx.label());
    VarPattern relation = Optional.ofNullable(ctx.relation).map(this::getVariable).orElseGet(Graql::var);
    VarPattern resource = Optional.ofNullable(ctx.resource).map(this::getVariable).orElseGet(Graql::var);
    if (ctx.predicate() != null) {
        resource = resource.val(visitPredicate(ctx.predicate()));
    }
    VarPattern finalResource = resource;
    return var -> var.has(type, finalResource, relation);
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Token(org.antlr.v4.runtime.Token) Graql(ai.grakn.graql.Graql) ConnectedComponentQuery(ai.grakn.graql.analytics.ConnectedComponentQuery) UnaryOperator(java.util.function.UnaryOperator) Label(ai.grakn.concept.Label) Map(java.util.Map) ComputeQuery(ai.grakn.graql.ComputeQuery) ConceptId(ai.grakn.concept.ConceptId) Aggregate(ai.grakn.graql.Aggregate) MinQuery(ai.grakn.graql.analytics.MinQuery) Collectors.toSet(java.util.stream.Collectors.toSet) QueryBuilder(ai.grakn.graql.QueryBuilder) MaxQuery(ai.grakn.graql.analytics.MaxQuery) ImmutableSet(com.google.common.collect.ImmutableSet) AggregateQuery(ai.grakn.graql.AggregateQuery) ImmutableMap(com.google.common.collect.ImmutableMap) Graql.eq(ai.grakn.graql.Graql.eq) Collection(java.util.Collection) StringUtil(ai.grakn.util.StringUtil) Set(java.util.Set) ValuePredicate(ai.grakn.graql.ValuePredicate) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) Match(ai.grakn.graql.Match) List(java.util.List) GraqlParser(ai.grakn.graql.internal.antlr.GraqlParser) Stream(java.util.stream.Stream) LocalDate(java.time.LocalDate) Var(ai.grakn.graql.Var) DefineQuery(ai.grakn.graql.DefineQuery) Optional(java.util.Optional) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) DegreeQuery(ai.grakn.graql.analytics.DegreeQuery) DeleteQuery(ai.grakn.graql.DeleteQuery) GraqlBaseVisitor(ai.grakn.graql.internal.antlr.GraqlBaseVisitor) StdQuery(ai.grakn.graql.analytics.StdQuery) InsertQuery(ai.grakn.graql.InsertQuery) LocalDateTime(java.time.LocalDateTime) Function(java.util.function.Function) PathQuery(ai.grakn.graql.analytics.PathQuery) AttributeType(ai.grakn.concept.AttributeType) MeanQuery(ai.grakn.graql.analytics.MeanQuery) CommonUtil(ai.grakn.util.CommonUtil) SumQuery(ai.grakn.graql.analytics.SumQuery) GraqlQueryException(ai.grakn.exception.GraqlQueryException) Graql.label(ai.grakn.graql.Graql.label) GetQuery(ai.grakn.graql.GetQuery) Query(ai.grakn.graql.Query) MedianQuery(ai.grakn.graql.analytics.MedianQuery) Graql.and(ai.grakn.graql.Graql.and) Collectors.toList(java.util.stream.Collectors.toList) Order(ai.grakn.graql.Order) NamedAggregate(ai.grakn.graql.NamedAggregate) DateTimeFormatter(java.time.format.DateTimeFormatter) CountQuery(ai.grakn.graql.analytics.CountQuery) PathsQuery(ai.grakn.graql.analytics.PathsQuery) Pattern(ai.grakn.graql.Pattern) Label(ai.grakn.concept.Label) VarPattern(ai.grakn.graql.VarPattern) Graql(ai.grakn.graql.Graql)

Aggregations

Label (ai.grakn.concept.Label)87 Test (org.junit.Test)41 Role (ai.grakn.concept.Role)25 GraknTx (ai.grakn.GraknTx)22 ConceptId (ai.grakn.concept.ConceptId)21 Concept (ai.grakn.concept.Concept)20 Set (java.util.Set)20 RelationshipType (ai.grakn.concept.RelationshipType)19 SchemaConcept (ai.grakn.concept.SchemaConcept)19 AttributeType (ai.grakn.concept.AttributeType)17 EntityType (ai.grakn.concept.EntityType)17 Relationship (ai.grakn.concept.Relationship)14 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 Type (ai.grakn.concept.Type)12 Stream (java.util.stream.Stream)12 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)11 Schema (ai.grakn.util.Schema)11 Collection (java.util.Collection)11 Pattern (ai.grakn.graql.Pattern)10