title: Calculate tf-idf of strings
body: <p>I have 2 documents <code>doc1.txt</code> and <code>doc2.txt</code>. The contents of these 2 documents are:</p>
  
  <pre><code> #doc1.txt
   very good, very bad, you are great
  
   #doc2.txt
   very bad, good restaurent, nice place to visit
  </code></pre>
  
  <p>I want to make my corpus separated with <code>,</code> so that my final <code>DocumentTermMatrix</code> becomes:</p>
  
  <pre><code>      terms
   docs       very good      very bad        you are great   good restaurent   nice place to visit
   doc1       tf-idf          tf-idf         tf-idf          0                    0
   doc2       0               tf-idf         0               tf-idf             tf-idf
  </code></pre>
  
  <p>I know, how to calculate <code>DocumentTermMatrix</code> of individual words (using <a href="http://scikit-learn.org/stable/modules/feature_extraction.html" rel="nofollow">http://scikit-learn.org/stable/modules/feature_extraction.html</a>) but don't know how to calculate <code>DocumentTermMatrix</code> of <code>strings</code> in Python.</p>