0

I am currently diving into the Grakn phone_calls examples for the Python client and are playing around a bit. What I currently try is to get only certain atrributes of a Grakn thing. The Python API documentation informs me to use thing.attributes(attribute_types) and states that attribute_types is supposed to be a list of AttributeTypes.

I tried the following passing a python list of AttributeTypes:

for attr in answer.attributes([transaction.get_schema_concept('first-name'), transaction.get_schema_concept('phone-number')]):
    print("  {}: {}".format(attr.type().label(), attr.value()))

Resulting in the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-277eb53a924b> in <module>()
     31                     print("{}. {}: {} - Type: {} - Thing: {}".format(i, answer.type().label(), answer.id, answer.is_type(), answer.is_thing()))
     32 
---> 33                     for attr in answer.attributes([transaction.get_schema_concept('first-name'), transaction.get_schema_concept('phone-number'), transaction.get_schema_concept('is-customer')]):
     34                         print("  {}: {}".format(attr.type().label(), attr.value()))
     35                     #for role in answer.roles():

~\Anaconda3\envs\grakn\lib\site-packages\grakn\service\Session\Concept\Concept.py in attributes(self, *attribute_types)
    481     def attributes(self, *attribute_types):
    482         """ Retrieve iterator of this Thing's attributes, filtered by optionally provided attribute types """
--> 483         attrs_req = RequestBuilder.ConceptMethod.Thing.attributes(attribute_types)
    484         method_response = self._tx_service.run_concept_method(self.id, attrs_req)
    485         from grakn.service.Session.util import ResponseReader

~\Anaconda3\envs\grakn\lib\site-packages\grakn\service\Session\util\RequestBuilder.py in attributes(attribute_types)
    549                 attributes_req = concept_messages.Thing.Attributes.Req()
    550                 for attribute_type_concept in attribute_types:
--> 551                     grpc_attr_type_concept = RequestBuilder.ConceptMethod._concept_to_grpc_concept(attribute_type_concept)
    552                     attributes_req.attributeTypes.extend([grpc_attr_type_concept])
    553                 concept_method_req = concept_messages.Method.Req()

~\Anaconda3\envs\grakn\lib\site-packages\grakn\service\Session\util\RequestBuilder.py in _concept_to_grpc_concept(concept)
    205             """ Takes a concept from ConceptHierarcy and converts to GRPC message """
    206             grpc_concept = concept_messages.Concept()
--> 207             grpc_concept.id = concept.id
    208             base_type_name = concept.base_type
    209             grpc_base_type = BaseTypeMapping.name_to_grpc_base_type[base_type_name]

AttributeError: 'list' object has no attribute 'id'
dmainz
  • 985
  • 7
  • 6

1 Answers1

0

The problem was that I missinterpreted list of AttributeTypes as a Python list, but instead could pass one or more AttributeTypes as parameters instead. For example:

for attr in answer.attributes(transaction.get_schema_concept('first-name'), transaction.get_schema_concept('phone-number'), transaction.get_schema_concept('is-customer')):
    print("  {}: {}".format(attr.type().label(), attr.value())) 

I hope that this will be of some help for other Grakn newbies.

dmainz
  • 985
  • 7
  • 6