nodes: 0, module; 1, function_definition; 2, function_name:query_relations; 3, parameters; 4, block; 5, identifier:self; 6, identifier:environment_id; 7, identifier:collection_id; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, dictionary_splat_pattern; 15, expression_statement; 16, if_statement; 17, if_statement; 18, if_statement; 19, if_statement; 20, if_statement; 21, expression_statement; 22, if_statement; 23, expression_statement; 24, expression_statement; 25, expression_statement; 26, expression_statement; 27, expression_statement; 28, expression_statement; 29, return_statement; 30, identifier:entities; 31, None; 32, identifier:context; 33, None; 34, identifier:sort; 35, None; 36, identifier:filter; 37, None; 38, identifier:count; 39, None; 40, identifier:evidence_count; 41, None; 42, identifier:kwargs; 43, comment:"""
          Knowledge Graph relationship query.
  
          See the [Knowledge Graph
          documentation](https://cloud.ibm.com/docs/services/discovery?topic=discovery-kg#kg)
          for more details.
  
          :param str environment_id: The ID of the environment.
          :param str collection_id: The ID of the collection.
          :param list[QueryRelationsEntity] entities: An array of entities to find
          relationships for.
          :param QueryEntitiesContext context: Entity text to provide context for the
          queried entity and rank based on that association. For example, if you wanted to
          query the city of London in England your query would look for `London` with the
          context of `England`.
          :param str sort: The sorting method for the relationships, can be `score` or
          `frequency`. `frequency` is the number of unique times each entity is identified.
          The default is `score`. This parameter cannot be used in the same query as the
          **bias** parameter.
          :param QueryRelationsFilter filter:
          :param int count: The number of results to return. The default is `10`. The
          maximum is `1000`.
          :param int evidence_count: The number of evidence items to return for each result.
          The default is `0`. The maximum number of evidence items per query is 10,000.
          :param dict headers: A `dict` containing the request headers
          :return: A `DetailedResponse` containing the result, headers and HTTP status code.
          :rtype: DetailedResponse
          """; 44, comparison_operator:environment_id is None; 45, block; 46, comparison_operator:collection_id is None; 47, block; 48, comparison_operator:entities is not None; 49, block; 50, comparison_operator:context is not None; 51, block; 52, comparison_operator:filter is not None; 53, block; 54, assignment; 55, comparison_operator:'headers' in kwargs; 56, block; 57, assignment; 58, call; 59, assignment; 60, assignment; 61, assignment; 62, assignment; 63, identifier:response; 64, identifier:environment_id; 65, None; 66, raise_statement; 67, identifier:collection_id; 68, None; 69, raise_statement; 70, identifier:entities; 71, None; 72, expression_statement; 73, identifier:context; 74, None; 75, expression_statement; 76, identifier:filter; 77, None; 78, expression_statement; 79, identifier:headers; 80, dictionary; 81, string; 82, identifier:kwargs; 83, expression_statement; 84, identifier:sdk_headers; 85, call; 86, attribute; 87, argument_list; 88, identifier:params; 89, dictionary; 90, identifier:data; 91, dictionary; 92, identifier:url; 93, call; 94, identifier:response; 95, call; 96, call; 97, call; 98, assignment; 99, assignment; 100, assignment; 101, string_content:headers; 102, call; 103, identifier:get_sdk_headers; 104, argument_list; 105, identifier:headers; 106, identifier:update; 107, identifier:sdk_headers; 108, pair; 109, pair; 110, pair; 111, pair; 112, pair; 113, pair; 114, pair; 115, attribute; 116, argument_list; 117, attribute; 118, argument_list; 119, identifier:ValueError; 120, argument_list; 121, identifier:ValueError; 122, argument_list; 123, identifier:entities; 124, list_comprehension; 125, identifier:context; 126, call; 127, identifier:filter; 128, call; 129, attribute; 130, argument_list; 131, string; 132, string; 133, string; 134, string; 135, attribute; 136, string; 137, identifier:entities; 138, string; 139, identifier:context; 140, string; 141, identifier:sort; 142, string; 143, identifier:filter; 144, string; 145, identifier:count; 146, string; 147, identifier:evidence_count; 148, string; 149, identifier:format; 150, list_splat; 151, identifier:self; 152, identifier:request; 153, keyword_argument; 154, keyword_argument; 155, keyword_argument; 156, keyword_argument; 157, keyword_argument; 158, keyword_argument; 159, string; 160, string; 161, call; 162, for_in_clause; 163, attribute; 164, argument_list; 165, attribute; 166, argument_list; 167, identifier:headers; 168, identifier:update; 169, call; 170, string_content:discovery; 171, string_content:V1; 172, string_content:query_relations; 173, string_content:version; 174, identifier:self; 175, identifier:version; 176, string_content:entities; 177, string_content:context; 178, string_content:sort; 179, string_content:filter; 180, string_content:count; 181, string_content:evidence_count; 182, string_content:/v1/environments/{0}/collections/{1}/query_relations; 183, call; 184, identifier:method; 185, string; 186, identifier:url; 187, identifier:url; 188, identifier:headers; 189, identifier:headers; 190, identifier:params; 191, identifier:params; 192, identifier:json; 193, identifier:data; 194, identifier:accept_json; 195, True; 196, string_content:environment_id must be provided; 197, string_content:collection_id must be provided; 198, attribute; 199, argument_list; 200, identifier:x; 201, identifier:entities; 202, identifier:self; 203, identifier:_convert_model; 204, identifier:context; 205, identifier:QueryEntitiesContext; 206, identifier:self; 207, identifier:_convert_model; 208, identifier:filter; 209, identifier:QueryRelationsFilter; 210, attribute; 211, argument_list; 212, attribute; 213, argument_list; 214, string_content:POST; 215, identifier:self; 216, identifier:_convert_model; 217, identifier:x; 218, identifier:QueryRelationsEntity; 219, identifier:kwargs; 220, identifier:get; 221, string; 222, identifier:self; 223, identifier:_encode_path_vars; 224, identifier:environment_id; 225, identifier:collection_id; 226, string_content:headers
