use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.
the class TypeAdjacencyImpl method put.
@Override
public TypeEdge put(Encoding.Edge.Type encoding, TypeVertex adjacent) {
assert !owner.isDeleted();
TypeVertex from = isOut() ? owner : adjacent;
TypeVertex to = isOut() ? adjacent : owner;
TypeEdgeImpl edge = new TypeEdgeImpl.Buffered(encoding, from, to);
edges.computeIfAbsent(encoding, e -> new ConcurrentSkipListSet<>()).add(getView(edge));
if (isOut())
((TypeAdjacencyImpl<?>) to.ins()).putNonRecursive(edge);
else
((TypeAdjacencyImpl<?>) from.outs()).putNonRecursive(edge);
owner.setModified();
return edge;
}
use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.
the class RelationIterator method createIterator.
private Forwardable<ThingVertex, Order.Asc> createIterator(int pos) {
StructureEdge<?, ?> edge = edges.get(pos);
ThingVertex player = answer.get(edge.to().id().asVariable().asRetrievable()).asThing();
return SortedIterators.Forwardable.merge(iterate(edge.asNative().asRolePlayer().types()).map(roleLabel -> {
TypeVertex roleVertex = graphMgr.schema().getType(roleLabel);
return player.ins().edge(ROLEPLAYER, roleVertex).fromAndOptimised().filter(relRole -> relationTypes.contains(relRole.key().type().properLabel()));
}), ASC).filter(relRole -> !scoped.contains(relRole.value())).mapSorted(relRole -> {
scoped.record(pos, relRole.value());
return relRole.key();
}, relation -> new KeyValue<>(relation, null), ASC);
}
use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.
the class EncodingTest method expectedAttributeIID.
private ByteArray expectedAttributeIID(GraphManager graphMgr, Label attributeTypeLabel, long attributeValue) {
TypeVertex type = graphMgr.schema().getType(attributeTypeLabel);
assertTrue(type.isAttributeType());
return ByteArray.join(ATTRIBUTE.prefix().bytes(), type.iid().bytes(), Encoding.ValueType.LONG.bytes(), encodeLongAsSorted(attributeValue));
}
use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.
the class EncodingTest method expectedAttributeIID.
private ByteArray expectedAttributeIID(GraphManager graphMgr, Label attributeTypeLabel, String attributeValue) {
TypeVertex type = graphMgr.schema().getType(attributeTypeLabel);
assertTrue(type.isAttributeType());
try {
return ByteArray.join(ATTRIBUTE.prefix().bytes(), type.iid().bytes(), Encoding.ValueType.STRING.bytes(), encodeStringAsSorted(attributeValue, STRING_ENCODING));
} catch (TypeDBCheckedException e) {
throw TypeDBException.of(e);
}
}
use of com.vaticle.typedb.core.graph.vertex.TypeVertex in project grakn by graknlabs.
the class RelationTypeImpl method getRelates.
/**
* Get the role type with a given {@code roleLabel} related by this relation type.
*
* First, look up the role type by the given label and it's scope: the relation label.
* If the role type vertex do not exist, then call {@code role()} to get the inherited role types,
* and see if the any of them has the {@code roleLabel} of interest.
*
* @param roleLabel the label of the role
* @return the role type related in this relation
*/
@Override
public RoleTypeImpl getRelates(String roleLabel) {
Optional<RoleTypeImpl> roleType;
TypeVertex roleTypeVertex = graphMgr.schema().getType(roleLabel, vertex.label());
if (roleTypeVertex != null) {
return RoleTypeImpl.of(graphMgr, roleTypeVertex);
} else if ((roleType = getRelates().filter(role -> role.getLabel().name().equals(roleLabel)).first()).isPresent()) {
return roleType.get();
} else
return null;
}
Aggregations