title: Getting 'trigrams' in Java
body: <p>I am having a bit of an issue getting <code>trigrams</code> in Java.  My program can currently get <code>bigrams</code> fine but when I try to implement the same structure of the method and change it to get <code>trigrams</code> it seems to not work as well. 
  I want the <code>trigrams</code> to get every possible combination of words within the <code>arraylist</code>, e.g.</p>
  
  <pre><code>Original = [eye, test, find, free, nhs]
  Trigram = [eye test find, 2, eye test free, 3, eye test nhs, 4, eye find free, 3, eye find nhs, 4, eye free nhs, 5, etc...]
  </code></pre>
  
  <p>The numbers determine the distance between the first word and the last word and should get every combination of words of a 3 in the <code>arraylist</code>.  This currently works fine for <code>bigrams</code>...</p>
  
  <pre><code>Original = [eye, test, find, free, nhs]
  Bigram = [eye test, 1, eye find, 2, eye free, 3, eye nhs, 4, test find, 1, test free, 2, test nhs, 3, find free, 1, etc..]
  </code></pre>
  
  <p>Here are the methods</p>
  
  <pre><code>public ArrayList&lt;String&gt; bagOfWords;
  public ArrayList&lt;String&gt; bigramList = new ArrayList&lt;String&gt;();
  public ArrayList&lt;String&gt; trigramList = new ArrayList&lt;String&gt;();
  
  
  public void trigram() throws FileNotFoundException{
      PrintWriter tg = new PrintWriter(new File(trigramFile));
      // CREATES THE TRIGRAM
      for (int i = 0; i &lt; bagOfWords.size() - 1; i++) {
          for (int j = 1; j &lt; bagOfWords.size() - 1; j++) {
              for(int k = j + 1; k &lt; bagOfWords.size(); k++){
                  int distance = (k - i);
                  if (distance &lt; 4){
                      trigramList.add(bagOfWords.get(i) + " " + bagOfWords.get(j) + " " + bagOfWords.get(k) + ", " + distance);
                  }
              }
          }
      }
  
  
  public void bigram() throws FileNotFoundException{
      // CREATES THE BIGRAM
      PrintWriter bg = new PrintWriter(new File(bigramFile));
      for (int i = 0; i &lt; bagOfWords.size() - 1; i++) {
          for (int j = i + 1; j &lt; bagOfWords.size(); j++) {
              int distance = (j - i);
              if (distance &lt; 4){
                  bigramList.add(bagOfWords.get(i) + " " + bagOfWords.get(j) + ", " + distance);
              }
          }
      }
  </code></pre>
  
  <p>Can anyone help me alter the <code>trigram()</code> method to create an appropriate <code>trigram</code> for what I need? 
  Thanks for any help.</p>