code: def query_relations(self,
                          environment_id,
                          collection_id,
                          entities=None,
                          context=None,
                          sort=None,
                          filter=None,
                          count=None,
                          evidence_count=None,
                          **kwargs):
          """
          Knowledge Graph relationship query.
  
          See the [Knowledge Graph
          documentation](https://cloud.ibm.com/docs/services/discovery?topic=discovery-kg#kg)
          for more details.
  
          :param str environment_id: The ID of the environment.
          :param str collection_id: The ID of the collection.
          :param list[QueryRelationsEntity] entities: An array of entities to find
          relationships for.
          :param QueryEntitiesContext context: Entity text to provide context for the
          queried entity and rank based on that association. For example, if you wanted to
          query the city of London in England your query would look for `London` with the
          context of `England`.
          :param str sort: The sorting method for the relationships, can be `score` or
          `frequency`. `frequency` is the number of unique times each entity is identified.
          The default is `score`. This parameter cannot be used in the same query as the
          **bias** parameter.
          :param QueryRelationsFilter filter:
          :param int count: The number of results to return. The default is `10`. The
          maximum is `1000`.
          :param int evidence_count: The number of evidence items to return for each result.
          The default is `0`. The maximum number of evidence items per query is 10,000.
          :param dict headers: A `dict` containing the request headers
          :return: A `DetailedResponse` containing the result, headers and HTTP status code.
          :rtype: DetailedResponse
          """
  
          if environment_id is None:
              raise ValueError('environment_id must be provided')
          if collection_id is None:
              raise ValueError('collection_id must be provided')
          if entities is not None:
              entities = [
                  self._convert_model(x, QueryRelationsEntity) for x in entities
              ]
          if context is not None:
              context = self._convert_model(context, QueryEntitiesContext)
          if filter is not None:
              filter = self._convert_model(filter, QueryRelationsFilter)
  
          headers = {}
          if 'headers' in kwargs:
              headers.update(kwargs.get('headers'))
          sdk_headers = get_sdk_headers('discovery', 'V1', 'query_relations')
          headers.update(sdk_headers)
  
          params = {'version': self.version}
  
          data = {
              'entities': entities,
              'context': context,
              'sort': sort,
              'filter': filter,
              'count': count,
              'evidence_count': evidence_count
          }
  
          url = '/v1/environments/{0}/collections/{1}/query_relations'.format(
              *self._encode_path_vars(environment_id, collection_id))
          response = self.request(
              method='POST',
              url=url,
              headers=headers,
              params=params,
              json=data,
              accept_json=True)
          return response