<jupyter_start><jupyter_text>Step1. User enters the hike URLStep2. Check if hike URL already exists in hikes_dfStep2b. If it does not, scrape the data from the url Step3. Scale the new data (using the transform method)Step4. Calculate the cosine similarity between hikes_df and new_nike_dataStep5. Sort the cosine similarity scores and subset to the requested number of recommendationsStep6. Get the index of the recommendations and subset hikes_df Step7. Return the recommendations<jupyter_code>def index_from_url(df, url):
    return df[df['hike_url']==title].index.values[0]
 
# function that returns hike url from its index
def url_from_index(df, index):
    return df[df.index==index].hike_url.values[0]
# generating recommendations for given url
def get_recommendations(new_hike_url, df, number_of_recommendations):
 
    # index = index_from_url(df, new_hike_url)
    
    new_data = get_one_hike(new_hike_url)
    
    np_array = df.values
    
    cosine_similarity_matrix = cosine_similarity(np_array, new_data.values.reshape(1, -1))

    similarity_scores = list(enumerate(cosine_similarity_matrix[index]))

    similarity_scores_sorted = sorted(similarity_scores, key=lambda x: x[1], reverse=True)

    recommendations_indices = [t[0] for t in similarity_scores_sorted[1:(number_of_recommendations+1)]]

    return hikes_df['hike_url'].iloc[recommendations_indices]
 
# recommendations('tbd', df, 10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0825242718446602, 'fraction_numerical': 0.012482662968099861, 'mean_word_length': 5.649769585253456, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '454913', 'license': 'MIT', 'n_tokens_mistral': 491, 'n_tokens_neox': 460, 'n_words': 123, 'path': 'notebooks/test_cosine_similarity.ipynb', 'repo_name': 'annnvv/hiking_upward_recommender', 'size': '1442'}