def similar_document(first_book, second_book): if first_book == '1' or first_book == '2' or first_book == '3' or first_book == '4': if second_book == '1' or second_book == '2' or second_book == '3' or second_book == '4': percentage = Task4.sentence_similarity( first_book, second_book ) #trigger the function sentence similarity that will return the score of similarity between two books return "The similarity between the two documents is =" + str( percentage ) + " percent" #return the score of similarity between two books return "Books only from 1 to 4"
def similarity_of_all(string='all'): if string.lower() == 'all': list_of_sim_matrix = dict( ) #creating a dictionary for the similarities score count = 1 #intializing count with 1 which having index of book 1 while (count <= 4): #iterate through all 4 books count_for_second_book = 4 #sceond count has second book indexes while (count_for_second_book >= 1): #conditions for books remain in the limit percentage_of_each = Task4.sentence_similarity( str(count), str(count_for_second_book) ) #triggering task 4 function to get the similarity between two book at a ttime list_of_sim_matrix[str(count) + ' and ' + str(count_for_second_book)] = str( percentage_of_each) count_for_second_book -= 1 #decreement book second count += 1 #increement book first return json.dumps(list_of_sim_matrix) return "Not a required String"