title: Calculate cosine similarity given 2 sentence strings
body: <p>From <a href="https://stackoverflow.com/questions/12118720/python-tf-idf-cosine-to-find-document-similarity">Python: tf-idf-cosine: to find document similarity</a> , it is possible to calculate document similarity using tf-idf cosine. Without importing external libraries, are that any ways to calculate cosine similarity between 2 strings?</p>
  
  <pre><code>s1 = "This is a foo bar sentence ."
  s2 = "This sentence is similar to a foo bar sentence ."
  s3 = "What is this string ? Totally not related to the other two lines ."
  
  cosine_sim(s1, s2) # Should give high cosine similarity
  cosine_sim(s1, s3) # Shouldn't give high cosine similarity value
  cosine_sim(s2, s3) # Shouldn't give high cosine similarity value
  </code></pre>