Search in sources :

Example 6 with Printer

use of ai.grakn.graql.Printer 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 7 with Printer

use of ai.grakn.graql.Printer in project grakn by graknlabs.

the class GraqlPrinterTest method whenPrintingWithColorizeTrue_ResultIsColored.

@Test
public void whenPrintingWithColorizeTrue_ResultIsColored() {
    Printer printer = Printers.graql(true);
    Type production = rule.tx().getEntityType("production");
    String productionString = printer.graqlString(production);
    assertThat(productionString, containsString("\u001B"));
}
Also used : Type(ai.grakn.concept.Type) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Printer(ai.grakn.graql.Printer) Test(org.junit.Test)

Example 8 with Printer

use of ai.grakn.graql.Printer in project grakn by graknlabs.

the class GraqlPrinterTest method testRelationOutput.

@Test
public void testRelationOutput() {
    Printer printer = Printers.graql(true);
    Match match = rule.tx().graql().match(var("r").isa("has-cast").rel(var().has("name", "Al Pacino")).rel(var().has("name", "Michael Corleone")).rel(var().has("title", "Godfather")));
    String relationString = printer.graqlString(match.get("r").iterator().next());
    assertThat(relationString, containsString("has-cast"));
    assertThat(relationString, containsString("actor"));
    assertThat(relationString, containsString("production-with-cast"));
    assertThat(relationString, containsString("character-being-played"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Printer(ai.grakn.graql.Printer) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 9 with Printer

use of ai.grakn.graql.Printer 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)

Example 10 with Printer

use of ai.grakn.graql.Printer in project grakn by graknlabs.

the class GraqlPrinterTest method whenGettingOutputForResource_IncludesValueOfResource.

@Test
public void whenGettingOutputForResource_IncludesValueOfResource() {
    Printer printer = Printers.graql(false);
    Match match = rule.tx().graql().match(var("x").isa("title").val("Godfather"));
    String result = printer.graqlString(match.iterator().next());
    assertEquals("$x val \"Godfather\" isa title;", result.trim());
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Printer(ai.grakn.graql.Printer) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Aggregations

Printer (ai.grakn.graql.Printer)14 Test (org.junit.Test)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 Type (ai.grakn.concept.Type)4 Match (ai.grakn.graql.Match)3 Thing (ai.grakn.concept.Thing)2 Relationship (ai.grakn.concept.Relationship)1 Role (ai.grakn.concept.Role)1 SchemaConcept (ai.grakn.concept.SchemaConcept)1 GetQuery (ai.grakn.graql.GetQuery)1 Query (ai.grakn.graql.Query)1 Answer (ai.grakn.graql.admin.Answer)1 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)1