Search in sources :

Example 1 with FixedCompositeEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCompositeEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testCompositeFactory.

@Test
void testCompositeFactory() {
    Map<String, Object> map = new HashMap<>();
    List<Feature> features = new LinkedList<>();
    features.add(FeatureFactory.newObjectFeature("f1", new Object()));
    features.add(FeatureFactory.newTextFeature("f2", "hola"));
    features.add(FeatureFactory.newFulltextFeature("f3", "foo bar"));
    features.add(FeatureFactory.newNumericalFeature("f4", 131));
    features.add(FeatureFactory.newBooleanFeature("f5", false));
    features.add(FeatureFactory.newDurationFeature("f6", Duration.ofDays(2)));
    Map<String, Object> nestedMap = new HashMap<>();
    nestedMap.put("nf-1", "nested text");
    nestedMap.put("nf-2", ByteBuffer.allocate(1024));
    features.add(FeatureFactory.newCompositeFeature("f7", nestedMap));
    for (Feature f : features) {
        map.put(f.getName(), f.getValue().getUnderlyingObject());
    }
    final Feature feature = FeatureFactory.newCompositeFeature("composite-feature", map);
    CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedCompositeEntity);
    assertEquals(Type.COMPOSITE, counterfactualEntity.asFeature().getType());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) FixedCompositeEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCompositeEntity) HashMap(java.util.HashMap) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Test (org.junit.jupiter.api.Test)1 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)1 FixedCompositeEntity (org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCompositeEntity)1 Feature (org.kie.kogito.explainability.model.Feature)1