Search in sources :

Example 41 with Thing

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

the class RelationshipImpl method reify.

/**
 * Reifys and returns the {@link RelationshipReified}
 */
public RelationshipReified reify() {
    if (relationshipStructure.isReified())
        return relationshipStructure.reify();
    // Get the role players to transfer
    Map<Role, Set<Thing>> rolePlayers = structure().allRolePlayers();
    // Now Reify
    relationshipStructure = relationshipStructure.reify();
    // Transfer relationships
    rolePlayers.forEach((role, things) -> {
        Thing thing = Iterables.getOnlyElement(things);
        addRolePlayer(role, thing);
    });
    return relationshipStructure.reify();
}
Also used : Role(ai.grakn.concept.Role) Set(java.util.Set) Thing(ai.grakn.concept.Thing)

Example 42 with Thing

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

the class MatchTest method testMatchAllResourcesUsingResourceName.

@Test
public void testMatchAllResourcesUsingResourceName() {
    Match match = qb.match(var().has("title", "Godfather").has(Schema.MetaSchema.ATTRIBUTE.getLabel().getValue(), x));
    Thing godfather = movieKB.tx().getAttributeType("title").getAttribute("Godfather").owner();
    Set<Attribute<?>> expected = godfather.attributes().collect(toSet());
    Set<Attribute<?>> results = match.get(x).map(Concept::asAttribute).collect(toSet());
    assertEquals(expected, results);
}
Also used : Attribute(ai.grakn.concept.Attribute) Thing(ai.grakn.concept.Thing) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 43 with Thing

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

the class QueryErrorTest method whenTryingToSetExistingInstanceType_Throw.

@Test
public void whenTryingToSetExistingInstanceType_Throw() {
    Thing movie = rule.tx().getEntityType("movie").instances().iterator().next();
    Type person = rule.tx().getEntityType("person");
    exception.expect(GraqlQueryException.class);
    exception.expectMessage(containsString("person"));
    qb.match(var("x").id(movie.getId())).insert(var("x").isa(label(person.getLabel()))).execute();
}
Also used : Type(ai.grakn.concept.Type) AttributeType(ai.grakn.concept.AttributeType) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 44 with Thing

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

the class GraqlPrinterTest method testResourceOutputWithResource.

// allOf accepts an array with generics
@SuppressWarnings("unchecked")
@Test
public void testResourceOutputWithResource() {
    Printer printer = Printers.graql(true, rule.tx().getAttributeType("title"), rule.tx().getAttributeType("tmdb-vote-count"), rule.tx().getAttributeType("name"));
    Thing godfather = rule.tx().getAttributeType("title").getAttribute("Godfather").owner();
    String repr = printer.graqlString(godfather);
    assertThat(repr, allOf(containsString("movie"), containsString("has"), containsString("title"), containsString("\"Godfather\""), containsString("tmdb-vote-count"), containsString("1000"), not(containsString("name"))));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Printer(ai.grakn.graql.Printer) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 45 with Thing

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

the class GraqlPrinterTest method testResourceOutputNoResources.

@Test
public void testResourceOutputNoResources() {
    Printer printer = Printers.graql(true);
    Thing godfather = rule.tx().getAttributeType("title").getAttribute("Godfather").owner();
    String repr = printer.graqlString(godfather);
    assertThat(repr, allOf(containsString("movie"), not(containsString("title")), not(containsString("Godfather"))));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Printer(ai.grakn.graql.Printer) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Aggregations

Thing (ai.grakn.concept.Thing)47 Role (ai.grakn.concept.Role)30 Test (org.junit.Test)29 RelationshipType (ai.grakn.concept.RelationshipType)17 EntityType (ai.grakn.concept.EntityType)14 Relationship (ai.grakn.concept.Relationship)12 HashSet (java.util.HashSet)9 Set (java.util.Set)9 GraknTx (ai.grakn.GraknTx)7 Attribute (ai.grakn.concept.Attribute)7 ConceptId (ai.grakn.concept.ConceptId)7 AttributeType (ai.grakn.concept.AttributeType)6 Concept (ai.grakn.concept.Concept)6 Entity (ai.grakn.concept.Entity)6 Collectors (java.util.stream.Collectors)5 Label (ai.grakn.concept.Label)4 Schema (ai.grakn.util.Schema)4 Collection (java.util.Collection)4 Map (java.util.Map)4 GraknSession (ai.grakn.GraknSession)3