AnalyzeTextOptions.java

  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.

  3. package com.azure.search.documents.indexes.models;

  4. import com.azure.core.annotation.Fluent;
  5. import com.fasterxml.jackson.annotation.JsonProperty;

  6. import java.util.Arrays;
  7. import java.util.List;

  8. /**
  9.  * Specifies some text and analysis components used to break that text into
  10.  * tokens.
  11.  */
  12. @Fluent
  13. public final class AnalyzeTextOptions {
  14.     /*
  15.      * The text to break into tokens.
  16.      */
  17.     @JsonProperty(value = "text", required = true)
  18.     private final String text;

  19.     /*
  20.      * The name of the analyzer to use to break the given text.
  21.      */
  22.     @JsonProperty(value = "analyzer")
  23.     private LexicalAnalyzerName analyzerName;

  24.     /*
  25.      * The name of the tokenizer to use to break the given text.
  26.      */
  27.     @JsonProperty(value = "tokenizer")
  28.     private LexicalTokenizerName tokenizerName;

  29.     /*
  30.      * The name of the normalizer to use to normalize the given text.
  31.      */
  32.     @JsonProperty(value = "normalizer")
  33.     private LexicalNormalizerName normalizerName;

  34.     /*
  35.      * An optional list of token filters to use when breaking the given text.
  36.      */
  37.     @JsonProperty(value = "tokenFilters")
  38.     private List<TokenFilterName> tokenFilters;

  39.     /*
  40.      * An optional list of character filters to use when breaking the given
  41.      * text.
  42.      */
  43.     @JsonProperty(value = "charFilters")
  44.     private List<CharFilterName> charFilters;

  45.     /**
  46.      * Constructor to {@link AnalyzeTextOptions} which takes analyzerName.
  47.      *
  48.      * @param text The text break into tokens.
  49.      * @param analyzerName The name of the analyzer to use to break the given text.
  50.      */
  51.     public AnalyzeTextOptions(String text, LexicalAnalyzerName analyzerName) {
  52.         this.text = text;
  53.         this.analyzerName = analyzerName;
  54.         this.tokenizerName = null;
  55.         this.normalizerName = null;
  56.     }

  57.     /**
  58.      * Constructor to {@link AnalyzeTextOptions} which takes tokenizerName.
  59.      *
  60.      * @param text The text break into tokens.
  61.      * @param tokenizerName The name of the tokenizer to use to break the given text.
  62.      */
  63.     public AnalyzeTextOptions(String text, LexicalTokenizerName tokenizerName) {
  64.         this.text = text;
  65.         this.tokenizerName = tokenizerName;
  66.         this.analyzerName = null;
  67.         this.normalizerName = null;
  68.     }

  69.     /**
  70.      * Constructor to {@link AnalyzeTextOptions} which takes normalizerName.
  71.      *
  72.      * @param text The text break into tokens.
  73.      * @param normalizerName The name of the normalizer to use to break the given text.
  74.      */
  75.     public AnalyzeTextOptions(String text, LexicalNormalizerName normalizerName) {
  76.         this.text = text;
  77.         this.normalizerName = normalizerName;
  78.         this.analyzerName = null;
  79.         this.tokenizerName = null;
  80.     }

  81.     /**
  82.      * Get the text property: The text to break into tokens.
  83.      *
  84.      * @return the text value.
  85.      */
  86.     public String getText() {
  87.         return this.text;
  88.     }

  89.     /**
  90.      * Get the analyzer name property: The name of the analyzer to use to break the given text.
  91.      *
  92.      * @return the analyzer value.
  93.      */
  94.     public LexicalAnalyzerName getAnalyzerName() {
  95.         return this.analyzerName;
  96.     }

  97.     /**
  98.      * Get the tokenizer name property: The name of the tokenizer to use to break the given text.
  99.      *
  100.      * @return the tokenizer value.
  101.      */
  102.     public LexicalTokenizerName getTokenizerName() {
  103.         return this.tokenizerName;
  104.     }

  105.     /**
  106.      * Get the normalizer name property: The name of the normalizer to use to normalize the given text.
  107.      *
  108.      * @return the normalizer value.
  109.      */
  110.     public LexicalNormalizerName getNormalizer() {
  111.         return this.normalizerName;
  112.     }

  113.     /**
  114.      * Get the tokenFilters property: An optional list of token filters to use when breaking the given text.
  115.      *
  116.      * @return the tokenFilters value.
  117.      */
  118.     public List<TokenFilterName> getTokenFilters() {
  119.         return this.tokenFilters;
  120.     }

  121.     /**
  122.      * Set the tokenFilters property: An optional list of token filters to use when breaking the given text.
  123.      *
  124.      * @param tokenFilters the tokenFilters value to set.
  125.      * @return the AnalyzeRequest object itself.
  126.      */
  127.     public AnalyzeTextOptions setTokenFilters(TokenFilterName... tokenFilters) {
  128.         this.tokenFilters = (tokenFilters == null) ? null : Arrays.asList(tokenFilters);
  129.         return this;
  130.     }

  131.     /**
  132.      * Get the charFilters property: An optional list of character filters to use when breaking the given text.
  133.      *
  134.      * @return the charFilters value.
  135.      */
  136.     public List<CharFilterName> getCharFilters() {
  137.         return this.charFilters;
  138.     }

  139.     /**
  140.      * Set the charFilters property: An optional list of character filters to use when breaking the given text.
  141.      *
  142.      * @param charFilters the charFilters value to set.
  143.      * @return the AnalyzeRequest object itself.
  144.      */
  145.     public AnalyzeTextOptions setCharFilters(CharFilterName... charFilters) {
  146.         this.charFilters = (charFilters == null) ? null : Arrays.asList(charFilters);
  147.         return this;
  148.     }
  149. }