Search in sources :

Example 1 with CurrencyFeatureDomain

use of org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain in project kogito-apps by kiegroup.

the class CounterfactualEntityFactory method from.

public static CounterfactualEntity from(Feature feature, FeatureDistribution featureDistribution) {
    CounterfactualEntity entity = null;
    validateFeature(feature);
    final Type type = feature.getType();
    final FeatureDomain featureDomain = feature.getDomain();
    final boolean isConstrained = feature.isConstrained();
    final Object valueObject = feature.getValue().getUnderlyingObject();
    if (type == Type.NUMBER) {
        if (valueObject instanceof Double) {
            if (isConstrained) {
                entity = FixedDoubleEntity.from(feature);
            } else {
                entity = DoubleEntity.from(feature, featureDomain.getLowerBound(), featureDomain.getUpperBound(), featureDistribution, isConstrained);
            }
        } else if (valueObject instanceof Long) {
            if (isConstrained) {
                entity = FixedLongEntity.from(feature);
            } else {
                entity = LongEntity.from(feature, featureDomain.getLowerBound().intValue(), featureDomain.getUpperBound().intValue(), featureDistribution, isConstrained);
            }
        } else if (valueObject instanceof Integer) {
            if (isConstrained) {
                entity = FixedIntegerEntity.from(feature);
            } else {
                entity = IntegerEntity.from(feature, featureDomain.getLowerBound().intValue(), featureDomain.getUpperBound().intValue(), featureDistribution, isConstrained);
            }
        }
    } else if (feature.getType() == Type.BOOLEAN) {
        if (isConstrained) {
            entity = FixedBooleanEntity.from(feature);
        } else {
            entity = BooleanEntity.from(feature, isConstrained);
        }
    } else if (feature.getType() == Type.TEXT) {
        if (isConstrained) {
            entity = FixedTextEntity.from(feature);
        } else {
            throw new IllegalArgumentException("Unsupported feature type: " + feature.getType());
        }
    } else if (feature.getType() == Type.BINARY) {
        if (isConstrained) {
            entity = FixedBinaryEntity.from(feature);
        } else {
            entity = BinaryEntity.from(feature, ((BinaryFeatureDomain) featureDomain).getCategories(), isConstrained);
        }
    } else if (feature.getType() == Type.URI) {
        if (isConstrained) {
            entity = FixedURIEntity.from(feature);
        } else {
            entity = URIEntity.from(feature, ((URIFeatureDomain) featureDomain).getCategories(), isConstrained);
        }
    } else if (feature.getType() == Type.TIME) {
        if (isConstrained) {
            entity = FixedTimeEntity.from(feature);
        } else {
            final LocalTime lowerBound = LocalTime.MIN.plusSeconds(featureDomain.getLowerBound().longValue());
            final LocalTime upperBound = LocalTime.MIN.plusSeconds(featureDomain.getUpperBound().longValue());
            entity = TimeEntity.from(feature, lowerBound, upperBound, isConstrained);
        }
    } else if (feature.getType() == Type.DURATION) {
        if (isConstrained) {
            entity = FixedDurationEntity.from(feature);
        } else {
            DurationFeatureDomain domain = (DurationFeatureDomain) featureDomain;
            entity = DurationEntity.from(feature, Duration.of(domain.getLowerBound().longValue(), domain.getUnit()), Duration.of(domain.getUpperBound().longValue(), domain.getUnit()), featureDistribution, isConstrained);
        }
    } else if (feature.getType() == Type.VECTOR) {
        if (isConstrained) {
            entity = FixedVectorEntity.from(feature);
        } else {
            throw new IllegalArgumentException("Unsupported feature type: " + feature.getType());
        }
    } else if (feature.getType() == Type.COMPOSITE) {
        if (isConstrained) {
            entity = FixedCompositeEntity.from(feature);
        } else {
            throw new IllegalArgumentException("Unsupported feature type: " + feature.getType());
        }
    } else if (feature.getType() == Type.CURRENCY) {
        if (isConstrained) {
            entity = FixedCurrencyEntity.from(feature);
        } else {
            entity = CurrencyEntity.from(feature, ((CurrencyFeatureDomain) featureDomain).getCategories(), isConstrained);
        }
    } else if (feature.getType() == Type.CATEGORICAL) {
        if (isConstrained) {
            entity = FixedCategoricalEntity.from(feature);
        } else {
            entity = CategoricalEntity.from(feature, ((CategoricalFeatureDomain) featureDomain).getCategories(), isConstrained);
        }
    } else if (feature.getType() == Type.UNDEFINED) {
        if (isConstrained) {
            entity = FixedObjectEntity.from(feature);
        } else {
            entity = ObjectEntity.from(feature, ((ObjectFeatureDomain) featureDomain).getCategories(), isConstrained);
        }
    } else {
        throw new IllegalArgumentException("Unsupported feature type: " + feature.getType());
    }
    return entity;
}
Also used : LocalTime(java.time.LocalTime) URIFeatureDomain(org.kie.kogito.explainability.model.domain.URIFeatureDomain) DurationFeatureDomain(org.kie.kogito.explainability.model.domain.DurationFeatureDomain) ObjectFeatureDomain(org.kie.kogito.explainability.model.domain.ObjectFeatureDomain) URIFeatureDomain(org.kie.kogito.explainability.model.domain.URIFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) DurationFeatureDomain(org.kie.kogito.explainability.model.domain.DurationFeatureDomain) BinaryFeatureDomain(org.kie.kogito.explainability.model.domain.BinaryFeatureDomain) CurrencyFeatureDomain(org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) Type(org.kie.kogito.explainability.model.Type)

Aggregations

LocalTime (java.time.LocalTime)1 Type (org.kie.kogito.explainability.model.Type)1 BinaryFeatureDomain (org.kie.kogito.explainability.model.domain.BinaryFeatureDomain)1 CategoricalFeatureDomain (org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain)1 CurrencyFeatureDomain (org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain)1 DurationFeatureDomain (org.kie.kogito.explainability.model.domain.DurationFeatureDomain)1 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)1 ObjectFeatureDomain (org.kie.kogito.explainability.model.domain.ObjectFeatureDomain)1 URIFeatureDomain (org.kie.kogito.explainability.model.domain.URIFeatureDomain)1