package org.apache.lucene.analysis.fr;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import java.util.Iterator;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.TokenFilter;

/**
 * Removes elisions from a token stream. For example, "l'avion" (the plane) will be
 * tokenized as "avion" (plane).
 * 
 * @author Mathieu Lecarme<mlecarme@openwide.fr>
 * @see{http://fr.wikipedia.org/wiki/%C3%89lision}
 * 
 * Note that StandardTokenizer sees "’" as a space, and cuts it out.
 */
public class ElisionFilter extends TokenFilter {
  private Set articles = null;

  private static String apostrophes = "'’";

  public void setArticles(Set articles) {
    this.articles = new HashSet();
    Iterator iter = articles.iterator();
    while (iter.hasNext()) {
      this.articles.add(((String) iter.next()).toLowerCase());
    }
  }

  /**
   * Constructs an elision filter with standard stop words
   */
  protected ElisionFilter(TokenStream input) {
    super(input);
    this.articles = new HashSet(Arrays.asList(new String[] { "l", "m", "t",
        "qu", "n", "s", "j" }));
  }

  /**
   * Constructs an elision filter with a Set of stop words
   */
  public ElisionFilter(TokenStream input, Set articles) {
    super(input);
    setArticles(articles);
  }

  /**
   * Constructs an elision filter with an array of stop words
   */
  public ElisionFilter(TokenStream input, String[] articles) {
    super(input);
    setArticles(new HashSet(Arrays.asList(articles)));
  }

  /**
   * Returns the next input Token whith termText() without elisioned start
   */
  public Token next() throws IOException {
    Token t = input.next();
    if (t == null)
      return null;
    String text = t.termText();
    System.out.println(text);
    int minPoz = -1;
    int poz;
    for (int i = 0; i < apostrophes.length(); i++) {
      poz = text.indexOf(apostrophes.charAt(i));
      if (poz != -1)
        minPoz = (minPoz == -1) ? poz : Math.min(poz, minPoz);
    }
    if (minPoz != -1
        && articles.contains(text.substring(0, minPoz).toLowerCase()))
      text = text.substring(minPoz + 1);
    return new Token(text, t.startOffset(), t.endOffset(), t.type());
  }

}

@@ -1229,181 +1229,241 @@
 %0A * 
+%3Cp%3E
 %0A * 
-@author Mathieu Lecarme%3Cmlecarme@openwide.fr%3E%0A * @see%7Bhttp://fr.wikipedia.org/wiki/%25C3%2589lision%7D%0A * %0A * Note that StandardTokenizer sees %22%E2%80%99%22 as a space, and cuts it out.
+Note that StandardTokenizer sees %22 ' %22 as a space, and cuts it out.%0A * %0A * @see %3Ca href=%22http://fr.wikipedia.org/wiki/%25C3%2589lision%22%3EElision in Wikipedia%3C/a%3E %0A * @author %3Ca href=%22mailto:mlecarme@openwide.fr%22%3EMathieu Lecarme%3C/a%3E
 %0A */

fix javadoc unknown tag warning.