コード例 #1
0
 def to_pair(iter_res):
     response = iter_res.relation_rolePlayersMap_iter_res
     from grakn.service.Session.Concept import ConceptFactory
     role = ConceptFactory.create_remote_concept(
         tx_service, response.role)
     from grakn.service.Session.Concept import ConceptFactory
     player = ConceptFactory.create_remote_concept(
         tx_service, response.player)
     return (role, player)
コード例 #2
0
 def sup(self, super_concept=None):
     """ 
     Get or set super schema concept.
     If used as a setter returns self
     """
     if super_concept is None:
         # get direct super schema concept
         get_sup_req = RequestBuilder.ConceptMethod.SchemaConcept.get_sup()
         method_response = self._tx_service.run_concept_method(
             self.id, get_sup_req)
         get_sup_response = method_response.schemaConcept_getSup_res
         # check if received a Null or Concept
         whichone = get_sup_response.WhichOneof('res')
         if whichone == 'schemaConcept':
             grpc_schema_concept = get_sup_response.schemaConcept
             from grakn.service.Session.Concept import ConceptFactory
             concept = ConceptFactory.create_remote_concept(
                 self._tx_service, grpc_schema_concept)
             return concept
         elif whichone == 'null':
             return None
         else:
             raise GraknError(
                 "Unknown response concent for getting super schema concept: {0}"
                 .format(whichone))
     else:
         # set direct super SchemaConcept of this SchemaConcept
         set_sup_req = RequestBuilder.ConceptMethod.SchemaConcept.set_sup(
             super_concept)
         method_response = self._tx_service.run_concept_method(
             self.id, set_sup_req)
         return self
コード例 #3
0
 def roles(self):
     """ Retrieve roles in this relation schema type """
     get_roles = RequestBuilder.ConceptMethod.RelationType.roles()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.relationType_roles_iter_res.role),
         self._tx_service.run_concept_iter_method(self.id, get_roles))
コード例 #4
0
 def relations(self, *roles):
     """ Get iterator this Thing's relations, filtered to the optionally provided roles """
     relations_req = RequestBuilder.ConceptMethod.Thing.relations(roles)
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.thing_relations_iter_res.relation),
         self._tx_service.run_concept_iter_method(self.id, relations_req))
コード例 #5
0
 def keys(self):
     """ Retrieve an iterator of attribute types that this Type uses as keys """
     keys_req = RequestBuilder.ConceptMethod.Type.keys()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.type_keys_iter_res.attributeType),
         self._tx_service.run_concept_iter_method(self.id, keys_req))
コード例 #6
0
 def playing(self):
     """ Retrieve iterator of roles played by this type """
     playing_req = RequestBuilder.ConceptMethod.Type.playing()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.type_playing_iter_res.role),
         self._tx_service.run_concept_iter_method(self.id, playing_req))
コード例 #7
0
 def instances(self):
     """ Retrieve all instances of this Type as an iterator """
     instances_req = RequestBuilder.ConceptMethod.Type.instances()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.type_instances_iter_res.thing),
         self._tx_service.run_concept_iter_method(self.id, instances_req))
コード例 #8
0
 def players(self):
     """ Retrieve an iterator of entities that play this role """
     players_req = RequestBuilder.ConceptMethod.Role.players()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.role_players_iter_res.type),
         self._tx_service.run_concept_iter_method(self.id, players_req))
コード例 #9
0
 def roles(self):
     """ Retrieve iterator of roles this Thing plays """
     roles_req = RequestBuilder.ConceptMethod.Thing.roles()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.thing_roles_iter_res.role),
         self._tx_service.run_concept_iter_method(self.id, roles_req))
コード例 #10
0
 def keys(self, *attribute_types):
     """ Retrieve iterator of keys (i.e. actual attributes) of this Thing, filtered by the optionally provided attribute types """
     keys_req = RequestBuilder.ConceptMethod.Thing.keys(attribute_types)
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.thing_keys_iter_res.attribute),
         self._tx_service.run_concept_iter_method(self.id, keys_req))
コード例 #11
0
 def owners(self):
     """ Retrieve entities that have this attribute value """
     owners_req = RequestBuilder.ConceptMethod.Attribute.owners()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.attribute_owners_iter_res.thing),
         self._tx_service.run_concept_iter_method(self.id, owners_req))
コード例 #12
0
 def type(self):
     """ Get the type (schema concept) of this Thing """
     type_req = RequestBuilder.ConceptMethod.Thing.type()
     method_response = self._tx_service.run_concept_method(
         self.id, type_req)
     from grakn.service.Session.Concept import ConceptFactory
     return ConceptFactory.create_remote_concept(
         self._tx_service, method_response.thing_type_res.type)
コード例 #13
0
 def sups(self):
     """ Retrieve the all supertypes (direct and higher level) of this schema concept as an iterator """
     sups_req = RequestBuilder.ConceptMethod.SchemaConcept.sups()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.schemaConcept_sups_iter_res.
             schemaConcept),
         self._tx_service.run_concept_iter_method(self.id, sups_req))
