Search in sources :

Example 46 with Label

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

the class GraknTxPropertyTest method whenCallingGetEntityType_TheResultIsTheSameAsGetSchemaConcept.

@Property
public void whenCallingGetEntityType_TheResultIsTheSameAsGetSchemaConcept(@Open GraknTx graph, @FromTx EntityType type) {
    Label label = type.getLabel();
    assertSameResult(() -> graph.getSchemaConcept(label), () -> graph.getEntityType(label.getValue()));
}
Also used : Label(ai.grakn.concept.Label) MetaSchema.isMetaLabel(ai.grakn.util.Schema.MetaSchema.isMetaLabel) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 47 with Label

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

the class GraknTxPropertyTest method whenCallingGetSchemaConceptWithAnExistingLabel_ItReturnsThatConcept.

@Property
public void whenCallingGetSchemaConceptWithAnExistingLabel_ItReturnsThatConcept(@Open GraknTx graph, @FromTx SchemaConcept concept) {
    Label label = concept.getLabel();
    assertEquals(concept, graph.getSchemaConcept(label));
}
Also used : Label(ai.grakn.concept.Label) MetaSchema.isMetaLabel(ai.grakn.util.Schema.MetaSchema.isMetaLabel) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 48 with Label

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

the class GraknTxPropertyTest method whenCallingGetResourceType_TheResultIsTheSameAsGetSchemaConcept.

@Property
public void whenCallingGetResourceType_TheResultIsTheSameAsGetSchemaConcept(@Open GraknTx graph, @FromTx AttributeType type) {
    Label label = type.getLabel();
    assertSameResult(() -> graph.getSchemaConcept(label), () -> graph.getAttributeType(label.getValue()));
}
Also used : Label(ai.grakn.concept.Label) MetaSchema.isMetaLabel(ai.grakn.util.Schema.MetaSchema.isMetaLabel) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 49 with Label

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

the class RolePlayerFragmentSetTest method whenLabelDoesNotReferToARole_DoNotApplyRoleOptimisation.

@Test
public void whenLabelDoesNotReferToARole_DoNotApplyRoleOptimisation() {
    Label movie = Label.of("movie");
    Collection<EquivalentFragmentSet> fragmentSets = Sets.newHashSet(EquivalentFragmentSets.rolePlayer(null, a, b, c, d), EquivalentFragmentSets.label(null, d, ImmutableSet.of(movie)));
    Collection<EquivalentFragmentSet> expected = Sets.newHashSet(fragmentSets);
    RolePlayerFragmentSet.ROLE_OPTIMISATION.apply(fragmentSets, sampleKB.tx());
    assertEquals(expected, fragmentSets);
}
Also used : Label(ai.grakn.concept.Label) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet) Test(org.junit.Test)

Example 50 with Label

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

the class DegreeTest method testDegreeTwoAttributes.

@Test
public void testDegreeTwoAttributes() throws InvalidKBException {
    // create a simple graph
    Role pet = tx.putRole("pet");
    Role owner = tx.putRole("owner");
    RelationshipType mansBestFriend = tx.putRelationshipType("mans-best-friend").relates(pet).relates(owner);
    EntityType person = tx.putEntityType("person").plays(owner);
    EntityType animal = tx.putEntityType("animal").plays(pet);
    AttributeType<String> name = tx.putAttributeType("name", AttributeType.DataType.STRING);
    AttributeType<String> altName = tx.putAttributeType("alternate-name", AttributeType.DataType.STRING);
    animal.attribute(name).attribute(altName);
    // add data to the graph
    Entity coco = animal.addEntity();
    Entity dave = person.addEntity();
    Attribute coconut = name.putAttribute("coconut");
    Attribute stinky = altName.putAttribute("stinky");
    mansBestFriend.addRelationship().addRolePlayer(owner, dave).addRolePlayer(pet, coco);
    coco.attribute(coconut).attribute(stinky);
    // manually compute the degree for small graph
    Map<Long, Set<String>> subgraphReferenceDegrees = new HashMap<>();
    subgraphReferenceDegrees.put(1L, Sets.newHashSet(coco.getId().getValue(), dave.getId().getValue()));
    // manually compute degree for almost full graph
    Map<Long, Set<String>> almostFullReferenceDegrees = new HashMap<>();
    almostFullReferenceDegrees.put(2L, Sets.newHashSet(coco.getId().getValue()));
    almostFullReferenceDegrees.put(1L, Sets.newHashSet(dave.getId().getValue(), coconut.getId().getValue()));
    // manually compute degrees
    Map<Long, Set<String>> fullReferenceDegrees = new HashMap<>();
    fullReferenceDegrees.put(3L, Sets.newHashSet(coco.getId().getValue()));
    fullReferenceDegrees.put(1L, Sets.newHashSet(dave.getId().getValue(), coconut.getId().getValue(), stinky.getId().getValue()));
    tx.commit();
    try (GraknTx graph = session.open(GraknTxType.READ)) {
        // create a subgraph excluding attributes and their relationship
        HashSet<Label> subGraphTypes = Sets.newHashSet(Label.of("animal"), Label.of("person"), Label.of("mans-best-friend"));
        Map<Long, Set<String>> degrees = graph.graql().compute().centrality().usingDegree().in(subGraphTypes).execute();
        assertEquals(subgraphReferenceDegrees, degrees);
        // create a subgraph excluding one attribute type only
        HashSet<Label> almostFullTypes = Sets.newHashSet(Label.of("animal"), Label.of("person"), Label.of("mans-best-friend"), Label.of("@has-name"), Label.of("name"));
        degrees = graph.graql().compute().centrality().usingDegree().in(almostFullTypes).execute();
        assertEquals(almostFullReferenceDegrees, degrees);
        // full graph
        degrees = graph.graql().compute().centrality().usingDegree().of().execute();
        assertEquals(fullReferenceDegrees, degrees);
    }
}
Also used : Entity(ai.grakn.concept.Entity) HashSet(java.util.HashSet) Set(java.util.Set) Attribute(ai.grakn.concept.Attribute) HashMap(java.util.HashMap) RelationshipType(ai.grakn.concept.RelationshipType) Label(ai.grakn.concept.Label) Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) GraknTx(ai.grakn.GraknTx) 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