1
0
mirror of https://github.com/MarkParker5/STARK.git synced 2025-02-22 12:00:09 +02:00

upgrade Command.find() with fuzzywuzzy (one letter problem stayed)

This commit is contained in:
dQz6tMwk8rJqvDR 2020-06-25 00:59:11 +03:00
parent a48dad2552
commit d7868f2f98
2 changed files with 13 additions and 3 deletions

View File

@ -39,13 +39,16 @@ class Command(ABC):
return (weight, index)
index += 1
return None # if not found
def removeKeyword(this, string):
position = this._getKeyword(string)
if(position): del this._keywords[ position[0] ][ position[1] ]
def addKeyword(this, weight, string):
if this._getKeyword(string): return
if( this._keywords.get(weight) ): this._keywords[weight].append(string)
else: this._keywords[weight] = [string]
def changeKeyword(this, weight, string):
this.removeKeyword(string)
this.addKeyword(weight, string)
@ -60,6 +63,7 @@ class Command(ABC):
# getters
def getName(this):
return this._name
def getKeywords(this):
return this._keywords
@ -67,6 +71,7 @@ class Command(ABC):
@abstractmethod
def start(this, string): # main method
pass
@abstractmethod
def confirm(this): # optional method
pass
@ -80,6 +85,10 @@ class Command(ABC):
def append(obj):
Command._list.append(obj)
@staticmethod
def ratio(string, word):
return ( fuzz.WRatio(string, word) + fuzz.ratio(string, word) ) / 2
@staticmethod
def find(string):
string = string.lower()
@ -89,12 +98,13 @@ class Command(ABC):
chances[i] = 0
for weight, words in obj.getKeywords().items():
for word in words:
chances[i] += fuzz.partial_ratio(word, string) * weight
print(chances)
chances[i] += Command.ratio(string, word) * weight
if( sum( chances.values() ) ):
top = max( chances.values() ) / sum( chances.values() ) * 100
else:
return list[0]
if( max( chances.values() ) < 1000 or top < 80): return list[0]
print(chances)
print(top)
for i, chance in chances.items():
if chance == max( chances.values() ):

View File

@ -96,7 +96,7 @@ def method():
keywords = {
10: ['который час', 'сколько времени'],
5: ['текущее', 'сейчас', 'час', 'время'],
5: ['текущее', 'сейчас', 'время'],
1: ['сколько']
}
ctime = SmallTalk('Current Time', keywords)