コード例 #14
0
 def subs(self):
     """ Retrieve the sub schema concepts of this schema concept, as an iterator """
     subs_req = RequestBuilder.ConceptMethod.SchemaConcept.subs()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.schemaConcept_subs_iter_res.
             schemaConcept),
         self._tx_service.run_concept_iter_method(self.id, subs_req))
コード例 #15
0
 def attributes(self):
     """ Retrieve all attributes attached to this Type as an iterator """
     attributes_req = RequestBuilder.ConceptMethod.Type.attributes()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.type_attributes_iter_res.
             attributeType),
         self._tx_service.run_concept_iter_method(self.id, attributes_req))
コード例 #16
0
 def relations(self):
     """ Retrieve relations that this role participates in, as an iterator """
     relations_req = RequestBuilder.ConceptMethod.Role.relations()
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.role_relations_iter_res.
             relationType),
         self._tx_service.run_concept_iter_method(self.id, relations_req))
コード例 #17
0
 def create(self):
     """ Instantiate an entity of the given type and return it """
     create_req = RequestBuilder.ConceptMethod.EntityType.create()
     method_response = self._tx_service.run_concept_method(
         self.id, create_req)
     grpc_entity_concept = method_response.entityType_create_res.entity
     from grakn.service.Session.Concept import ConceptFactory
     return ConceptFactory.create_remote_concept(self._tx_service,
                                                 grpc_entity_concept)
コード例 #18
0
 def create(self):
     """ Create an instance of a relation with this type """
     create_rel_inst_req = RequestBuilder.ConceptMethod.RelationType.create(
     )
     method_response = self._tx_service.run_concept_method(
         self.id, create_rel_inst_req)
     grpc_relation_concept = method_response.relationType_create_res.relation
     from grakn.service.Session.Concept import ConceptFactory
     return ConceptFactory.create_remote_concept(self._tx_service,
                                                 grpc_relation_concept)
コード例 #19
0
 def create(self, value):
     """ Create an instance with this AttributeType """
     self_value_type = self.value_type()
     create_inst_req = RequestBuilder.ConceptMethod.AttributeType.create(
         value, self_value_type)
     method_response = self._tx_service.run_concept_method(
         self.id, create_inst_req)
     grpc_attribute_concept = method_response.attributeType_create_res.attribute
     from grakn.service.Session.Concept import ConceptFactory
     return ConceptFactory.create_remote_concept(self._tx_service,
                                                 grpc_attribute_concept)
コード例 #20
0
 def role_players(self, *roles):
     """ Retrieve role players filtered by roles """
     role_players_req = RequestBuilder.ConceptMethod.Relation.role_players(
         roles)
     from grakn.service.Session.Concept import ConceptFactory
     return map(
         lambda iter_res: ConceptFactory.create_remote_concept(
             self._tx_service, iter_res.relation_rolePlayers_iter_res.thing
         ),
         self._tx_service.run_concept_iter_method(self.id,
                                                  role_players_req))
コード例 #21
0
 def get_schema_concept(tx_service, grpc_get_concept):
     which_one = grpc_get_concept.WhichOneof("res")
     if which_one == "schemaConcept":
         grpc_concept = grpc_get_concept.schemaConcept
         return ConceptFactory.create_remote_concept(
             tx_service, grpc_concept)
     elif which_one == "null":
         return None
     else:
         raise GraknError(
             "Unknown get_schema_concept response: {0}".format(which_one))
コード例 #22
0
 def attribute(self, value):
     """ Retrieve an attribute instance by value if it exists """
     self_value_type = self.value_type()
     get_attribute_req = RequestBuilder.ConceptMethod.AttributeType.attribute(
         value, self_value_type)
     method_response = self._tx_service.run_concept_method(
         self.id, get_attribute_req)
     response = method_response.attributeType_attribute_res
     whichone = response.WhichOneof('res')
     if whichone == 'attribute':
         from grakn.service.Session.Concept import ConceptFactory
         return ConceptFactory.create_remote_concept(
             self._tx_service, response.attribute)
     elif whichone == 'null':
         return None
     else:
         raise GraknError(
             "Unknown `res` key in AttributeType `attribute` response: {0}".
             format(whichone))
コード例 #23
0
 def put_entity_type(tx_service, grpc_put_entity_type):
     return ConceptFactory.create_remote_concept(
         tx_service, grpc_put_entity_type.entityType)
コード例 #24
0
 def put_relation_type(tx_service, grpc_put_relation_type):
     return ConceptFactory.create_remote_concept(
         tx_service, grpc_put_relation_type.relationType)
コード例 #25
0
 def put_attribute_type(tx_service, grpc_put_attribute_type):
     return ConceptFactory.create_remote_concept(
         tx_service, grpc_put_attribute_type.attributeType)
コード例 #26
0
 def put_rule(tx_service, grpc_put_rule):
     return ConceptFactory.create_remote_concept(tx_service,
                                                 grpc_put_rule.rule)
コード例 #27
0
 def get_attributes_by_value(tx_service):
     return lambda iterate_res: ConceptFactory.create_remote_concept(
         tx_service, iterate_res.getAttributes_iter_res.attribute)