/** * Check whether it is possible that there is a resource edge between the two given concepts. */ private static boolean mayHaveResourceEdge(GraknTx graknGraph, ConceptId conceptId1, ConceptId conceptId2) { Concept concept1 = graknGraph.getConcept(conceptId1); Concept concept2 = graknGraph.getConcept(conceptId2); return concept1 != null && concept2 != null && (concept1.isAttribute() || concept2.isAttribute()); }
public static GrpcConcept.BaseType getBaseType(Concept concept) { if (concept.isEntityType()) { return GrpcConcept.BaseType.EntityType; } else if (concept.isRelationshipType()) { return GrpcConcept.BaseType.RelationshipType; } else if (concept.isAttributeType()) { return GrpcConcept.BaseType.AttributeType; } else if (concept.isEntity()) { return GrpcConcept.BaseType.Entity; } else if (concept.isRelationship()) { return GrpcConcept.BaseType.Relationship; } else if (concept.isAttribute()) { return GrpcConcept.BaseType.Attribute; } else if (concept.isRole()) { return GrpcConcept.BaseType.Role; } else if (concept.isRule()) { return GrpcConcept.BaseType.Rule; } else if (concept.isType()) { return GrpcConcept.BaseType.MetaType; } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } }
/** * Helper class which filters a {@link Stream} of {@link Attribute} to those of a specific set of {@link AttributeType}. * * @param conceptStream The {@link Stream} to filter * @param attributeTypesIds The {@link AttributeType} {@link ConceptId}s to filter to. * @return the filtered stream */ private <X extends Concept> Stream<Attribute<?>> attributes(Stream<X> conceptStream, Set<ConceptId> attributeTypesIds){ Stream<Attribute<?>> attributeStream = conceptStream. filter(concept -> concept.isAttribute() && !this.equals(concept)). map(Concept::asAttribute); if(!attributeTypesIds.isEmpty()){ attributeStream = attributeStream.filter(attribute -> attributeTypesIds.contains(attribute.type().id())); } return attributeStream; }
private static ConceptProto.Concept.BASE_TYPE getBaseType(ai.grakn.concept.Concept concept) { if (concept.isEntityType()) { return ConceptProto.Concept.BASE_TYPE.ENTITY_TYPE; } else if (concept.isRelationshipType()) { return ConceptProto.Concept.BASE_TYPE.RELATION_TYPE; } else if (concept.isAttributeType()) { return ConceptProto.Concept.BASE_TYPE.ATTRIBUTE_TYPE; } else if (concept.isEntity()) { return ConceptProto.Concept.BASE_TYPE.ENTITY; } else if (concept.isRelationship()) { return ConceptProto.Concept.BASE_TYPE.RELATION; } else if (concept.isAttribute()) { return ConceptProto.Concept.BASE_TYPE.ATTRIBUTE; } else if (concept.isRole()) { return ConceptProto.Concept.BASE_TYPE.ROLE; } else if (concept.isRule()) { return ConceptProto.Concept.BASE_TYPE.RULE; } else if (concept.isType()) { return ConceptProto.Concept.BASE_TYPE.META_TYPE; } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } }
@Override public <V> Collection<Attribute<V>> getAttributesByValue(V value) { if (value == null) return Collections.emptySet(); //Make sure you trying to retrieve supported data type if (!AttributeType.DataType.SUPPORTED_TYPES.containsKey(value.getClass().getName())) { throw GraknTxOperationException.unsupportedDataType(value); } HashSet<Attribute<V>> attributes = new HashSet<>(); AttributeType.DataType dataType = AttributeType.DataType.SUPPORTED_TYPES.get(value.getClass().getTypeName()); //noinspection unchecked getConcepts(dataType.getVertexProperty(), dataType.getPersistenceValue(value)).forEach(concept -> { if (concept != null && concept.isAttribute()) { //noinspection unchecked attributes.add(concept.asAttribute()); } }); return attributes; }
List<List<ConceptId>> extendedPaths = new ArrayList<>(); for (List<ConceptId> currentPath : allPaths) { boolean hasAttribute = currentPath.stream().anyMatch(conceptID -> tx.getConcept(conceptID).isAttribute()); if (!hasAttribute) { extendedPaths.add(currentPath);
/** * * @param concept The concept to no longer track */ @SuppressWarnings("SuspiciousMethodCalls") public void remove(Concept concept){ modifiedThings.remove(concept); modifiedRoles.remove(concept); modifiedRelationshipTypes.remove(concept); modifiedRules.remove(concept); if(concept.isAttribute()) { newAttributes.removeAll(AttributeImpl.from(concept.asAttribute()).getIndex()); } if(concept.isRelationship()){ newRelationships.remove(concept.asRelationship()); } conceptCache.remove(concept.id()); if (concept.isSchemaConcept()) { Label label = concept.asSchemaConcept().label(); schemaConceptCache.remove(label); labelCache.remove(label); } }
if (concept.isAttribute()) { output.append(colorKeyword("val ")).append(StringUtil.valueToString(concept.asAttribute().value())); } else if (concept.isSchemaConcept()) {
@Override public String toString() { if (concept.isAttribute()) { return "hasValue(" + valueToString(concept.asAttribute().value()) + ")"; } else if (concept.isThing()) { Thing thing = concept.asThing(); Stream<Attribute<?>> resources = thing.attributes(); Optional<?> value = resources .filter(resource -> NAME_TYPES.contains(resource.type().label())) .map(Attribute::value).findFirst(); return "instance(" + value.map(StringUtil::valueToString).orElse("") + ") isa " + thing.type().label(); } else if (concept.isType()) { return "type(" + concept.asType().label() + ")"; } else if (concept.isRole()) { return "role(" + concept.asRole().label() + ")"; } else if (concept.isRule()) { return "rule(" + concept.asRule().label() + ")"; } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } }
private void attachAttribute(Concept owner, Attribute attribute){ if (owner.isEntity()){ EntityImpl.from(owner.asEntity()).attributeInferred(attribute); } else if (owner.isRelationship()){ RelationshipImpl.from(owner.asRelationship()).attributeInferred(attribute); } else if (owner.isAttribute()){ AttributeImpl.from(owner.asAttribute()).attributeInferred(attribute); } }
static Pattern toPattern(Concept concept) { if (!concept.isThing()){ throw GraqlQueryException.conceptNotAThing(concept); } if (concept.isEntity()) { return new EntityConverter().pattern(concept.asEntity()); } else if (concept.isRelationship()) { return new RelationshipConverter().pattern(concept.asRelationship()); } else if (concept.isAttribute()) { return new AttributeConverter().pattern(concept.asAttribute()); } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } }
@Override protected Json concept(Concept concept) { Json json = Json.object("id", concept.id().getValue()); if (concept.isSchemaConcept()) { json.set("name", concept.asSchemaConcept().label().getValue()); SchemaConcept superConcept = concept.asSchemaConcept().sup(); if (superConcept != null) json.set("sub", superConcept.label().getValue()); } else if (concept.isThing()) { json.set("isa", concept.asThing().type().label().getValue()); } else { throw CommonUtil.unreachableStatement("Unrecognised concept " + concept); } if (concept.isAttribute()) { json.set("value", concept.asAttribute().value()); } if (concept.isRule()) { Pattern when = concept.asRule().when(); if (when != null) { json.set("when", when.toString()); } Pattern then = concept.asRule().then(); if (then != null) { json.set("then", then.toString()); } } return json; }