Skip to content

Commit

Permalink
Generate Tokenizer variants
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Nov 12, 2024
1 parent f73cd06 commit 9df0451
Show file tree
Hide file tree
Showing 30 changed files with 16,888 additions and 15,678 deletions.
5 changes: 4 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ After:
- `variabletop` -> `variableTop`

### TokenFilterDefinition
- The `smartcn_stop` Builder method has been renamed to `smartcnStop`.
- The `smartcn_stop` Builder method has been renamed to `smartcnStop`.

### TokenizerDefinition
- The `smartcn` Builder method has been renamed to `smartcnTokenizer`.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@
* GitHub history for details.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package org.opensearch.client.opensearch._types.analysis;

import jakarta.json.stream.JsonGenerator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Generated;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
Expand All @@ -47,41 +54,35 @@
// typedef: _types.analysis.CharGroupTokenizer

@JsonpDeserializable
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class CharGroupTokenizer extends TokenizerBase implements TokenizerDefinitionVariant {
private final List<String> tokenizeOnChars;

@Nullable
private final Integer maxTokenLength;

@Nonnull
private final List<String> tokenizeOnChars;

// ---------------------------------------------------------------------------------------------

private CharGroupTokenizer(Builder builder) {
super(builder);

this.tokenizeOnChars = ApiTypeHelper.unmodifiableRequired(builder.tokenizeOnChars, this, "tokenizeOnChars");
this.maxTokenLength = builder.maxTokenLength;

this.tokenizeOnChars = ApiTypeHelper.unmodifiableRequired(builder.tokenizeOnChars, this, "tokenizeOnChars");
}

public static CharGroupTokenizer of(Function<Builder, ObjectBuilder<CharGroupTokenizer>> fn) {
public static CharGroupTokenizer of(Function<CharGroupTokenizer.Builder, ObjectBuilder<CharGroupTokenizer>> fn) {
return fn.apply(new Builder()).build();
}

/**
* TokenizerDefinition variant kind.
* {@link TokenizerDefinition} variant kind.
*/
@Override
public TokenizerDefinition.Kind _tokenizerDefinitionKind() {
return TokenizerDefinition.Kind.CharGroup;
}

/**
* Required - API name: {@code tokenize_on_chars}
*/
public final List<String> tokenizeOnChars() {
return this.tokenizeOnChars;
}

/**
* API name: {@code max_token_length}
*/
Expand All @@ -90,44 +91,54 @@ public final Integer maxTokenLength() {
return this.maxTokenLength;
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
/**
* Required - API name: {@code tokenize_on_chars}
*/
@Nonnull
public final List<String> tokenizeOnChars() {
return this.tokenizeOnChars;
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.write("type", "char_group");
super.serializeInternal(generator, mapper);
if (ApiTypeHelper.isDefined(this.tokenizeOnChars)) {
generator.writeKey("tokenize_on_chars");
generator.writeStartArray();
for (String item0 : this.tokenizeOnChars) {
generator.write(item0);

}
generator.writeEnd();

}
if (this.maxTokenLength != null) {
generator.writeKey("max_token_length");
generator.write(this.maxTokenLength);

}

generator.writeKey("tokenize_on_chars");
generator.writeStartArray();
for (String item0 : this.tokenizeOnChars) {
generator.write(item0);
}
generator.writeEnd();
}

// ---------------------------------------------------------------------------------------------

/**
* Builder for {@link CharGroupTokenizer}.
*/

public static class Builder extends TokenizerBase.AbstractBuilder<Builder> implements ObjectBuilder<CharGroupTokenizer> {
private List<String> tokenizeOnChars;

@Nullable
private Integer maxTokenLength;
private List<String> tokenizeOnChars;

/**
* API name: {@code max_token_length}
*/
public final Builder maxTokenLength(@Nullable Integer value) {
this.maxTokenLength = value;
return this;
}

/**
* Required - API name: {@code tokenize_on_chars}
*
* <p>
* Adds all elements of <code>list</code> to <code>tokenizeOnChars</code>.
* </p>
*/
public final Builder tokenizeOnChars(List<String> list) {
this.tokenizeOnChars = _listAddAll(this.tokenizeOnChars, list);
Expand All @@ -136,22 +147,16 @@ public final Builder tokenizeOnChars(List<String> list) {

/**
* Required - API name: {@code tokenize_on_chars}
*
* <p>
* Adds one or more values to <code>tokenizeOnChars</code>.
* </p>
*/
public final Builder tokenizeOnChars(String value, String... values) {
this.tokenizeOnChars = _listAdd(this.tokenizeOnChars, value, values);
return this;
}

/**
* API name: {@code max_token_length}
*/
public final Builder maxTokenLength(@Nullable Integer value) {
this.maxTokenLength = value;
return this;
}

@Override
protected Builder self() {
return this;
Expand All @@ -160,8 +165,7 @@ protected Builder self() {
/**
* Builds a {@link CharGroupTokenizer}.
*
* @throws NullPointerException
* if some of the required fields are null.
* @throws NullPointerException if some of the required fields are null.
*/
public CharGroupTokenizer build() {
_checkSingleUse();
Expand All @@ -181,11 +185,29 @@ public CharGroupTokenizer build() {
);

protected static void setupCharGroupTokenizerDeserializer(ObjectDeserializer<CharGroupTokenizer.Builder> op) {
TokenizerBase.setupTokenizerBaseDeserializer(op);
op.add(Builder::tokenizeOnChars, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "tokenize_on_chars");
setupTokenizerBaseDeserializer(op);
op.add(Builder::maxTokenLength, JsonpDeserializer.integerDeserializer(), "max_token_length");
op.add(Builder::tokenizeOnChars, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "tokenize_on_chars");

op.ignore("type");
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + Objects.hashCode(this.maxTokenLength);
result = 31 * result + this.tokenizeOnChars.hashCode();
return result;
}

@Override
public boolean equals(Object o) {
if (!super.equals(o)) {
return false;
}
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
CharGroupTokenizer other = (CharGroupTokenizer) o;
return Objects.equals(this.maxTokenLength, other.maxTokenLength) && this.tokenizeOnChars.equals(other.tokenizeOnChars);
}
}
Loading

0 comments on commit 9df0451

Please sign in to comment.