如何为 Amazon Mechanical Turk 准备包含表情符号字符的 CSV HIT 文件

问题描述 投票:0回答:1

Amazon Mechanical Turk 拒绝包含 4 字节 UTF-8 字符(例如表情符号)的 CSV HIT 文件。然而,表情符号字符是工作人员任务中不可或缺的一部分,我需要保留它们。

我在 https://github.com/charman/mturk-emoji 找到了该脚本,它将表情符号字符替换为其等效的 HTML 跨度(例如 )。但是,当将预处理后的 CSV 提供给 MTurk 时,不会渲染表情符号字符。

csv emoji mechanicalturk
1个回答
0
投票

我按照以下步骤成功解决了问题。

  1. 使用链接的

    GitHub 存储库
    中的脚本 encode_emoji.py 将 CVS 转换为 UTF-8 表情符号。你会得到,比如说,
    sample_with_emoji.csv

  2. 在 Mechanical Turk 中,编辑当前项目并转到

    Design Layout
    。为了正确渲染带有表情符号字节的 HTML
    span
    ,您需要在 MTurk 的 HTML 编辑器中的开头添加以下代码:

<script src="https://code.jquery.com/jquery-3.3.1.js"
            integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
            crossorigin="anonymous"></script>

<script>
    function displayEmoji() {

  /**
   * utf8ByteArrayToString() copied from:
   *   https://github.com/google/closure-library/blob/e877b1eac410c0d842bcda118689759512e0e26f/closure/goog/crypt/crypt.js
   *
   * Converts a UTF-8 byte array to JavaScript's 16-bit Unicode.
   * @param {Uint8Array|Array<number>} bytes UTF-8 byte array.
   * @return {string} 16-bit Unicode string.
   */
  var utf8ByteArrayToString = function(bytes) {
    var out = [], pos = 0, c = 0;
    while (pos < bytes.length) {
      var c1 = bytes[pos++];
      if (c1 < 128) {
        out[c++] = String.fromCharCode(c1);
      } else if (c1 > 191 && c1 < 224) {
        var c2 = bytes[pos++];
        out[c++] = String.fromCharCode((c1 & 31) << 6 | c2 & 63);
      } else if (c1 > 239 && c1 < 365) {
        // Surrogate Pair
        var c2 = bytes[pos++];
        var c3 = bytes[pos++];
        var c4 = bytes[pos++];
        var u = ((c1 & 7) << 18 | (c2 & 63) << 12 | (c3 & 63) << 6 | c4 & 63) -
                0x10000;
        out[c++] = String.fromCharCode(0xD800 + (u >> 10));
        out[c++] = String.fromCharCode(0xDC00 + (u & 1023));
      } else {
        var c2 = bytes[pos++];
        var c3 = bytes[pos++];
        out[c++] =
          String.fromCharCode((c1 & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
      }
    }
    return out.join('');
  }

  jQuery(this).text(utf8ByteArrayToString(JSON.parse(jQuery(this).attr('data-emoji-bytes'))));
}
</script>

<script>
    jQuery(document).ready(function() {
      jQuery('span.emoji-bytes').each(displayEmoji);
    });
</script>

以上基本上是存储库中 README 文件底部的内容,脚本

decode_emoji.js
是内联添加的,而不是源代码。

  1. 按“保存”即可开始。现在,如果您上传
    sample_with_emoji.csv
    文件,表情符号将在预览中正确呈现。
© www.soinside.com 2019 - 2024. All rights reserved.