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

com.blackbirdai.client.model.Correction Maven / Gradle / Ivy

The newest version!
package com.blackbirdai.client.model;

import com.fasterxml.jackson.databind.JsonNode;

import javax.annotation.Nullable;

/**
 * Container for spelling correction result.
 */
public class Correction {
    private final String cq;
    private final Type type;

    public Correction(String cq, Type type) {
        this.cq = cq;
        this.type = type;
    }

    /**
     * Returns spelling corrected query.
     */
    public String getCq() {
        return cq;
    }

    /**
     * Returns level of confidence for this spelling correction.
     */
    public Type getType() {
        return type;
    }

    @Nullable
    static Correction parseJson(JsonNode json) {
        if (json.get("cq") == null || json.get("type") == null) {
            return null;
        } else {
            try {
                Type cqType = Type.valueOf(json.get("type").asText().toUpperCase());
                return new Correction(json.get("cq").asText(), cqType);
            } catch (Exception e) {
                return null;
            }
        }
    }

    public enum Type {
        STRONG,
        WEAK
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy