Search in sources :

Example 6 with Attribute

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

the class CorenessTest method testImplicitTypeShouldBeIncluded.

@Test
public void testImplicitTypeShouldBeIncluded() {
    addSchemaAndEntities();
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        String aResourceTypeLabel = "aResourceTypeLabel";
        AttributeType<String> attributeType = graph.putAttributeType(aResourceTypeLabel, AttributeType.DataType.STRING);
        graph.getEntityType(thing).attribute(attributeType);
        graph.getEntityType(anotherThing).attribute(attributeType);
        Attribute Attribute1 = attributeType.putAttribute("blah");
        graph.getConcept(entityId1).asEntity().attribute(Attribute1);
        graph.getConcept(entityId2).asEntity().attribute(Attribute1);
        graph.getConcept(entityId3).asEntity().attribute(Attribute1);
        graph.getConcept(entityId4).asEntity().attribute(Attribute1);
        Attribute Attribute2 = attributeType.putAttribute("bah");
        graph.getConcept(entityId1).asEntity().attribute(Attribute2);
        graph.getConcept(entityId2).asEntity().attribute(Attribute2);
        graph.getConcept(entityId3).asEntity().attribute(Attribute2);
        graph.commit();
    }
    Map<Long, Set<String>> result;
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        result = graph.graql().compute().centrality().usingKCore().execute();
        System.out.println("result = " + result);
        assertEquals(2, result.size());
        assertEquals(5, result.get(4L).size());
        assertEquals(1, result.get(3L).size());
        result = graph.graql().compute().centrality().usingKCore().minK(4L).execute();
        assertEquals(1, result.size());
        assertEquals(5, result.get(4L).size());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Set(java.util.Set) Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

Example 7 with Attribute

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

the class KCoreTest method testImplicitTypeShouldBeExcluded.

@Test
public void testImplicitTypeShouldBeExcluded() {
    addSchemaAndEntities();
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        String aResourceTypeLabel = "aResourceTypeLabel";
        AttributeType<String> attributeType = graph.putAttributeType(aResourceTypeLabel, AttributeType.DataType.STRING);
        graph.getEntityType(thing).attribute(attributeType);
        Attribute aAttribute = attributeType.putAttribute("blah");
        graph.getConcept(entityId1).asEntity().attribute(aAttribute);
        graph.getConcept(entityId2).asEntity().attribute(aAttribute);
        graph.commit();
    }
    Map<String, Set<String>> result;
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        result = graph.graql().compute().cluster().usingKCore().includeAttribute().kValue(2L).execute();
        assertEquals(1, result.size());
        assertEquals(5, result.values().iterator().next().size());
        result = graph.graql().compute().cluster().usingKCore().kValue(3L).execute();
        assertEquals(1, result.size());
        assertEquals(4, result.values().iterator().next().size());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Set(java.util.Set) Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

Example 8 with Attribute

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

the class JsonMigratorMainTest method runAndAssertDataCorrect.

private void runAndAssertDataCorrect(String... args) {
    run(args);
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        EntityType personType = graph.getEntityType("person");
        assertEquals(1, personType.instances().count());
        Entity person = personType.instances().iterator().next();
        Entity address = getProperty(graph, person, "has-address").asEntity();
        Entity streetAddress = getProperty(graph, address, "address-has-street").asEntity();
        Attribute number = getResource(graph, streetAddress, Label.of("number"));
        assertEquals(21L, number.getValue());
        Collection<Thing> phoneNumbers = getProperties(graph, person, "has-phone");
        assertEquals(2, phoneNumbers.size());
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) Thing(ai.grakn.concept.Thing)

Example 9 with Attribute

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

the class AttributeTest method whenCreatingResource_EnsureTheResourcesDataTypeIsTheSameAsItsType.

@Test
public void whenCreatingResource_EnsureTheResourcesDataTypeIsTheSameAsItsType() throws Exception {
    AttributeType<String> attributeType = tx.putAttributeType("attributeType", AttributeType.DataType.STRING);
    Attribute attribute = attributeType.putAttribute("resource");
    assertEquals(AttributeType.DataType.STRING, attribute.dataType());
}
Also used : Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

Example 10 with Attribute

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

the class GrpcServerIT method whenGettingAnAttribute_TheInformationOnTheAttributeIsCorrect.

@Test
public void whenGettingAnAttribute_TheInformationOnTheAttributeIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x").isa("title")).get();
        Attribute<?> remoteConcept = query.stream().findAny().get().get("x").asAttribute();
        Attribute<?> localConcept = localTx.getConcept(remoteConcept.getId()).asAttribute();
        assertEquals(localConcept.dataType(), remoteConcept.dataType());
        assertEquals(localConcept.getValue(), remoteConcept.getValue());
        assertEquals(localConcept.owner().getId(), remoteConcept.owner().getId());
        assertEqualConcepts(localConcept, remoteConcept, Attribute::ownerInstances);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

Aggregations

Attribute (ai.grakn.concept.Attribute)36 Test (org.junit.Test)26 GraknTx (ai.grakn.GraknTx)15 EntityType (ai.grakn.concept.EntityType)15 Entity (ai.grakn.concept.Entity)14 RelationshipType (ai.grakn.concept.RelationshipType)10 Set (java.util.Set)10 Role (ai.grakn.concept.Role)9 AttributeType (ai.grakn.concept.AttributeType)8 Relationship (ai.grakn.concept.Relationship)8 Label (ai.grakn.concept.Label)7 Thing (ai.grakn.concept.Thing)6 Concept (ai.grakn.concept.Concept)5 HashSet (java.util.HashSet)5 ConceptId (ai.grakn.concept.ConceptId)4 Schema (ai.grakn.util.Schema)4 GraknTxOperationException (ai.grakn.exception.GraknTxOperationException)3 Sets (com.google.common.collect.Sets)3 Collection (java.util.Collection)3 Collectors (java.util.stream.Collectors)3