-1

我有以下内容:

table(
  [
    [
      "UnitID",
      "First Name",
      "Last Name",
      "NPS Score",
      "Comments",
      "emotion",
      "polarity"
    ],
    *[
      invite_unitid_arr,
      invite_name_arr,
      invite_lastname_arr,
      nps_score_integers,
      comment_arr,
      SadPanda.emotion(comment_arr),
      SadPanda.polarity(comment_arr)
    ].transpose
  ]
)

但是,SadPanda.emotion(comment_arr)SadPanda.polarity(comment_arr)返回:

undefined method 'gsub!' for #<Array:0x007f8f9b0d40a8>

如何转置数组,但也可以在数组SadPanda.emotion()中的每个字符串值上使用?

编辑:

需要明确的是,这就是我想要的最终结果:

[
invite_unitid_arr[0],
invite_name_arr[0],
invite_lastname_arr[0],
nps_score_integers[0],
comment_arr[0],
SadPanda.emotion(comment_arr[0]),
SadPanda.polarity(comment_arr[0])
],

[
invite_unitid_arr[1],
invite_name_arr[1],
invite_lastname_arr[1],
nps_score_integers[1],
comment_arr[1],
SadPanda.emotion(comment_arr[1]),
SadPanda.polarity(comment_arr[1])
]

等等等等。该.transpose方法完全按照我需要它对数组中的所有值执行的操作,但我不知道如何传入and方法并comment_arr[0]在每次转置数组时递增该值。.emotion.polarity

4

1 回答 1

0

To solve the issue:

new_comment_array_emotion = []
new_comment_array_polarity = []

comment_arr.each do |x|
    new_comment_array_emotion << SadPanda.emotion(x)
    new_comment_array_polarity << SadPanda.polarity(x)
end

table(
  [
    [
      "UnitID",
      "First Name",
      "Last Name",
      "NPS Score",
      "Comments",
      "emotion",
      "polarity"
    ],
    *[
      invite_unitid_arr,
      invite_name_arr,
      invite_lastname_arr,
      nps_score_integers,
      comment_arr,
      new_comment_array_emotion,
      new_comment_array_polarity
    ].transpose
  ]
)

Feel free to propose a cleaner way of doing this within Ruby.

于 2013-10-15T17:45:33.893 回答