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()));
}
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));
}
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()));
}
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);
}
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);
}
}
Aggregations