Parse the answers to correct FB Format.
544267
public function parse($answers)
    {
        // Iterate through answers and parse it if possible
        // Also, move quick replies to the last answer
        $parsed = [];

        $previous_index = 0;
        
        if ($this->isSingularResponse($answers)) {
            $answers = [$answers];
        }

        foreach ($answers as $index => $answer) {
            // If the answer is a Closure
            if (!is_string($answer) && is_callable($answer)) {
                $answer = [
                    'type'    => 'callback',
                    'content' => $answer,
                ];
            }

            if (isset($answer['content']) && isset($answer['quick_replies'])) {
                $answer['content'] = (array)$answer['content'];

                $answer['content']['quick_replies'] = $answer['quick_replies'];
                unset($answer['quick_replies']);
            }

            // Cast attachment key to other messages
            if (($index === 'attachment' || isset($answer['attachment']))) {
                $answer = $this->parseAttachmentMessage($index, $answer);
            }

            // Parse answer when possible.
            // Iterate through supported message type and return if answer is supported
            if ($this->isParsable($answer) && $index !== 'quick_replies') {
                if (isset($answer['type'])) {
                    $parser       = $this->typeClasses[$answer['type']];

                    $parsedAnswer = $parser::load($answer['content'], [
                        'skip_detection' => true
                    ]);

                    if ($parsedAnswer !== false) {
                        $answer = $parsedAnswer;
                    }
                } else {
                    foreach ($this->typeClasses as $type => $parser) {
                        // If not supported, it will return false, otherwise, return parsed data
                        $parsedAnswer = $parser::load($answer);

                        if ($parsedAnswer !== false) {
                            $answer = $parsedAnswer;

                            break;
                        }
                    }
                }
            }
            
            if ($index === 'quick_replies') {
                $parsed[$previous_index]                             = (array)$parsed[$previous_index];
                $parsed[$previous_index]['content']['quick_replies'] = $answer;
            }

            $parsed[$index] = $answer;
            $previous_index = $index;
        }

        unset($parsed['quick_replies']);

        return $parsed;
    }
421631
def parse_passage(obj: dict) -> BioCPassage:
    """"""
    passage = BioCPassage()
    passage.offset = obj['offset']
    passage.infons = obj['infons']
    if 'text' in obj:
        passage.text = obj['text']
    for sentence in obj['sentences']:
        passage.add_sentence(parse_sentence(sentence))
    for annotation in obj['annotations']:
        passage.add_annotation(parse_annotation(annotation))
    for relation in obj['relations']:
        passage.add_relation(parse_relation(relation))
    return passage
107450
def _parse(self, data):
        
        if type(data) == type(bytes()):
            try:
                data = data.decode('utf-8')
            except UnicodeDecodeError:
                return data

        try:
            data = json.loads(data, parse_float=Decimal)
        except ValueError:
            return data

        # Facebook's Graph API sometimes responds with 'true' or 'false'. Facebook offers no documentation
        # as to the prerequisites for this type of response, though it seems that it responds with 'true'
        # when objects are successfully deleted and 'false' upon attempting to delete or access an item that
        # one does not have access to.
        #
        # For example, the API would respond with 'false' upon attempting to query a feed item without having
        # the 'read_stream' extended permission. If you were to query the entire feed, however, it would respond
        # with an empty list instead.
        #
        # Genius.
        #
        # We'll handle this discrepancy as gracefully as we can by implementing logic to deal with this behavior
        # in the high-level access functions (get, post, delete etc.).
        if type(data) is dict:
            if 'error' in data:
                error = data['error']

                if error.get('type') == "OAuthException":
                    exception = OAuthError
                else:
                    exception = FacebookError

                raise exception(**self._get_error_params(data))

            # Facebook occasionally reports errors in its legacy error format.
            if 'error_msg' in data:
                raise FacebookError(**self._get_error_params(data))

        return data
637341
def user_parse(data):
        """"""
        user = data.get('response', {}).get('user', {})
        yield 'id', user.get('id')
        yield 'email', user.get('contact', {}).get('email')
        yield 'first_name', user.get('firstName')
        yield 'last_name', user.get('lastName')
        city, country = user.get('homeCity', ', ').split(', ')
        yield 'city', city
        yield 'country', country
534408
def get_answer_begin_end(data):
    '''
    
    '''
    begin = []
    end = []
    for qa_pair in data:
        tokens = qa_pair['passage_tokens']
        char_begin = qa_pair['answer_begin']
        char_end = qa_pair['answer_end']
        word_begin = get_word_index(tokens, char_begin)
        word_end = get_word_index(tokens, char_end)
        begin.append(word_begin)
        end.append(word_end)
    return np.asarray(begin), np.asarray(end)
