All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.index.analysis.stemmer.turkish.states.DerivationalState Maven / Gradle / Ivy

There is a newer version: 7.7.0.2
Show newest version
package org.elasticsearch.index.analysis.stemmer.turkish.states;

import java.util.EnumSet;
import java.util.List;

import org.elasticsearch.index.analysis.stemmer.turkish.suffixes.DerivationalSuffix;
import org.elasticsearch.index.analysis.stemmer.turkish.suffixes.Suffix;
import org.elasticsearch.index.analysis.stemmer.turkish.transitions.Transition;

public enum DerivationalState implements State {
  A(true, false, EnumSet.of(DerivationalSuffix.S1)) {
    @Override
    public State nextState(final Suffix suffix) {
      switch((DerivationalSuffix) suffix) {
        case S1:
          return B;
        default:
          return null;
      }
    }
  },

  B(false, true, EnumSet.noneOf(DerivationalSuffix.class)) {
    @Override
    public State nextState(final Suffix suffix) {
      return null;
    }
  };

  private boolean initialState;
  private boolean finalState;
  private EnumSet suffixes;

  private DerivationalState(final boolean initialState,
                            final boolean finalState,
                            final EnumSet suffixes) {

    this.initialState = initialState;
    this.finalState = finalState;
    this.suffixes = suffixes;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public boolean initialState() {
    return this.initialState;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public boolean finalState() {
    return this.finalState;
  }

  public static DerivationalState getInitialState() {
    for(DerivationalState state : values()) {
      if(state.initialState())
        return state;
    }

    return null;
  }

  public EnumSet suffixes() {
    return this.suffixes;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void addTransitions(final String word,
                             final List transitions,
                             final boolean marked) {

    for(Suffix suffix : suffixes()) {
      if(suffix.match(word)) {
        transitions.add(new Transition(this, nextState(suffix),
            word, suffix, marked));
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy