Skip to content

Commit 2b93e26

Browse files
authored
feat/fuzzy_match (#8)
* feat/fuzzy_match * feat/fuzzy_match
1 parent 9edb8c9 commit 2b93e26

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

__init__.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from json_database import JsonStorageXDG
66
from ovos_bus_client.apis.ocp import OCPInterface
77
from ovos_bus_client.message import Message
8-
98
from ovos_utils import classproperty
109
from ovos_utils.log import LOG
10+
from ovos_utils.ocp import MediaType, PlaybackType
11+
from ovos_utils.parse import fuzzy_match, MatchStrategy
1112
from ovos_utils.process_utils import RuntimeRequirements
1213
from ovos_workshop.decorators import intent_handler
1314
from ovos_workshop.decorators.ocp import ocp_search
1415
from ovos_workshop.skills.common_play import OVOSCommonPlaybackSkill
15-
from ovos_utils.ocp import MediaType, PlaybackType
1616

1717

1818
class LocalMediaSkill(OVOSCommonPlaybackSkill):
@@ -24,7 +24,7 @@ class LocalMediaSkill(OVOSCommonPlaybackSkill):
2424

2525
def __init__(self, *args, **kwargs):
2626
self.archive = JsonStorageXDG("LocalMedia", subfolder="OCP")
27-
super().__init__(skill_icon = join(dirname(__file__), "res", "icon", "ovos-file-browser.svg"),
27+
super().__init__(skill_icon=join(dirname(__file__), "res", "icon", "ovos-file-browser.svg"),
2828
supported_media=[MediaType.SHORT_FILM, MediaType.MUSIC,
2929
MediaType.RADIO, MediaType.RADIO_THEATRE,
3030
MediaType.MOVIE, MediaType.AUDIOBOOK,
@@ -146,16 +146,24 @@ def search_db(self, phrase, media_type):
146146
entities = self.ocp_voc_match(phrase)
147147
base_score += 30 * len(entities)
148148

149+
if media_type == MediaType.GENERIC:
150+
candidates = self.archive.values()
151+
else:
152+
candidates = [video for video in self.archive.values()
153+
if video["media_type"] == media_type]
154+
149155
if entities:
150-
if media_type == MediaType.GENERIC:
151-
candidates = self.archive.values()
152-
else:
153-
candidates = [video for video in self.archive.values()
154-
if video["media_type"] == media_type]
155-
156156
title = list(entities.values())[0]
157-
return [video for video in candidates
158-
if title.lower() in video["title"].lower()]
157+
for video in candidates:
158+
if title.lower() in video["title"].lower():
159+
video["match_confidence"] = base_score
160+
yield video
161+
else:
162+
for entry in candidates:
163+
score = fuzzy_match(phrase, entry["title"],
164+
strategy=MatchStrategy.DAMERAU_LEVENSHTEIN_SIMILARITY)
165+
entry["match_confidence"] = score * 100
166+
yield entry
159167
return []
160168

161169
## File Browser

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ovos-utils >= 0.1.0a7
1+
ovos-utils >= 0.1.0a16
22
ovos-bus-client>=0.0.9a2
33
ovos-workshop>=0.0.16a5

0 commit comments

Comments
 (0)