use of com.vaticle.typedb.core.concept.thing.Attribute in project grakn by graknlabs.
the class ThingService method unsetHas.
private void unsetHas(Thing thing, ConceptProto.Thing protoAttribute, UUID reqID) {
Attribute attribute = getThing(protoAttribute).asAttribute();
thing.unsetHas(attribute);
transactionSvc.respond(unsetHasRes(reqID));
}
use of com.vaticle.typedb.core.concept.thing.Attribute in project grakn by graknlabs.
the class TypeService method get.
private void get(AttributeType attributeType, ConceptProto.Attribute.Value protoValue, UUID reqID) {
Attribute attribute;
switch(protoValue.getValueCase()) {
case STRING:
attribute = attributeType.asString().get(protoValue.getString());
break;
case DOUBLE:
attribute = attributeType.asDouble().get(protoValue.getDouble());
break;
case LONG:
attribute = attributeType.asLong().get(protoValue.getLong());
break;
case DATE_TIME:
LocalDateTime dateTime = ofEpochMilli(protoValue.getDateTime()).atOffset(UTC).toLocalDateTime();
attribute = attributeType.asDateTime().get(dateTime);
break;
case BOOLEAN:
attribute = attributeType.asBoolean().get(protoValue.getBoolean());
break;
case VALUE_NOT_SET:
default:
// TODO: Unify our exceptions - they should either all be TypeDBException or all be StatusRuntimeException
throw TypeDBException.of(BAD_VALUE_TYPE);
}
transactionSvc.respond(getRes(reqID, attribute));
}
use of com.vaticle.typedb.core.concept.thing.Attribute in project grakn by graknlabs.
the class RuleTest method rule_has_variable_materialises_when_missing.
@Test
public void rule_has_variable_materialises_when_missing() throws IOException {
Util.resetDirectory(dataDir);
try (CoreDatabaseManager databaseMgr = CoreDatabaseManager.open(options)) {
databaseMgr.create(database);
try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.SCHEMA)) {
try (CoreTransaction txn = session.transaction(Arguments.Transaction.Type.WRITE)) {
ConceptManager conceptMgr = txn.concepts();
EntityType milk = conceptMgr.putEntityType("milk");
AttributeType ageInDays = conceptMgr.putAttributeType("age-in-days", AttributeType.ValueType.LONG);
AttributeType isStillGood = conceptMgr.putAttributeType("is-still-good", AttributeType.ValueType.BOOLEAN);
milk.setOwns(ageInDays);
milk.setOwns(isStillGood);
txn.logic().putRule("old-milk-is-not-good", TypeQL.parsePattern("{ $x isa milk; $a 10 isa age-in-days; }").asConjunction(), TypeQL.parseVariable("$x has $a").asThing());
txn.commit();
}
}
try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
try (CoreTransaction txn = session.transaction(Arguments.Transaction.Type.WRITE)) {
ConceptManager conceptMgr = txn.concepts();
EntityType milk = conceptMgr.getEntityType("milk");
AttributeType ageInDays = conceptMgr.getAttributeType("age-in-days");
Entity milkInst = milk.create();
Attribute.Long ageInDays10 = ageInDays.asLong().put(10L);
Rule rule = txn.logic().getRule("old-milk-is-not-good");
ConceptMap whenAnswer = new ConceptMap(map(pair(Identifier.Variable.name("x"), milkInst), pair(Identifier.Variable.name("a"), ageInDays10)));
List<Map<Identifier.Variable, Concept>> materialisations = rule.conclusion().materialise(whenAnswer, txn.traversal(), conceptMgr).toList();
assertEquals(1, materialisations.size());
assertEquals(2, materialisations.get(0).size());
List<? extends Attribute> ageInDaysOwned = milkInst.getHas(ageInDays).toList();
assertEquals(1, ageInDaysOwned.size());
assertEquals(ageInDays10, ageInDaysOwned.get(0));
}
}
}
}
Aggregations