21
21
from ovos_utils .ocp import MediaType , PlaybackType , PlaybackMode , PlayerState , OCP_ID , \
22
22
MediaEntry , Playlist , MediaState , TrackState , dict2entry , PluginStream
23
23
from ovos_workshop .app import OVOSAbstractApplication
24
- from padacioso import IntentContainer
24
+ from ovos_utils .xdg_utils import xdg_data_home
25
+ from ovos_config .meta import get_xdg_base
25
26
26
27
from ocp_pipeline .feats import OCPFeaturizer
27
28
from ocp_pipeline .legacy import LegacyCommonPlay
@@ -48,6 +49,7 @@ class OCPPipelineMatcher(ConfidenceMatcherPipeline, OVOSAbstractApplication):
48
49
"next.intent" , "prev.intent" , "pause.intent" , "play_favorites.intent" ,
49
50
"resume.intent" , "like_song.intent" ]
50
51
intent_matchers = {}
52
+ intent_cache = f"{ xdg_data_home ()} /{ get_xdg_base ()} /intent_cache"
51
53
52
54
def __init__ (self , bus : Optional [Union [MessageBusClient , FakeBus ]] = None ,
53
55
config : Optional [Dict ] = None ):
@@ -150,9 +152,22 @@ def register_ocp_api_events(self):
150
152
@classmethod
151
153
def load_intent_files (cls ):
152
154
intent_files = cls .load_resource_files ()
155
+
156
+ try :
157
+ from ovos_padatious import IntentContainer
158
+ is_padatious = True
159
+ except ImportError :
160
+ from padacioso import IntentContainer
161
+ is_padatious = False
162
+ LOG .warning ("Padatious not available, using padacioso. intent matching will be orders of magnitude slower!" )
163
+
153
164
for lang , intent_data in intent_files .items ():
154
165
lang = standardize_lang_tag (lang )
155
- cls .intent_matchers [lang ] = IntentContainer ()
166
+ if is_padatious :
167
+ cache = f"{ cls .intent_cache } /{ lang } "
168
+ cls .intent_matchers [lang ] = IntentContainer (cache )
169
+ else :
170
+ cls .intent_matchers [lang ] = IntentContainer ()
156
171
for intent_name in cls .intents :
157
172
samples = intent_data .get (intent_name )
158
173
if samples :
@@ -301,6 +316,10 @@ def handle_player_state_update(self, message: Message):
301
316
def match_high (self , utterances : List [str ], lang : str , message : Message = None ) -> Optional [IntentHandlerMatch ]:
302
317
""" exact matches only, handles playback control
303
318
recommended after high confidence intents pipeline stage """
319
+
320
+ if not len (self .skill_aliases ): # skill_id registered when skills load
321
+ return None # dont waste compute cycles, no media skills -> no match
322
+
304
323
lang = self ._get_closest_lang (lang )
305
324
if lang is None : # no intents registered for this lang
306
325
return None
@@ -310,9 +329,21 @@ def match_high(self, utterances: List[str], lang: str, message: Message = None)
310
329
utterance = utterances [0 ].lower ()
311
330
match = self .intent_matchers [lang ].calc_intent (utterance )
312
331
332
+ if hasattr (match , "name" ): # padatious
333
+ match = {
334
+ "name" : match .name ,
335
+ "conf" : match .conf ,
336
+ "entities" : match .matches
337
+ }
338
+
313
339
if match ["name" ] is None :
314
340
return None
315
- LOG .info (f"OCP exact match: { match } " )
341
+
342
+ if match .get ("conf" , 1.0 ) < 0.7 :
343
+ LOG .debug (f"Ignoring low confidence OCP match: { match } " )
344
+ return None
345
+
346
+ LOG .info (f"OCP match: { match } " )
316
347
317
348
player = self .get_player (message )
318
349
@@ -1128,6 +1159,12 @@ def match(self, utterances: List[str], lang: str, message: Message = None) -> Op
1128
1159
return None
1129
1160
1130
1161
match = OCPPipelineMatcher .intent_matchers [lang ].calc_intent (utterance )
1162
+ if hasattr (match , "name" ): # padatious
1163
+ match = {
1164
+ "name" : match .name ,
1165
+ "conf" : match .conf ,
1166
+ "entities" : match .matches
1167
+ }
1131
1168
1132
1169
if match ["name" ] is None :
1133
1170
return None
0 commit comments