def get_relation_type(self): method = concept_proto.Type.Req() method.role_type_get_relation_type_req.CopyFrom( concept_proto.RoleType.GetRelationType.Req()) return concept_proto_reader.type_( self._execute( method).role_type_get_relation_type_res.relation_type)
def _type_stream(self, method: concept_proto.Thing.Req, type_list_getter: Callable[[concept_proto.Thing.Res], List[concept_proto.Type]]): method.iid = concept_proto_builder.iid(self.get_iid()) request = transaction_proto.Transaction.Req() request.thing_req.CopyFrom(method) return map( lambda type_proto: concept_proto_reader.type_(type_proto), self._transaction._stream( request, lambda res: type_list_getter(res.thing_res)))
def get_relates(self, role_label: str = None): method = concept_proto.Type.Req() if role_label: get_relates_req = concept_proto.RelationType.GetRelatesForRoleLabel.Req() get_relates_req.label = role_label method.relation_type_get_relates_for_role_label_req.CopyFrom(get_relates_req) res = self._execute(method).relation_type_get_relates_for_role_label_res return concept_proto_reader.type_(res.role_type) if res.HasField("role_type") else None else: method.relation_type_get_relates_req.CopyFrom(concept_proto.RelationType.GetRelates.Req()) return self._type_stream(method, lambda res: res.relation_type_get_relates_res.roles)
def _of(concept_map_proto: answer_proto.ConceptMap): variable_map = {} for res_var in concept_map_proto.map: res_concept = concept_map_proto.map[res_var] if res_concept.HasField(ConceptMap._THING): concept = concept_proto_reader.thing(res_concept.thing) else: concept = concept_proto_reader.type_(res_concept.type) variable_map[res_var] = concept query_pattern = None if concept_map_proto.pattern == "" else concept_map_proto.pattern return ConceptMap(variable_map, query_pattern)
def get_players_by_role_type(self): method = concept_proto.Thing.Req() method.relation_get_players_by_role_type_req.CopyFrom(concept_proto.Relation.GetPlayersByRoleType.Req()) method.iid = concept_proto_builder.iid(self.get_iid()) request = transaction_proto.Transaction.Req() request.thing_req.CopyFrom(method) stream = self._transaction._stream(request, lambda res: res.thing_res.relation_get_players_by_role_type_res.role_types_with_players) role_player_dict = {} for role_player in stream: role = concept_proto_reader.type_(role_player.role_type) player = concept_proto_reader.thing(role_player.player) if role not in role_player_dict: role_player_dict[role] = [] role_player_dict[role].append(player) return role_player_dict
def get_supertype(self): req = concept_proto.Type.Req() req.type_get_supertype_req.CopyFrom(concept_proto.Type.GetSupertype.Req()) res = self._execute(req).type_get_supertype_res return concept_proto_reader.type_(res.type) if res.WhichOneof("res") == "type" else None
def get_type(self): method = concept_proto.Thing.Req() method.thing_get_type_req.CopyFrom(concept_proto.Thing.GetType.Req()) return concept_proto_reader.type_( self._execute(method).thing_get_type_res.thing_type)