def _create_answer_group(tx_service, grpc_answer_group):
     grpc_owner_concept = grpc_answer_group.owner
     owner_concept = ConceptFactory.create_local_concept(grpc_owner_concept)
     grpc_answers = list(grpc_answer_group.answers)
     answer_list = [
         AnswerConverter.convert(tx_service, grpc_answer)
         for grpc_answer in grpc_answers
     ]
     return AnswerGroup(owner_concept, answer_list)
 def create_explanation(tx_service, grpc_explanation_res):
     """ Convert gRPC explanation response to explanation object """
     grpc_list_of_concept_maps = grpc_explanation_res.explanation
     native_list_of_concept_maps = []
     for grpc_concept_map in grpc_list_of_concept_maps:
         native_list_of_concept_maps.append(
             AnswerConverter._create_concept_map(tx_service,
                                                 grpc_concept_map))
     rule = ConceptFactory.create_local_concept(grpc_explanation_res.rule)
     if len(rule.id) == 0:
         rule = None
     return Explanation(native_list_of_concept_maps, rule)
    def _create_concept_map(tx_service, grpc_concept_map_msg):
        """ Create a Concept Dictionary from the grpc response """
        var_concept_map = grpc_concept_map_msg.map
        answer_map = {}
        for (variable, grpc_concept) in var_concept_map.items():
            answer_map[variable] = ConceptFactory.create_local_concept(
                grpc_concept)

        query_pattern = grpc_concept_map_msg.pattern
        has_explanation = grpc_concept_map_msg.hasExplanation

        return ConceptMap(answer_map, query_pattern, has_explanation,
                          tx_service)
예제 #4
0
 def __init__(self, grpc_concept):
     super(Thing, self).__init__(grpc_concept)
     self._inferred = grpc_concept.inferred_res.inferred
     from grakn.service.Session.Concept import ConceptFactory
     self._type = ConceptFactory.create_local_concept(
         grpc_concept.type_res.type)