Search in sources :

Example 31 with Concept

use of com.vaticle.typedb.core.concept.Concept in project grakn by graknlabs.

the class Mapping method transform.

public ConceptMap transform(ConceptMap conceptMap) {
    Map<Retrievable, Concept> transformed = new HashMap<>();
    for (Map.Entry<Retrievable, ? extends Concept> entry : conceptMap.concepts().entrySet()) {
        Retrievable id = entry.getKey();
        Retrievable mapped = mapping.get(id);
        if (mapped != null) {
            Concept concept = entry.getValue();
            transformed.put(mapped, concept);
        }
    }
    return new ConceptMap(transformed);
}
Also used : Concept(com.vaticle.typedb.core.concept.Concept) Retrievable(com.vaticle.typedb.core.traversal.common.Identifier.Variable.Retrievable) HashMap(java.util.HashMap) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Map(java.util.Map) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) HashMap(java.util.HashMap)

Example 32 with Concept

use of com.vaticle.typedb.core.concept.Concept in project grakn by graknlabs.

the class Resolver method compatibleBounds.

private Optional<ConceptMap> compatibleBounds(Conjunction conjunction, ConceptMap bounds) {
    Map<Retrievable, Concept> newBounds = new HashMap<>();
    for (Map.Entry<Retrievable, ? extends Concept> entry : bounds.concepts().entrySet()) {
        Retrievable id = entry.getKey();
        Concept bound = entry.getValue();
        Variable conjVariable = conjunction.variable(id);
        assert conjVariable != null;
        if (conjVariable.isThing()) {
            if (!conjVariable.asThing().iid().isPresent())
                newBounds.put(id, bound);
            else if (!conjVariable.asThing().iid().get().iid().equals(bound.asThing().getIID())) {
                return Optional.empty();
            }
        } else if (conjVariable.isType()) {
            if (!conjVariable.asType().label().isPresent())
                newBounds.put(id, bound);
            else if (!conjVariable.asType().label().get().properLabel().equals(bound.asType().getLabel())) {
                return Optional.empty();
            }
        } else {
            throw TypeDBException.of(ILLEGAL_STATE);
        }
    }
    return Optional.of(new ConceptMap(newBounds));
}
Also used : Concept(com.vaticle.typedb.core.concept.Concept) Variable(com.vaticle.typedb.core.pattern.variable.Variable) Retrievable(com.vaticle.typedb.core.traversal.common.Identifier.Variable.Retrievable) HashMap(java.util.HashMap) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) HashMap(java.util.HashMap) Map(java.util.Map) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap)

Aggregations

Concept (com.vaticle.typedb.core.concept.Concept)32 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)31 HashMap (java.util.HashMap)29 Test (org.junit.Test)23 Set (java.util.Set)20 Rule (com.vaticle.typedb.core.logic.Rule)17 Util.createRule (com.vaticle.typedb.core.logic.resolvable.Util.createRule)17 Variable (com.vaticle.typedb.core.traversal.common.Identifier.Variable)11 HashSet (java.util.HashSet)11 Map (java.util.Map)11 Relation (com.vaticle.typedb.core.concept.thing.Relation)8 Thing (com.vaticle.typedb.core.concept.thing.Thing)8 Retrievable (com.vaticle.typedb.core.traversal.common.Identifier.Variable.Retrievable)5 Collections.set (com.vaticle.typedb.common.collection.Collections.set)4 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)4 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)4 Label (com.vaticle.typedb.core.common.parameters.Label)4 ThingType (com.vaticle.typedb.core.concept.type.ThingType)4 Type (com.vaticle.typedb.core.concept.type.Type)4 Lists (com.google.common.collect.Lists)3