From e63439f64c83bce6014477ee703a6c25f458eb70 Mon Sep 17 00:00:00 2001 From: moguno Date: Sun, 26 Mar 2017 12:55:03 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=9E=E3=83=83=E3=83=81=E3=81=99=E3=82=8B?= =?UTF-8?q?=E9=96=A2=E9=80=A3=E4=BB=98=E3=81=91=E3=81=8C=E8=A4=87=E6=95=B0?= =?UTF-8?q?=E3=81=82=E3=81=A3=E3=81=9F=E5=A0=B4=E5=90=88=E3=80=81=E5=84=AA?= =?UTF-8?q?=E5=85=88=E9=A0=86=E4=BD=8D=E3=81=AE=E4=B8=80=E7=95=AA=E9=AB=98?= =?UTF-8?q?=E3=81=84=E9=96=A2=E9=80=A3=E4=BB=98=E3=81=91=E3=82=92=E7=99=BA?= =?UTF-8?q?=E5=8B=95=E3=81=95=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/plugin/intent_selector/intent_selector.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/plugin/intent_selector/intent_selector.rb b/core/plugin/intent_selector/intent_selector.rb index d028567..e2d034d 100644 --- a/core/plugin/intent_selector/intent_selector.rb +++ b/core/plugin/intent_selector/intent_selector.rb @@ -31,7 +31,7 @@ Plugin.create(:intent_selector) do # [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, @@ -119,12 +119,19 @@ Plugin.create(:intent_selector) do # ==== 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を文字列で得る。 -- 2.10.1 (Apple Git-78)