Search in sources :

Example 1 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.

the class ConversionUtilsTest method toOutputTypedValue.

@Test
void toOutputTypedValue() {
    Output name = ConversionUtils.toOutput("name", new UnitValue("number", new DoubleNode(10d)));
    assertNotNull(name);
    assertEquals("name", name.getName());
    assertEquals(Type.NUMBER, name.getType());
    assertEquals(10d, name.getValue().getUnderlyingObject());
    Output name1 = ConversionUtils.toOutput("name1", new StructureValue("complex", singletonMap("key", new UnitValue("string1", new TextNode("stringValue")))));
    assertNotNull(name1);
    assertEquals("name1", name1.getName());
    assertEquals(Type.COMPOSITE, name1.getType());
    assertTrue(name1.getValue().getUnderlyingObject() instanceof List);
    @SuppressWarnings("unchecked") List<Output> outputs = (List<Output>) name1.getValue().getUnderlyingObject();
    assertEquals(1, outputs.size());
    assertEquals(Type.TEXT, outputs.get(0).getType());
    assertEquals("stringValue", outputs.get(0).getValue().getUnderlyingObject());
    List<TypedValue> values = List.of(new UnitValue("number", new DoubleNode(0d)), new UnitValue("number", new DoubleNode(1d)));
    assertNotNull(ConversionUtils.toOutput("name", new CollectionValue("list", values)));
}
Also used : CollectionValue(org.kie.kogito.tracing.typedvalue.CollectionValue) Output(org.kie.kogito.explainability.model.Output) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) StructureValue(org.kie.kogito.tracing.typedvalue.StructureValue) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) Test(org.junit.jupiter.api.Test)

Example 2 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.

the class ConversionUtils method toFeatureList.

// //////////////////////////
// TO EXPLAINABILITY MODEL
// //////////////////////////
/*
     * ---------------------------------------
     * Feature conversion
     * ---------------------------------------
     */
public static List<Feature> toFeatureList(Collection<? extends HasNameValue<TypedValue>> values, Collection<CounterfactualSearchDomain> searchDomains) {
    if (searchDomains.isEmpty()) {
        return toFeatureList(values);
    } else {
        AtomicInteger index = new AtomicInteger();
        final List<FeatureDomain> featureDomains = toFeatureDomainList(searchDomains);
        final List<Boolean> featureConstraints = toFeatureConstraintList(searchDomains);
        return values.stream().map(hnv -> {
            final String name = hnv.getName();
            final TypedValue value = hnv.getValue();
            final int i = index.getAndIncrement();
            return toFeature(name, value, featureDomains.get(i), featureConstraints.get(i));
        }).collect(Collectors.toList());
    }
}
Also used : FeatureFactory(org.kie.kogito.explainability.model.FeatureFactory) Feature(org.kie.kogito.explainability.model.Feature) BiFunction(java.util.function.BiFunction) CounterfactualSearchDomainValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainValue) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) Value(org.kie.kogito.explainability.model.Value) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) HasNameValue(org.kie.kogito.explainability.api.HasNameValue) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonObject(io.vertx.core.json.JsonObject) CounterfactualDomainCategorical(org.kie.kogito.explainability.api.CounterfactualDomainCategorical) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Type(org.kie.kogito.explainability.model.Type) TextNode(com.fasterxml.jackson.databind.node.TextNode) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) Objects(java.util.Objects) List(java.util.List) CounterfactualDomain(org.kie.kogito.explainability.api.CounterfactualDomain) CollectionValue(org.kie.kogito.tracing.typedvalue.CollectionValue) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) Output(org.kie.kogito.explainability.model.Output) Optional(java.util.Optional) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Collections(java.util.Collections) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue)

Example 3 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.

the class ConversionUtils method toTypedValue.

