def _process_query(self, query, prepared=False):
<EOL>if prepared is True:<EOL><INDENT>files = {'<STR_LIT>': str(query)}<EOL>logger.debug('<STR_LIT>'.format(query))<EOL>res, status = self.post(<EOL>self.disambiguate_service,<EOL>files=files,<EOL>headers={'<STR_LIT>': '<STR_LIT:application/json>'},<EOL>)<EOL>if status == <NUM_LIT:200>:<EOL><INDENT>return self.decode(res), status<EOL><DEDENT>else:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>return None, status<EOL><DEDENT><DEDENT>text = query['<STR_LIT:text>']<EOL>sentence_coordinates = [<EOL>{<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": len(text)<EOL>}<EOL>]<EOL>total_nb_sentences = len(sentence_coordinates)  <EOL>sentences_groups = []<EOL>if len(text) > self.max_text_length:<EOL><INDENT>res, status_code = self.segment(text)<EOL>if status_code == <NUM_LIT:200>:<EOL><INDENT>sentence_coordinates = res['<STR_LIT>']<EOL>total_nb_sentences = len(sentence_coordinates)<EOL><DEDENT>else:<EOL><INDENT>logger.error('<STR_LIT>')<EOL><DEDENT>logger.debug(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(<EOL>total_nb_sentences, self.sentences_per_group<EOL>)<EOL>)<EOL>sentences_groups = self._group_sentences(<EOL>total_nb_sentences,<EOL>self.sentences_per_group<EOL>)<EOL><DEDENT>else:<EOL><INDENT>query['<STR_LIT>'] = "<STR_LIT:true>"<EOL><DEDENT>if total_nb_sentences > <NUM_LIT:1>:<EOL><INDENT>query['<STR_LIT>'] = sentence_coordinates<EOL><DEDENT>if len(sentences_groups) > <NUM_LIT:0>:<EOL><INDENT>for group in sentences_groups:<EOL><INDENT>query['<STR_LIT>'] = group<EOL>res, status_code = self._process_query(query, prepared=True)<EOL>if status_code == <NUM_LIT:200>:<EOL><INDENT>if '<STR_LIT>' in res:<EOL><INDENT>query['<STR_LIT>'] = res[u'<STR_LIT>']<EOL><DEDENT>query['<STR_LIT>'] = res[u'<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>logger.error(<EOL>"<STR_LIT>".format(query)<EOL>)<EOL>return None, status_code<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>res, status_code = self._process_query(query, prepared=True)<EOL>if status_code == <NUM_LIT:200>:<EOL><INDENT>query['<STR_LIT>'] = res[u'<STR_LIT>']<EOL>if '<STR_LIT>' in res:<EOL><INDENT>query['<STR_LIT>'] = res[u'<STR_LIT>']<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.error("<STR_LIT>".format(query))<EOL>return None, status_code<EOL><DEDENT><DEDENT>return query, status_code<EOL>
Process query recursively, if the text is too long,
        it is split and processed bit a bit.

        Args:
            query (sdict): Text to be processed.
            prepared (bool): True when the query is ready to be submitted via
            POST request.
        Returns:
            str: Body ready to be submitted to the API.