Search in sources :

Example 31 with Label

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

the class SchemaConceptTest method whenChangingTheLabelOfSchemaConceptAndThatLabelIsTakenByAnotherConcept_Throw.

@Test
public void whenChangingTheLabelOfSchemaConceptAndThatLabelIsTakenByAnotherConcept_Throw() {
    Label label = Label.of("mylabel");
    EntityType e1 = tx.putEntityType("Entity1");
    tx.putEntityType(label);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(ErrorMessage.LABEL_TAKEN.getMessage(label));
    e1.setLabel(label);
}
Also used : EntityType(ai.grakn.concept.EntityType) Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 32 with Label

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

the class GrpcServerIT method whenDeletingAConcept_TheConceptIsDeleted.

@Test
public void whenDeletingAConcept_TheConceptIsDeleted() {
    Label label = Label.of("hello");
    try (GraknTx tx = localSession.open(GraknTxType.WRITE)) {
        tx.putEntityType(label);
        tx.commit();
    }
    try (GraknTx tx = remoteSession.open(GraknTxType.WRITE)) {
        SchemaConcept schemaConcept = tx.getSchemaConcept(label);
        assertFalse(schemaConcept.isDeleted());
        schemaConcept.delete();
        assertTrue(schemaConcept.isDeleted());
        tx.commit();
    }
    try (GraknTx tx = localSession.open(GraknTxType.WRITE)) {
        assertNull(tx.getSchemaConcept(label));
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept) Test(org.junit.Test)

Example 33 with Label

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

the class Labels method generateFromTx.

@Override
public Label generateFromTx() {
    if (mustBeUnused) {
        Label label;
        int attempts = 0;
        do {
            // After a certain number of attempts, generate truly random strings instead
            if (attempts < 100) {
                label = metaSyntacticLabel();
            } else {
                label = trueRandomLabel();
            }
            attempts += 1;
        } while (tx().getSchemaConcept(label) != null);
        return label;
    } else {
        return metaSyntacticLabel();
    }
}
Also used : Label(ai.grakn.concept.Label)

Example 34 with Label

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

the class HasAttributePropertyTest method whenCallingCheckValidPropertyAndLabelRefersToARole_Throw.

@Test
public void whenCallingCheckValidPropertyAndLabelRefersToARole_Throw() {
    Label label = Schema.MetaSchema.ROLE.getLabel();
    HasAttributeProperty property = HasAttributeProperty.of(label, var("x").admin(), var().admin());
    exception.expect(GraqlQueryException.class);
    exception.expectMessage(GraqlQueryException.mustBeAttributeType(label).getMessage());
    property.checkValidProperty(sampleKB.tx(), var("y").admin());
}
Also used : Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 35 with Label

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

the class AdminTest method testGetTypesInQuery.

@Test
public void testGetTypesInQuery() {
    Match match = qb.match(var("x").isa(label("movie").sub("production")).has("tmdb-vote-count", 400), var("y").isa("character"), var().rel("production-with-cast", "x").rel("y").isa("has-cast"));
    Set<SchemaConcept> types = Stream.of("movie", "production", "tmdb-vote-count", "character", "production-with-cast", "has-cast").map(t -> rule.tx().<SchemaConcept>getSchemaConcept(Label.of(t))).collect(toSet());
    assertEquals(types, match.admin().getSchemaConcepts());
}
Also used : PatternAdmin(ai.grakn.graql.admin.PatternAdmin) DeleteQuery(ai.grakn.graql.DeleteQuery) SchemaConcept(ai.grakn.concept.SchemaConcept) InsertQuery(ai.grakn.graql.InsertQuery) Graql(ai.grakn.graql.Graql) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) Label(ai.grakn.concept.Label) ConceptId(ai.grakn.concept.ConceptId) ClassRule(org.junit.ClassRule) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) QueryBuilder(ai.grakn.graql.QueryBuilder) Graql.var(ai.grakn.graql.Graql.var) Conjunction(ai.grakn.graql.admin.Conjunction) Set(java.util.Set) Test(org.junit.Test) Graql.label(ai.grakn.graql.Graql.label) Sets(com.google.common.collect.Sets) MovieKB(ai.grakn.test.kbs.MovieKB) Match(ai.grakn.graql.Match) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) SampleKBContext(ai.grakn.test.rule.SampleKBContext) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) SchemaConcept(ai.grakn.concept.SchemaConcept) Match(ai.grakn.graql.Match) Test(org.junit.Test)

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