use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class HasAttributeTypeProperty method mapToAtom.
@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
// NB: HasResourceType is a special case and it doesn't allow variables as resource types
Var varName = var.var().asUserDefined();
Label label = this.resourceType().getTypeLabel().orElse(null);
Var predicateVar = var().asUserDefined();
SchemaConcept schemaConcept = parent.tx().getSchemaConcept(label);
ConceptId predicateId = schemaConcept != null ? schemaConcept.getId() : null;
// isa part
VarPatternAdmin resVar = varName.has(Graql.label(label)).admin();
return HasAtom.create(resVar, predicateVar, predicateId, parent);
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class ConceptPropertyTest method whenCallingGetId_TheResultCanBeUsedToRetrieveTheSameConcept.
@Property
public void whenCallingGetId_TheResultCanBeUsedToRetrieveTheSameConcept(@Open GraknTx graph, @FromTx Concept concept) {
ConceptId id = concept.getId();
assertEquals(concept, graph.getConcept(id));
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class GraknTxPropertyTest method whenCallingGetConceptWithAnExistingConceptId_ItReturnsThatConcept.
@Property
public void whenCallingGetConceptWithAnExistingConceptId_ItReturnsThatConcept(@Open GraknTx graph, @FromTx Concept concept) {
ConceptId id = concept.getId();
assertEquals(concept, graph.getConcept(id));
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class TinkerComputeQueryRunner method run.
public <T> ComputeJob<T> run(ConnectedComponentQuery<T> query) {
return runCompute(query, tinkerComputeQuery -> {
if (!tinkerComputeQuery.selectedTypesHaveInstance()) {
LOG.info("Selected types don't have instances");
return (T) Collections.emptyMap();
}
Set<LabelId> subLabelIds = convertLabelsToIds(tinkerComputeQuery.subLabels());
GraknVertexProgram<?> vertexProgram;
if (query.sourceId().isPresent()) {
ConceptId conceptId = query.sourceId().get();
if (!tinkerComputeQuery.verticesExistInSubgraph(conceptId)) {
throw GraqlQueryException.instanceDoesNotExist();
}
vertexProgram = new ConnectedComponentVertexProgram(conceptId);
} else {
vertexProgram = new ConnectedComponentsVertexProgram();
}
Long clusterSize = query.clusterSize();
GraknMapReduce<?> mapReduce;
if (query.isMembersSet()) {
mapReduce = new ClusterMemberMapReduce(ConnectedComponentsVertexProgram.CLUSTER_LABEL, clusterSize);
} else {
mapReduce = new ClusterSizeMapReduce(ConnectedComponentsVertexProgram.CLUSTER_LABEL, clusterSize);
}
Memory memory = tinkerComputeQuery.compute(vertexProgram, mapReduce, subLabelIds).memory();
return memory.get(mapReduce.getClass().getName());
});
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class TinkerComputeQueryRunner method run.
public TinkerComputeJob<List<List<Concept>>> run(PathsQuery query) {
return runCompute(query, tinkerComputeQuery -> {
ConceptId sourceId = query.from();
ConceptId destinationId = query.to();
if (!tinkerComputeQuery.verticesExistInSubgraph(sourceId, destinationId)) {
throw GraqlQueryException.instanceDoesNotExist();
}
if (sourceId.equals(destinationId)) {
return Collections.singletonList(Collections.singletonList(tx.getConcept(sourceId)));
}
ComputerResult result;
Set<LabelId> subLabelIds = convertLabelsToIds(tinkerComputeQuery.subLabels());
try {
result = tinkerComputeQuery.compute(new ShortestPathVertexProgram(sourceId, destinationId), null, subLabelIds);
} catch (NoResultException e) {
return Collections.emptyList();
}
Multimap<Concept, Concept> predecessorMapFromSource = tinkerComputeQuery.getPredecessorMap(result);
List<List<Concept>> allPaths = tinkerComputeQuery.getAllPaths(predecessorMapFromSource, sourceId);
if (tinkerComputeQuery.isAttributeIncluded()) {
// this can be slow
return tinkerComputeQuery.getExtendedPaths(allPaths);
}
LOG.info("Number of paths: " + allPaths.size());
return allPaths;
});
}
Aggregations