小编X. *_*ang的帖子

将 splat 运算符与 when 一起使用

案例陈述:

case x
when 1
  "one"
when 2
  "two"
when 3
  "three"
else
  "many"
end
Run Code Online (Sandbox Code Playgroud)

使用运算符进行评估===。该运算符在表达式的值上调用,when并将表达式的值case作为参数。上面的 case 语句等价于以下内容:

if 1 === x
  "one"
elsif 2 === x
  "two"
elsif 3 === x
  "three"
else
  "many"
end
Run Code Online (Sandbox Code Playgroud)

在这种情况下:

A = 1
B = [2, 3, 4]
case reason
when A
  puts "busy"
when *B
  puts "offline"
end
Run Code Online (Sandbox Code Playgroud)

when *B部分无法重写为*B === 2.

这是关于 splat 运算符吗?splat 运算符是关于赋值,而不是比较。case语句如何处理when *B

ruby splat

5
推荐指数
1
解决办法
542
查看次数

如何重试 sidekiq 工作程序而不引发异常

我的 sidekiq 工作人员使用 get 请求来获取语音识别结果,响应状态将为“成功”或“失败”或“正在运行”。当状态为“RUNNING”时,我想在 10 分钟内重试 sidekiq 工作程序。我如何在不睡眠或引发异常的情况下重试。因为睡眠会消耗太多资源,引发异常会留下我不想记录的 newrelic 错误日志。

class GetAsrTextWorker
  include Sidekiq::Worker
  sidekiq_options :queue => :default, :retry => 5

  sidekiq_retry_in do | count|
    600 * (count + 1)
  end

  def perform(task_id):
    # get request to get the outcome
    if status == "SUCCESSD"
       # save the outcome
    elsif status == "FAILED"
       raise AsrError
    elsif status == "RUNNING"
       raise "Asr running"
    end
  rescue AsrError => e
    Sidekiq.logger.error e.message
  end
end
Run Code Online (Sandbox Code Playgroud)

此方法将重试该工作程序,但会导致 newrelic 中出现丑陋的错误日志,我不想记录它。

ruby-on-rails sidekiq

3
推荐指数
1
解决办法
1930
查看次数

Does pre-trained Embedding matrix has <EOS>, <UNK> word vector?

我想构建一个带有预训练嵌入矩阵的 seq2seq 聊天机器人。是否预先训练嵌入基质,例如了Googlenews向量-negative300,FastText和手套,具有用于特定字向量<EOS><UNK>

nlp deep-learning

2
推荐指数
1
解决办法
2466
查看次数

标签 统计

deep-learning ×1

nlp ×1

ruby ×1

ruby-on-rails ×1

sidekiq ×1

splat ×1