static TypedValue toTypedValue(Output output) {
    String name = output.getName();
    Type type = output.getType();
    Value value = output.getValue();
    return toTypedValue(name, type, value);
}
Also used : Type(org.kie.kogito.explainability.model.Type) CounterfactualSearchDomainValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainValue) Value(org.kie.kogito.explainability.model.Value) HasNameValue(org.kie.kogito.explainability.api.HasNameValue) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) CollectionValue(org.kie.kogito.tracing.typedvalue.CollectionValue)

Example 4 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.

the class ConversionUtils method toOutputListForCollection.

static List<Output> toOutputListForCollection(String name, CollectionValue collectionValue) {
    Collection<TypedValue> values = collectionValue.getValue();
    List<Output> list = new ArrayList<>(values.size());
    int index = 0;
    for (TypedValue typedValue : values) {
        list.add(toOutput(name + "_" + index, typedValue));
        index++;
    }
    return list;
}
Also used : Output(org.kie.kogito.explainability.model.Output) ArrayList(java.util.ArrayList) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue)

Example 5 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-runtimes by kiegroup.

the class EventUtilsTest method testTypedVariableFromJsonNodeWithDMNType.

@Test
void testTypedVariableFromJsonNodeWithDMNType() throws JsonProcessingException {
    ObjectReader reader = new ObjectMapper().reader();
    TypedValue value = EventUtils.typedValueFromJsonNode(mockDMNType("Any"), null, null);
    assertNotNull(value);
    assertSame(TypedValue.Kind.UNIT, value.getKind());
    assertEquals(BuiltInType.UNKNOWN.getName(), value.getType());
    value = EventUtils.typedValueFromJsonNode(mockDMNType("boolean"), reader.readTree("true"), null);
    assertNotNull(value);
    assertSame(TypedValue.Kind.UNIT, value.getKind());
    assertEquals(BuiltInType.BOOLEAN.getName(), value.getType());
    value = EventUtils.typedValueFromJsonNode(mockDMNType("number"), reader.readTree("12"), null);
    assertNotNull(value);
    assertSame(TypedValue.Kind.UNIT, value.getKind());
    assertEquals(BuiltInType.NUMBER.getName(), value.getType());
    value = EventUtils.typedValueFromJsonNode(mockDMNType("string"), reader.readTree("\"test\""), null);
    assertNotNull(value);
    assertSame(TypedValue.Kind.UNIT, value.getKind());
    assertEquals(BuiltInType.STRING.getName(), value.getType());
    value = EventUtils.typedValueFromJsonNode(mockDMNType("number"), reader.readTree("[1,2,3]"), null);
    assertNotNull(value);
    assertSame(TypedValue.Kind.COLLECTION, value.getKind());
    assertEquals(BuiltInType.NUMBER.getName(), value.getType());
    value = EventUtils.typedValueFromJsonNode(mockDMNType("Person"), reader.readTree("{\"name\": \"John\", \"age\": 45, \"married\": true}"), null);
    assertNotNull(value);
    assertSame(TypedValue.Kind.STRUCTURE, value.getKind());
    assertEquals("Person", value.getType());
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) Test(org.junit.jupiter.api.Test)

Aggregations

TypedValue (org.kie.kogito.tracing.typedvalue.TypedValue)15 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)9 ArrayList (java.util.ArrayList)8 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)8 List (java.util.List)7 Test (org.junit.jupiter.api.Test)6 CollectionValue (org.kie.kogito.tracing.typedvalue.CollectionValue)6 TextNode (com.fasterxml.jackson.databind.node.TextNode)4 Map (java.util.Map)4 CounterfactualSearchDomainValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainValue)4 HasNameValue (org.kie.kogito.explainability.api.HasNameValue)4 Feature (org.kie.kogito.explainability.model.Feature)4 Type (org.kie.kogito.explainability.model.Type)4 Value (org.kie.kogito.explainability.model.Value)4 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)3 Collection (java.util.Collection)3 Collections.emptyList (java.util.Collections.emptyList)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Output (org.kie.kogito.explainability.model.Output)3