def _get_array_index(array_path):
    """Translates @first @last @1 @-1 expressions into an actual array index.

    :param str array_path: Array path in XJ notation.
    :rtype: int
    :return: Array index.
    """

    if not array_path.startswith('@'):
        raise XJPathError('Array index must start from @ symbol.')
    array_path = array_path[1:]
    if array_path == 'last':
        return -1
    if array_path == 'first':
        return 0
    if array_path.isdigit() or (array_path.startswith('-')
                                and array_path[1:].isdigit()):
        return int(array_path)
    else:
        raise XJPathError('Unknown index reference', (array_path,))