<commit_before>/*
 * Copyright 2017 IBM Corp. All Rights Reserved.
 *
 * Licensed 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.
 */
package com.ibm.watson.developer_cloud.speech_to_text.v1.model;

import com.google.gson.annotations.SerializedName;
import com.ibm.watson.developer_cloud.http.HttpMediaType;
import com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText;
import com.ibm.watson.developer_cloud.util.Validator;

import okhttp3.MediaType;


/**
 * Parameters to be use during a recognize call in the {@link SpeechToText} service.
 */
public class RecognizeOptions {

  /**
   * Builder.
   */
  public static class Builder {
    private String contentType;
    private Boolean continuous;
    private Integer inactivityTimeout;
    private Boolean interimResults;
    private String[] keywords;
    private Double keywordsThreshold;
    private Integer maxAlternatives;
    private String model;
    private String sessionId;
    private Boolean timestamps;
    private Double wordAlternativesThreshold;
    private Boolean wordConfidence;
    private Boolean profanityFilter;
    private Boolean smartFormatting;
    private String customizationId;
    private Boolean speakerLabels;

    private Builder(RecognizeOptions options) {
      contentType = options.contentType;
      continuous = options.continuous;
      inactivityTimeout = options.inactivityTimeout;
      interimResults = options.interimResults;
      keywords = options.keywords;
      keywordsThreshold = options.keywordsThreshold;
      maxAlternatives = options.maxAlternatives;
      model = options.model;
      sessionId = options.sessionId;
      timestamps = options.timestamps;
      wordAlternativesThreshold = options.wordAlternativesThreshold;
      wordConfidence = options.wordConfidence;
      profanityFilter = options.profanityFilter;
      smartFormatting = options.smartFormatting;
      customizationId = options.customizationId;
      speakerLabels = options.speakerLabels;
    }

    /**
     * Instantiates a new builder.
     */
    public Builder() { }

    /**
     * Builds the profile options.
     *
     * @return the profile options
     */
    public RecognizeOptions build() {
      return new RecognizeOptions(this);
    }

    /**
     * The format of the audio data specified as one of the following values: <br>
     * <ul>
     * <li><code>audio/flac</code> for Free Lossless Audio Codec (FLAC)</li>
     * <li><code>audio/l16</code> for Linear 16-bit Pulse-Code Modulation (PCM).</li>
     * <li><code>audio/wav</code> for Waveform Audio File Format (WAV)</li>
     * <li><code>audio/ogg;codecs=opus</code> for Ogg format files that use the opus codec</li>
     * </ul>
     * .
     *
     * @param contentType the content type
     * @return the recognize options
     * @throws IllegalArgumentException when contentType is null or invalid
     */
    public Builder contentType(String contentType) {
      Validator.isTrue((MediaType.parse(contentType) != null) && contentType.startsWith("audio/"),
          "contentType is not a valid mime audio format. Valid formats start with 'audio/'");

      Validator.isTrue(!contentType.contains(HttpMediaType.AUDIO_RAW) || contentType.contains("rate"),
          "When using PCM the audio rate should be specified.");

      this.contentType = contentType;
      return this;
    }

    /**
     * If <code>true</code>, converts dates, times, series of digits and numbers, phone numbers, currency values, and
     * Internet addresses into more readable, conventional representations in the final transcript of a recognition
     * request. If <code>false</code> (the default), no formatting is performed. Applies to US English transcription
     * only.
     *
     * @param smartFormatting Smart formatting
     * @return the recognize options
     */
    public Builder smartFormatting(Boolean smartFormatting) {
      this.smartFormatting = smartFormatting;
      return this;
    }

    /**
     * If <code>true</code>, adds speaker labels to the transcript.
     *
     * @param  speakerLabels Labels or "diarization"
     * @return the recognize options
     */
    public Builder speakerLabels(Boolean speakerLabels) {
      this.speakerLabels = speakerLabels;
      return this;
    }

    /**
     * If true, filters profanity from all output except for keyword results by replacing inappropriate words with a
     * series of asterisks. Set the parameter to false to return results with no censoring. Applies to US English
     * transcription only.
     *
     * @param profanityFilter the profanity filter
     * @return the recognize options
     */
    public Builder profanityFilter(Boolean profanityFilter) {
      this.profanityFilter = profanityFilter;
      return this;
    }

    /**
     * If true, multiple final results that represent multiple consecutive phrases separated by pauses are returned.
     * Otherwise, the recognition ends after first "end of speech" is detected.
     *
     * @param continuous the continuous
     * @return the recognize options
     */
    public Builder continuous(Boolean continuous) {
      this.continuous = continuous;
      return this;
    }

    /**
     * Inactivity timeout.
     *
     * @param inactivityTimeout the inactivity timeout
     * @return the recognize options
     */
    public Builder inactivityTimeout(Integer inactivityTimeout) {
      this.inactivityTimeout = inactivityTimeout;
      return this;
    }

    /**
     * If true, the service sends interim results for the transcription. Otherwise, the recognition ends after first
     * "end of speech" is detected. The default is false.<commit_msg>Update javadoc for interimResult, fixes #504<commit_after>/*
 * Copyright 2017 IBM Corp. All Rights Reserved.
 *
 * Licensed 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.
 */
package com.ibm.watson.developer_cloud.speech_to_text.v1.model;

import java.io.InputStream;

import com.google.gson.annotations.SerializedName;
import com.ibm.watson.developer_cloud.http.HttpMediaType;
import com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText;
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.RecognizeCallback;
import com.ibm.watson.developer_cloud.util.Validator;

import okhttp3.MediaType;


/**
 * Parameters to be use during a recognize call in the {@link SpeechToText} service.
 */
public class RecognizeOptions {

