def testrun_dice_coefficient(self): string = 'Die Katze lauft im Schnee! CF3, Benzene' srch1 = 'Katz' srch2 = 'Benze' srch3 = 'Hallo du' srch4 = '124' dice1 = misc.dice_coefficient(string, srch1) dice2 = misc.dice_coefficient(string, srch2) dice3 = misc.dice_coefficient(string, srch3) dice4 = misc.dice_coefficient(string, srch4) self.assertEqual(dice1, 0.162162) self.assertEqual(dice2, 0.210526) self.assertEqual(dice3, 0.0) self.assertEqual(dice4, 0.0)
def download_subtitle(tvshow, season, episode, language): """ This is a shortcut function to download a subtitle. It actually runs most of the function of the file in the correct order to make downloading of a subtitle easy. Searches for the tvshow id, then searches for the episode id, and then searches for the subtitle id, and then downloads the file and reads it ! @param tvshow: Tvshow name @param season: Season number @param episode: Episode number @param language: Language of the subtitle required """ tvshowids = search_tvshow(tvshow) # Let's find the tv show that matches the best tvid = None best_match = 0 for showid, showname in tvshowids: match = misc.dice_coefficient(showname, tvshow, ignore_case=True) if match > best_match and match > MINIMUM_COEF: best_match = match tvid = showid if not tvid: return None episodeid = search_episode(tvid, season, episode) subid = search_subtitles(episodeid, language) if not subid: return None return download_subid(subid[0])
def __score_name(self, given, guessed): """ Calculate score based on name @param given: Given movie name @param guessed: Guessed movie name @return: score calculated. Range from 0 to 1. @rtype: float """ score = misc.strings_contained(guessed, given) score += misc.dice_coefficient(guessed, given) assert 0 <= score <= 2 return score / 2