Search in sources :

Example 1 with PathsQuery

use of ai.grakn.graql.analytics.PathsQuery in project grakn by graknlabs.

the class GraqlTest method testPaths.

@Test
public void testPaths() throws InvalidKBException {
    addSchemaAndEntities();
    try (GraknTx graph = session.open(GraknTxType.WRITE)) {
        PathsQuery query = graph.graql().parse("compute paths from '" + entityId1 + "' to '" + entityId2 + "';");
        List<List<Concept>> path = query.execute();
        assertEquals(1, path.size());
        List<String> result = path.get(0).stream().map(Concept::getId).map(ConceptId::getValue).collect(Collectors.toList());
        List<String> expected = Lists.newArrayList(entityId1, relationId12, entityId2);
        assertEquals(expected, result);
    }
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) PathsQuery(ai.grakn.graql.analytics.PathsQuery) List(java.util.List) Test(org.junit.Test)

Example 2 with PathsQuery

use of ai.grakn.graql.analytics.PathsQuery in project grakn by graknlabs.

the class TinkerComputeQueryRunner method run.

public ComputeJob<Optional<List<Concept>>> run(PathQuery query) {
    PathsQuery pathsQuery = tx.graql().compute().paths();
    if (query.isAttributeIncluded())
        pathsQuery = pathsQuery.includeAttribute();
    pathsQuery = pathsQuery.from(query.from()).to(query.to()).in(query.subLabels());
    return run(pathsQuery).map(result -> result.stream().findAny());
}
Also used : PathsQuery(ai.grakn.graql.analytics.PathsQuery)

Aggregations

PathsQuery (ai.grakn.graql.analytics.PathsQuery)2 GraknTx (ai.grakn.GraknTx)1 Concept (ai.grakn.concept.Concept)1 List (java.util.List)1 Test (org.junit.Test)1