Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def compare_output(baseline, current):
similarity = 50;
if (DEFAULT_ALGORITHM == 'ratio'):
similarity = fuzz.ratio(baseline, current)
elif (DEFAULT_ALGORITHM == 'partial_ratio'):
similarity = fuzz.partial_ratio(baseline, current)
elif (DEFAULT_ALGORITHM == 'token_sort_ratio'):
similarity = fuzz.token_sort_ratio(baseline, current)
elif (DEFAULT_ALGORITHM == 'partial_token_sort_ratio'):
similarity = fuzz.partial_token_sort_ratio(baseline, current)
elif (DEFAULT_ALGORITHM == 'token_set_ratio'):
similarity = fuzz.token_set_ratio(baseline, current)
else:
print("Unknown similarity measure " + DEFAULT_ALGORITHM + ". Aborting")
sys.exit(-1)
return similarity
def role_add(self, event, user, role, reason=None, mode=None):
role_obj = None
if role.isdigit() and int(role) in event.guild.roles.keys():
role_obj = event.guild.roles[int(role)]
elif role.lower() in event.config.role_aliases:
role_obj = event.guild.roles.get(event.config.role_aliases[role.lower()])
else:
# First try exact match
exact_matches = [i for i in event.guild.roles.values() if i.name.lower().replace(' ', '') == role.lower()]
if len(exact_matches) == 1:
role_obj = exact_matches[0]
else:
# Otherwise we fuzz it up
rated = sorted([
(fuzz.partial_ratio(role, r.name.replace(' ', '')), r) for r in event.guild.roles.values()
], key=lambda i: i[0], reverse=True)
if rated[0][0] > 40:
if len(rated) == 1:
role_obj = rated[0][1]
elif rated[0][0] - rated[1][0] > 20:
role_obj = rated[0][1]
if not role_obj:
raise CommandFail('too many matches for that role, try something more exact or the role ID')
author_member = event.guild.get_member(event.author)
highest_role = sorted(
[event.guild.roles.get(r) for r in author_member.roles],
key=lambda i: i.position,
reverse=True)
# Fetch all channel names
channel_data = {}
for x in all_videos:
channel_id = x["snippet"]["channelId"]
if channel_id not in channel_data:
channel_data[channel_id] = {"name": x["snippet"]["channelTitle"]}
# Break search query into lowercase words
query_words = search_query.lower().split()
# Calculate score of each video title using fuzzy matching
video_results = []
for key in title_data:
score = 0
for q in query_words:
score += fuzz.ratio(q, key)
score += fuzz.ratio(search_query.lower(), key)
inc = fuzz.partial_ratio(q, key)
if inc == 100:
inc += len(q) * 20
score += inc
score += title_data[key]["statistics"]["viewCount"] / 10000000
video_results.append([score, title_data[key]])
# Calculate score of each channel name using fuzzy matching
channel_results = []
for key in channel_data:
channel_name = channel_data[key]["name"].lower()
score = 0
for q in query_words:
score += fuzz.ratio(q, channel_name)
score += fuzz.ratio(search_query.lower(), channel_name)
inc = fuzz.partial_ratio(q, channel_name)
if inc == 100:
inc += len(q) * 20
for epName in epNames:
if use_fuzzy_matching == True:
if episode.get('episodeName', None):
episodeNameTVDB = episode.get('episodeName').lower()
epNameL = epName.lower()
if re.sub('( |:|,|\.)', '', episodeNameTVDB) == re.sub('( |:|,|\.)', '', epNameL):
ratio1 = 100
ratio2 = 100
ratio3 = 100
ratio4 = 100
else:
ratio1 = fuzz.token_sort_ratio(re.sub('(:|,|\.)', '', episodeNameTVDB), re.sub('(:|,|\.)', '', epNameL))
ratio2 = fuzz.token_sort_ratio(re.sub('( |:|,|\.)', '', episodeNameTVDB), re.sub('( |:|,|\.)', '', epNameL))
ratio3 = fuzz.token_set_ratio(episodeNameTVDB, epNameL)
ratio4 = fuzz.partial_ratio(re.sub('(:|,|\.)', '', episodeNameTVDB), re.sub('(:|,|\.)', '', epNameL))
if min(len(episodeNameTVDB), len(epNameL)) < 6:
ratio = (ratio1 + ratio2) / 2.0
else:
ratio = (ratio1 + ratio2 + ratio3 + ratio4) / 4.0
if episodeSeason != episode.get('airedSeason'):
if episode.get('airedSeason') == 0:
ratio = 0.72 * ratio
else:
ratio = 0.80 * ratio
addon_log('tvdb ratio: \'{0}\'; \'{1}\' (TVDB); ratio={2:0.1f} ({3:0.1f} {4:0.1f} {5:0.1f} {6:0.1f})'.format(epName, episode.get('episodeName'), ratio, ratio1, ratio2, ratio3, ratio4))
if ratio > ratio_max:
if ratio_max > 0 and not (ratio_max_season == episode.get('airedSeason') and ratio_max_episode == episode.get('airedEpisodeNumber')):
ratio_max2 = ratio_max
def translate(self, algo):
algo_std = to_std_case(algo)
for a in self.algos:
if fuzz.partial_ratio(a, algo_std) > 85:
return a
self.algos.append(algo_std)
return algo_std
def is_similar_to(self, other: PredictedSubtitle) -> bool:
return fuzz.partial_ratio(self.text, other.text) >= self.sim_threshold
continue
candidate_to_add = None
# if the series id is set then find all shows belonging to that series
if( args.sid is not None ):
if( 'sid' in schedule_item and schedule_item['sid'] in args.sid):
candidate_to_add = schedule_item
elif( args.pid is not None ):
if( 'pid' in schedule_item and schedule_item['pid'] in args.pid):
candidate_to_add = schedule_item
elif( args.find is not None ):
if( 'title' in schedule_item and fuzz.partial_ratio( args.find, createShowTitle(schedule_item, args.originaltitle) ) > 85 ):
candidate_to_add = schedule_item
elif( 'title' in schedule_item and fuzz.partial_ratio( args.find, schedule_item['title'] ) > 85 ):
candidate_to_add = schedule_item
elif( 'original-title' in schedule_item and not schedule_item['original-title'] is None and fuzz.partial_ratio( args.find, schedule_item['original-title'] ) > 85 ):
candidate_to_add = schedule_item
else:
# By default if there is no filtering then we simply list everything in the schedule
candidate_to_add = schedule_item
# If the only new episode filter is set then only include shows that have recently started airing
if( args.new ):
# If the show is not a repeat show or hasn't got more than a single episode in total then it isn't considered a show so exclude it
if( not 'ep_num' in schedule_item or not 'ep_total' in schedule_item or int( schedule_item['ep_total']) < 2 or int(schedule_item['ep_num']) > 1 ):
candidate_to_add = None # If the show is beyond ep 1 then it cannot be considered a new show so i'm not going to add it
# Now process the adding of the show if all the filter criteria were satisified
if( candidate_to_add is not None ):
download_list.append(candidate_to_add)
total_items = len(download_list)
----------
query: str
Question to Ask
Returns
-------
answer: str
Answer, if any, else None
"""
ratio = 0
answer = None
# Fuzzily try to find best matching query
for Q, A in self.QNA_STATIC.items():
r = fuzz.partial_ratio(query, Q)
if r > ratio:
answer = A
ratio = r
for Q, A in self.QNA_DYNAMIC.items():
r = fuzz.partial_ratio(query, Q)
if r > ratio:
answer = A()
ratio = r
if ratio > 90:
return float(ratio)/100, answer
def _translateUtteranceIntoInputVector(self,utter, call):
#Metainfo+BOW+SLOT/Value matching result
#--CLASS
convClassInput=None
if (utter["transcript"] not in LSTMWithBOWTracker.dictFuzzyMatchingResult):
convClassInput=[0.0]*self.TOTALSIZEOFCLASSFeature
for topic in self.tagsets.keys():
for slot in self.tagsets[topic].keys():
convClassInput[self.dictIn["CLASS_"+slot]]=fuzz.partial_ratio(slot, utter["transcript"])
for value in self.tagsets[topic][slot]:
convClassInput[self.dictIn["CLASS_"+value]]=fuzz.partial_ratio(value, utter["transcript"])
LSTMWithBOWTracker.dictFuzzyMatchingResult[utter["transcript"]]=copy.deepcopy(convClassInput)
else:
convClassInput=LSTMWithBOWTracker.dictFuzzyMatchingResult[utter["transcript"]]
#-input
convSentenceInput=None
if not self.isUseSentenceRepresentationInsteadofBOW:
convSentenceInput=[0.0]*self.TOTALSIZEOFSENTENCEFeature
convSentenceInput[self.dictIn["SPEAKER_"+utter["speaker"]]]=1.0
convSentenceInput[self.dictIn["TOPIC_"+utter["segment_info"]["topic"]]]=1.0
splitedtrans=self.__getRegurelisedBOW(utter["transcript"])
for word in splitedtrans:
if ("WORD_"+word) in self.dictIn:#IGNORING OOV
convSentenceInput[self.dictIn["WORD_"+word]]=1.0