Mervin Hemaraju
Mervin Hemaraju

Reputation: 2117

Fuzzy Wuzzy: Obtain accurate scores

I have a case where users posts multiple messages daily to our work channel. These messages are an issue that can be related to multiple applications that we support (Okta, Slack, Cloudflare etc...). We have multiple solution documented that can help these users, and I want our bot to be able to send them the correct documentation automatically based on their messages.

I am using the string matching approach to achieve this with the FuzzyWuzzy Python library.

I run the message posted by a user in the list of applications that we support, and whenever FuzzyWuzzy gives me a score of > 90, I assume that this is the application that is being requested in the message. I am using the code below:

requests.py

from enum import Enum
from fuzzywuzzy import fuzz

class RequestType(Enum):

    OKTA_ACCESS = "okta access"
    OKTA_UNLOCK = "okta unlock"
    CLOUDFLARE = "cannot connect to cloudflare"

class RequestsMatcher:

    def __init__(self, message: str) -> None:
        
        scores = [
            (
                type,
                fuzz.partial_token_set_ratio(message, type.value)
            )
            for type in RequestType
        ]

        mvs = [score for score in scores if score[1] > 75]

        hits = [score for score in scores if score[1] > 90]

        print(scores)
        self.scores = scores
        self.highest = mvs
        self.hit = next(iter(hits), None)

The issue with this code is that, for a sample message like the one below, both cloudflare and okta will give a score of > 90 when it should've been just Cloudflare to return a score of > 90:

        '''
        Hello team, it looks like I am having an issue with Cloudflare. I have been added to the following Okta group.
        Can someone look into this for me, please?
        '''

Is there a better score calculation or better approach to obtain the necessary application that is being requested on support?

Upvotes: 1

Views: 126

Answers (0)

Related Questions