  /**
   * Builder.
   */
  public static class Builder {
    private String contentType;
    private Boolean continuous;
    private Integer inactivityTimeout;
    private Boolean interimResults;
    private String[] keywords;
    private Double keywordsThreshold;
    private Integer maxAlternatives;
    private String model;
    private String sessionId;
    private Boolean timestamps;
    private Double wordAlternativesThreshold;
    private Boolean wordConfidence;
    private Boolean profanityFilter;
    private Boolean smartFormatting;
    private String customizationId;
    private Boolean speakerLabels;

    private Builder(RecognizeOptions options) {
      contentType = options.contentType;
      continuous = options.continuous;
      inactivityTimeout = options.inactivityTimeout;
      interimResults = options.interimResults;
      keywords = options.keywords;
      keywordsThreshold = options.keywordsThreshold;
      maxAlternatives = options.maxAlternatives;
      model = options.model;
      sessionId = options.sessionId;
      timestamps = options.timestamps;
      wordAlternativesThreshold = options.wordAlternativesThreshold;
      wordConfidence = options.wordConfidence;
      profanityFilter = options.profanityFilter;
      smartFormatting = options.smartFormatting;
      customizationId = options.customizationId;
      speakerLabels = options.speakerLabels;
    }

    /**
     * Instantiates a new builder.
     */
    public Builder() { }

    /**
     * Builds the profile options.
     *
     * @return the profile options
     */
    public RecognizeOptions build() {
      return new RecognizeOptions(this);
    }

    /**
     * The format of the audio data specified as one of the following values: <br>
     * <ul>
     * <li><code>audio/flac</code> for Free Lossless Audio Codec (FLAC)</li>
     * <li><code>audio/l16</code> for Linear 16-bit Pulse-Code Modulation (PCM).</li>
     * <li><code>audio/wav</code> for Waveform Audio File Format (WAV)</li>
     * <li><code>audio/ogg;codecs=opus</code> for Ogg format files that use the opus codec</li>
     * </ul>
     * .
     *
     * @param contentType the content type
     * @return the recognize options
     * @throws IllegalArgumentException when contentType is null or invalid
     */
    public Builder contentType(String contentType) {
      Validator.isTrue((MediaType.parse(contentType) != null) && contentType.startsWith("audio/"),
          "contentType is not a valid mime audio format. Valid formats start with 'audio/'");

      Validator.isTrue(!contentType.contains(HttpMediaType.AUDIO_RAW) || contentType.contains("rate"),
          "When using PCM the audio rate should be specified.");

      this.contentType = contentType;
      return this;
    }

    /**
     * If <code>true</code>, converts dates, times, series of digits and numbers, phone numbers, currency values, and
     * Internet addresses into more readable, conventional representations in the final transcript of a recognition
     * request. If <code>false</code> (the default), no formatting is performed. Applies to US English transcription
     * only.
     *
     * @param smartFormatting Smart formatting
     * @return the recognize options
     */
    public Builder smartFormatting(Boolean smartFormatting) {
      this.smartFormatting = smartFormatting;
      return this;
    }

    /**
     * If <code>true</code>, adds speaker labels to the transcript.
     *
     * @param speakerLabels Labels or "diarization"
     * @return the recognize options
     */
    public Builder speakerLabels(Boolean speakerLabels) {
      this.speakerLabels = speakerLabels;
      return this;
    }

    /**
     * If true, filters profanity from all output except for keyword results by replacing inappropriate words with a
     * series of asterisks. Set the parameter to false to return results with no censoring. Applies to US English
     * transcription only.
     *
     * @param profanityFilter the profanity filter
     * @return the recognize options
     */
    public Builder profanityFilter(Boolean profanityFilter) {
      this.profanityFilter = profanityFilter;
      return this;
    }

    /**
     * If true, multiple final results that represent multiple consecutive phrases separated by pauses are returned.
     * Otherwise, the recognition ends after first "end of speech" is detected.
     *
     * @param continuous the continuous
     * @return the recognize options
     */
    public Builder continuous(Boolean continuous) {
      this.continuous = continuous;
      return this;
    }

    /**
     * Inactivity timeout.
     *
     * @param inactivityTimeout the inactivity timeout
     * @return the recognize options
     */
    public Builder inactivityTimeout(Integer inactivityTimeout) {
      this.inactivityTimeout = inactivityTimeout;
      return this;
    }

    /**
     * If true, the service sends interim results for the transcription. Otherwise, the recognition ends after first
     * "end of speech" is detected. The default is false. This option is only supported with the
     * {@link SpeechToText#recognizeUsingWebSocket(InputStream, RecognizeOptions, RecognizeCallback)}
     * method.
{'fraction_non_alphanumeric': 0.07928185573562123, 'fraction_numerical': 0.0027009850651414044, 'mean_word_length': 3.1963333333333335, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5331124', 'n_tokens_mistral': 3366, 'n_tokens_neox': 3197, 'n_words': 1112}