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

technology.semi.weaviate.client.v1.graphql.query.argument.NearTextArgument Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
// Generated by delombok at Tue Dec 20 18:59:22 UTC 2022
package technology.semi.weaviate.client.v1.graphql.query.argument;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

public class NearTextArgument implements Argument {
  private final String[] concepts;
  private final Float certainty;
  private final Float distance;
  private final NearTextMoveParameters moveTo;
  private final NearTextMoveParameters moveAwayFrom;
  private final Boolean autocorrect;

  private String getConcepts(String[] concepts) {
    return Stream.of(concepts).map(f -> String.format("\"%s\"", f)).collect(Collectors.joining(", "));
  }

  private String buildMoveParam(String name, NearTextMoveParameters moveParam) {
    Set arg = new LinkedHashSet<>();
    if (ArrayUtils.isNotEmpty(moveParam.getConcepts())) {
      arg.add(String.format("concepts: [%s]", getConcepts(moveParam.getConcepts())));
    }
    if (moveParam.getForce() != null) {
      arg.add(String.format("force: %s", moveParam.getForce()));
    }
    if (ArrayUtils.isNotEmpty(moveParam.getObjects())) {
      String objects = Arrays.stream(moveParam.getObjects()).map(this::mapObjectMoveToStringClause).collect(Collectors.joining(","));
      arg.add(String.format("objects: [%s]", objects));
    }
    return String.format("%s: {%s}", name, StringUtils.joinWith(" ", arg.toArray()));
  }

  private String mapObjectMoveToStringClause(NearTextMoveParameters.ObjectMove obj) {
    Set objectsArg = new LinkedHashSet<>();
    if (StringUtils.isNotBlank(obj.getId())) {
      objectsArg.add(String.format("id: \"%s\"", obj.getId()));
    }
    if (StringUtils.isNotBlank(obj.getBeacon())) {
      objectsArg.add(String.format("beacon: \"%s\"", obj.getBeacon()));
    }
    return String.format("{%s}", StringUtils.joinWith(" ", objectsArg.toArray()));
  }

  @Override
  public String build() {
    Set arg = new LinkedHashSet<>();
    if (concepts != null && concepts.length > 0) {
      arg.add(String.format("concepts: [%s]", getConcepts(concepts)));
    }
    if (certainty != null) {
      arg.add(String.format("certainty: %s", certainty));
    }
    if (distance != null) {
      arg.add(String.format("distance: %s", distance));
    }
    if (moveTo != null) {
      arg.add(buildMoveParam("moveTo", moveTo));
    }
    if (moveAwayFrom != null) {
      arg.add(buildMoveParam("moveAwayFrom", moveAwayFrom));
    }
    if (autocorrect != null) {
      arg.add(String.format("autocorrect: %s", autocorrect));
    }
    return String.format("nearText: {%s}", StringUtils.joinWith(" ", arg.toArray()));
  }

  @java.lang.SuppressWarnings("all")
  NearTextArgument(final String[] concepts, final Float certainty, final Float distance, final NearTextMoveParameters moveTo, final NearTextMoveParameters moveAwayFrom, final Boolean autocorrect) {
    this.concepts = concepts;
    this.certainty = certainty;
    this.distance = distance;
    this.moveTo = moveTo;
    this.moveAwayFrom = moveAwayFrom;
    this.autocorrect = autocorrect;
  }


  @java.lang.SuppressWarnings("all")
  public static class NearTextArgumentBuilder {
    @java.lang.SuppressWarnings("all")
    private String[] concepts;
    @java.lang.SuppressWarnings("all")
    private Float certainty;
    @java.lang.SuppressWarnings("all")
    private Float distance;
    @java.lang.SuppressWarnings("all")
    private NearTextMoveParameters moveTo;
    @java.lang.SuppressWarnings("all")
    private NearTextMoveParameters moveAwayFrom;
    @java.lang.SuppressWarnings("all")
    private Boolean autocorrect;

    @java.lang.SuppressWarnings("all")
    NearTextArgumentBuilder() {
    }

    /**
     * @return {@code this}.
     */
    @java.lang.SuppressWarnings("all")
    public NearTextArgument.NearTextArgumentBuilder concepts(final String[] concepts) {
      this.concepts = concepts;
      return this;
    }

    /**
     * @return {@code this}.
     */
    @java.lang.SuppressWarnings("all")
    public NearTextArgument.NearTextArgumentBuilder certainty(final Float certainty) {
      this.certainty = certainty;
      return this;
    }

    /**
     * @return {@code this}.
     */
    @java.lang.SuppressWarnings("all")
    public NearTextArgument.NearTextArgumentBuilder distance(final Float distance) {
      this.distance = distance;
      return this;
    }

    /**
     * @return {@code this}.
     */
    @java.lang.SuppressWarnings("all")
    public NearTextArgument.NearTextArgumentBuilder moveTo(final NearTextMoveParameters moveTo) {
      this.moveTo = moveTo;
      return this;
    }

    /**
     * @return {@code this}.
     */
    @java.lang.SuppressWarnings("all")
    public NearTextArgument.NearTextArgumentBuilder moveAwayFrom(final NearTextMoveParameters moveAwayFrom) {
      this.moveAwayFrom = moveAwayFrom;
      return this;
    }

    /**
     * @return {@code this}.
     */
    @java.lang.SuppressWarnings("all")
    public NearTextArgument.NearTextArgumentBuilder autocorrect(final Boolean autocorrect) {
      this.autocorrect = autocorrect;
      return this;
    }

    @java.lang.SuppressWarnings("all")
    public NearTextArgument build() {
      return new NearTextArgument(this.concepts, this.certainty, this.distance, this.moveTo, this.moveAwayFrom, this.autocorrect);
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("all")
    public java.lang.String toString() {
      return "NearTextArgument.NearTextArgumentBuilder(concepts=" + java.util.Arrays.deepToString(this.concepts) + ", certainty=" + this.certainty + ", distance=" + this.distance + ", moveTo=" + this.moveTo + ", moveAwayFrom=" + this.moveAwayFrom + ", autocorrect=" + this.autocorrect + ")";
    }
  }

  @java.lang.SuppressWarnings("all")
  public static NearTextArgument.NearTextArgumentBuilder builder() {
    return new NearTextArgument.NearTextArgumentBuilder();
  }

  @java.lang.SuppressWarnings("all")
  public String[] getConcepts() {
    return this.concepts;
  }

  @java.lang.SuppressWarnings("all")
  public Float getCertainty() {
    return this.certainty;
  }

  @java.lang.SuppressWarnings("all")
  public Float getDistance() {
    return this.distance;
  }

  @java.lang.SuppressWarnings("all")
  public NearTextMoveParameters getMoveTo() {
    return this.moveTo;
  }

  @java.lang.SuppressWarnings("all")
  public NearTextMoveParameters getMoveAwayFrom() {
    return this.moveAwayFrom;
  }

  @java.lang.SuppressWarnings("all")
  public Boolean getAutocorrect() {
    return this.autocorrect;
  }

  @java.lang.Override
  @java.lang.SuppressWarnings("all")
  public java.lang.String toString() {
    return "NearTextArgument(concepts=" + java.util.Arrays.deepToString(this.getConcepts()) + ", certainty=" + this.getCertainty() + ", distance=" + this.getDistance() + ", moveTo=" + this.getMoveTo() + ", moveAwayFrom=" + this.getMoveAwayFrom() + ", autocorrect=" + this.getAutocorrect() + ")";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy