Advertisement
Guest User

check for duplicate themes

a guest
Apr 8th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @author: rohezal
  5. """
  6.  
  7. def cleanTheme(theme):
  8.     filler_words = ["the", "and", "an", "a", "or", "is", "was", ".", "...", "!", "?", ","]  
  9.     theme = theme.lower()
  10.     theme_as_list = theme.split(" ")
  11.     clean_theme = ""
  12.     for word in theme_as_list:
  13.         if word not in filler_words:
  14.             clean_theme = clean_theme  + word + " "
  15.     clean_theme = clean_theme.strip()
  16.     return clean_theme
  17.  
  18. def findSimilarThemes(new_theme, themes):
  19.     new_theme_list = new_theme.split()
  20.     result_list = []
  21.     for existing_theme in themes:
  22.         existing_theme_list = existing_theme.split()
  23.         for word in new_theme_list:
  24.             if word in existing_theme_list:
  25.                 result_list.append(existing_theme)
  26.                 break
  27.     return result_list
  28.  
  29. def checkForDuplicateTheme(new_theme, themes):
  30.     return new_theme in themes
  31.    
  32.  
  33. suggested_themes = ["Loving the whole world", "The dog is evil", "Enough is enough", "And the world is not enough ..."]
  34. suggested_themes_clean = []
  35.  
  36. for theme in suggested_themes:
  37.     suggested_themes_clean.append(cleanTheme(theme))
  38.  
  39. mytheme = "The world is not enough"
  40. clean_theme = cleanTheme(mytheme)
  41. matching_themes = findSimilarThemes(clean_theme,suggested_themes_clean)
  42. is_duplicate = checkForDuplicateTheme(clean_theme, suggested_themes_clean)
  43.  
  44. print (clean_theme)
  45. print(matching_themes)
  46. print("Is duplicated: " + str(is_duplicate))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement