content: /* 
   * Copyright (C) 2015 Adrien Guille <adrien.guille@univ-lyon2.fr>
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  package main.java.fr.ericlab.sondy.core.text.index;
  
  import java.io.IOException;
  import java.io.StringReader;
  import java.util.ArrayList;
  import java.util.List;
  import org.apache.lucene.analysis.TokenStream;
  import org.apache.lucene.analysis.standard.StandardAnalyzer;
  import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
  
  /**
   *
   *   @author Adrien GUILLE, ERIC Lab, University of Lyon 2
   *   @email adrien.guille@univ-lyon2.fr
   */
  public class Tokenizer {
      
      public static List<String> tokenizeString(org.apache.lucene.analysis.Analyzer analyzer, String string) {
          List<String> result = new ArrayList<>(20);
          try {
              TokenStream stream  = analyzer.tokenStream(null, new StringReader(string));
              stream.reset();
              while (stream.incrementToken()) {
                  result.add(stream.getAttribute(CharTermAttribute.class).toString());
              }
              stream.close();
          } catch (IOException e) {}
          return result;
      }
      
      public static List<String> tokenizeString(String string) {
          return tokenizeString(new StandardAnalyzer(), string);
      }
  }
  