【发布时间】:2019-11-07 12:16:14
【问题描述】:
我有一个包含两个多方法的类 (multi submit)。
我这样称呼我的多重:
$perspective.submit(:message($message.content));
哪些被运到我的班级:
my $perspective-api = API::Perspective.new(:api-key(%*ENV<PERSPECTIVE_API_KEY>));
proto method submit (|) {*}
multi method submit(Str :$message!, MODEL :@models = TOXICITY) {
my $score = $perspective-api.analyze(:@models, :comment($message));
say @models Z=> $score<attributeScores>{@models}.map: *<summaryScore><value>;
multi method submit(Str :$name!, MODEL :@models = TOXICITY) {
my $score = $perspective-api.analyze(:@models, :comment($name));
say @models Z=> $score<attributeScores>{@models}.map: *<summaryScore><value>;
}
但是我总是得到以下响应:
Died because of the exception:
Cannot resolve caller AUTOGEN(Rose::ContentAnalysis::Perspective:D: :message(Str)); none of these signatures match:
(Rose::ContentAnalysis::Perspective: Str :$message!, MODEL :@models = MODEL::TOXICITY, *%_)
(Rose::ContentAnalysis::Perspective: Str :$name!, MODEL :@models = MODEL::TOXICITY, *%_)
尽管我的命名参数 (:message) 根据需要是 Str,而 @models 声明了默认值。
【问题讨论】:
-
你能分享
TOXICITY的定义吗?我想知道您的默认值是否无法分配。 -
@JonathanWorthington 你可以在我的
API::Perspective模块中找到 MODEL 枚举,如果那是你要找的。 github.com/shuppet/p6-api-perspective/blob/master/lib/API/…
标签: oop raku method-signature multimethod