1079921
def params_includes_answer(answer)
      question_ids = params[:question_id]
      return nil unless question_ids.kind_of? Hash
      answers = question_ids[answer.question_id.to_s]
      return nil unless answers.kind_of? Hash
      answers.values.flatten.include?(answer.id.to_s)
    end
616871
def parse(self, fp, headersonly=True):
        """"""
        feedparser = FeedParser(self._class)
        feedparser._set_headersonly()

        try:
            mp = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ)
        except:
            mp = fp

        data = ""

        # While parsing the header we can convert to us-ascii?
        while True:
            line = mp.readline()
            data = data + line.decode("us-ascii")
            if line == b"\n":
                break
        feedparser.feed(data) # mp[0:5000])
        return feedparser.close()
1287994
def parseresponse(self, resp):
        """"""
        # Support Python 3's bytes type from socket repsonses
        if sys.version_info.major > 2:
            resp = resp.decode('utf-8')
	
        if self.RESPONSE_TOKEN not in resp:
            raise BustimeError("The Bustime API returned an invalid response: {}".format(resp))
        elif self.ERROR_TOKEN in resp:
            return self.errorhandle(resp)
        else:
            if self.format == 'json':
                return xmltodict.parse(resp)[self.RESPONSE_TOKEN]
            elif self.format == 'xml':
                return resp
308194
function run (answers) {
    ls(['LICENSE', 'package.json', 'README.md', 'index.js', 'index.html', 'examples/basic/index.html', 'tests/index.test.js']).forEach(function (file) {
      answers.aframeVersion = aframeVersion;
      answers.npmName = `aframe-${answers.shortName}-component`;
      fs.writeFileSync(file, nunjucks.render(file, answers));
    });
  }
1102848
function parseArguments(opts, callback) {
  if ('function' === typeof opts) {
    callback = opts
    opts = {}
  }

  opts = opts || {}
  opts.callback = callback

  return opts
}
298165
def query_cast(value, answers, ignorecase = False):
    
    if ignorecase: value = value.lower()
    for item in answers:
        for a in item['values']:
            if ignorecase and (value == str(a).lower()):
                return item['values'][0]
            elif value == a:
                return item['values'][0]
    raise ValueError("Response '%s' not understood, please try again." % value)
195006
def user_parse(data):
        """"""
        user_ = data.get('user', {})
        yield 'id', data.get('user_nsid') or user_.get('id')
        yield 'username', user_.get('username', {}).get('_content')
        first_name, _, last_name = data.get(
            'fullname', {}).get('_content', '').partition(' ')
        yield 'first_name', first_name
        yield 'last_name', last_name
557321
def answers(self, other):
        """"""
        if other.__class__ == self.__class__:
            return (other.service + 0x40) == self.service or \
                   (self.service == 0x7f and
                    self.request_service_id == other.service)
        return False
1231057
def user_parse(data):
        """"""
        yield 'id', data.get('id') or data.get('user_id')
        first_name, _, last_name = data['name'].partition(' ')
        yield 'first_name', first_name
        yield 'last_name', last_name
        yield 'picture', data.get('profile_image_url')
        yield 'locale', data.get('lang')
        yield 'link', data.get('url')
        yield 'username', data.get('screen_name')
        city, _, country = map(lambda s: s.strip(),
                               data.get('location', '').partition(','))
        yield 'city', city
        yield 'country', country
1159258
def _parse_version_reply(self):
        ""
        if len(self._data) >= 2:
            reply = self._data[:2]
            self._data = self._data[2:]
            (version, method) = struct.unpack('BB', reply)
            if version == 5 and method in [0x00, 0x02]:
                self.version_reply(method)
            else:
                if version != 5:
                    self.version_error(SocksError(
                        "Expected version 5, got {}".format(version)))
                else:
                    self.version_error(SocksError(
                        "Wanted method 0 or 2, got {}".format(method)))
578809
function formatPageResponse(result) {
    var response = {};

    if (result.posts) {
        response.posts = result.posts;
    }

    if (result.meta && result.meta.pagination) {
        response.pagination = result.meta.pagination;
    }

    _.each(result.data, function (data, name) {
        if (data.meta) {
            // Move pagination to be a top level key
            response[name] = data;
            response[name].pagination = data.meta.pagination;
            delete response[name].meta;
        } else {
            // This is a single object, don't wrap it in an array
            response[name] = data[0];
        }
    });

    return response;
}
94099
def user_parse(data):
        """"""
        user_ = data.get('user')
        yield 'id', user_.get('username')
        yield 'username', user_.get('username')
        yield 'first_name', user_.get('first_name')
        yield 'last_name', user_.get('last_name')
        yield 'picture', user_.get('avatar')
        yield 'link', user_.get('resource_url')