機能 #1002 » 0002-.patch
core/plugin/intent_selector/intent_selector.rb | ||
---|---|---|
# [uri:] 開くURI。 _model:_ を渡している場合は、省略してもよい
|
||
def intent_open(intents, model: nil, uri: model.uri)
|
||
recommended, suggested = divide_intents(intents, uri, specified_model_slug(model))
|
||
if recommended.size == 1
|
||
if recommended.size >= 1
|
||
Plugin::Intent::IntentToken.open(
|
||
uri: uri,
|
||
model: model,
|
||
... | ... | |
# ==== Return
|
||
# 条件に対して推奨されるintentの配列と、intentsに指定されたそれ以外の値の配列
|
||
def divide_intents(intents, uri, model_slug)
|
||
intent_slugs = UserConfig[:intent_selector_rules].select{|record|
|
||
# モデル + URL(URLマッチ文字列が長い順)
|
||
intent_slugs_with_model = UserConfig[:intent_selector_rules].select{|record|
|
||
model_slug == record[:model].to_s && uri.to_s.start_with?(record[:str])
|
||
}.map{|record|
|
||
record[:intent].to_sym
|
||
}
|
||
intents.partition{|intent| intent_slugs.include?(intent.slug) }
|
||
}.sort {|a, b| a[:str].length <=> b[:str.length] }.reverse
|
||
# URLのみ(URLマッチ文字列が長い順)
|
||
intens_slugs_without_model = UserConfig[:intent_selector_rules].select{|record|
|
||
record[:model] == nil && uri.to_s.start_with?(record[:str])
|
||
}.sort {|a, b| a[:str].length <=> b[:str.length] }.reverse
|
||
intent_slugs = (intent_slugs_with_model + intens_slugs_without_model).map { |record| record[:intent] }
|
||
intents.partition{|intent| intent_slugs.include?(intent.slug.to_sym) }
|
||
end
|
||
# _model_ のmodel slugを文字列で得る。
|