Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RETIRED: Hibernate Migration (replaced by 543) #532

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tests/artifacts/*
*.log
release.properties
*.releaseBackup
**/*.db
pom.xml.tag
pom.xml.next
release-pom.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.kie.trustyai.connectors.kserve.v2.grpc.InferTensorContents;
import org.kie.trustyai.connectors.kserve.v2.grpc.ModelInferRequest;
import org.kie.trustyai.connectors.kserve.v2.grpc.ModelInferResponse;
import org.kie.trustyai.explainability.model.dataframe.Dataframe;

import com.google.protobuf.ByteString;

Expand Down
24 changes: 24 additions & 0 deletions explainability-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,32 @@
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
<version>3.2.11.Final</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be managed via the import of quarkus bom instead of explicit version (this version is tied to quarkus version)

</dependency>
Comment on lines +87 to +91
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to keep explainability-core thin so I prefer to have a explainability-persistance module to compose this use case if possible.

</dependencies>

<build>
<plugins>
<!-- The entity classes need to be indexed -->
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>default</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static CounterfactualEntity from(Feature feature, FeatureDistribution fea
} else if (featureDomain instanceof CurrencyFeatureDomain) {
entity = CurrencyEntity.from(feature, ((CurrencyFeatureDomain) featureDomain).getCategories());
} else if (featureDomain instanceof ObjectFeatureDomain) {
entity = ObjectEntity.from(feature, ((ObjectFeatureDomain) featureDomain).getCategories());
entity = ObjectEntity.from(feature, ((ObjectFeatureDomain) featureDomain).getRawCategories());
} else if (featureDomain instanceof URIFeatureDomain) {
entity = URIEntity.from(feature, ((URIFeatureDomain) featureDomain).getCategories());
} else if (featureDomain instanceof CategoricalNumericalFeatureDomain) {
Expand All @@ -149,7 +149,7 @@ public static CounterfactualEntity from(Feature feature, FeatureDistribution fea
if (isConstrained) {
entity = ObjectEntity.from(feature, null, true);
} else {
entity = ObjectEntity.from(feature, ((ObjectFeatureDomain) featureDomain).getCategories(), isConstrained);
entity = ObjectEntity.from(feature, ((ObjectFeatureDomain) featureDomain).getRawCategories(), isConstrained);
}
} else {
throw new IllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE + feature.getType());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.kie.trustyai.explainability.model;

import java.io.Serializable;
import java.util.Objects;

public class UnderlyingObject implements Serializable {
private Object object;

public UnderlyingObject() {

}

public UnderlyingObject(Object o) {
object = o;
}

public Object getObject() {
return this.object;
}

public void setObject(Object o) {
this.object = o;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
UnderlyingObject that = (UnderlyingObject) o;
return Objects.equals(object, that.object);
}

@Override
public int hashCode() {
return Objects.hash(object);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,54 @@
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;

import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Transient;

/**
* Wrapper class for any kind of value part of a prediction input or output.
*
*/
@Embeddable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only need similar annotation in core you can add jakarta-persistance-api dependency

public class Value {

private final Object underlyingObject;
private final UnderlyingObject wrappedUnderlyingObject;

public Value(Object underlyingObject) {
this.underlyingObject = underlyingObject;
this.wrappedUnderlyingObject = new UnderlyingObject(underlyingObject);
}

public Value() {
this.wrappedUnderlyingObject = new UnderlyingObject(null);
}

public String asString() {
if (underlyingObject instanceof List) {
if (getUnderlyingObject() instanceof List) {
try {
@SuppressWarnings("unchecked")
List<Feature> composite = (List<Feature>) underlyingObject;
List<Feature> composite = (List<Feature>) getUnderlyingObject();
return composite.stream().map(f -> f.getValue().asString()).collect(Collectors.joining(" "));
} catch (ClassCastException ignored) {
// ignored
}
}
if (underlyingObject instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) this.underlyingObject;
if (getUnderlyingObject() instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) getUnderlyingObject();
return new String(byteBuffer.array());
}
return ArrayUtils.toString(underlyingObject);
return ArrayUtils.toString(getUnderlyingObject());
}

public double asNumber() {
if (underlyingObject != null) {
if (getUnderlyingObject() != null) {
try {
if (underlyingObject instanceof Double) {
return (double) underlyingObject;
} else if (underlyingObject instanceof Number) {
return ((Number) underlyingObject).doubleValue();
} else if (underlyingObject instanceof Boolean) {
return (boolean) underlyingObject ? 1d : 0d;
if (getUnderlyingObject() instanceof Double) {
return (double) getUnderlyingObject();
} else if (getUnderlyingObject() instanceof Number) {
return ((Number) getUnderlyingObject()).doubleValue();
} else if (getUnderlyingObject() instanceof Boolean) {
return (boolean) getUnderlyingObject() ? 1d : 0d;
} else {
return Double.parseDouble(asString());
}
Expand All @@ -77,25 +87,31 @@ public double asNumber() {
}
}

@Transient
public Object getUnderlyingObject() {
return underlyingObject;
return wrappedUnderlyingObject.getObject();
}

@Access(AccessType.FIELD)
public UnderlyingObject getUnderlyingObjectContainer() {
return wrappedUnderlyingObject;
}

@Override
public String toString() {
return Objects.toString(underlyingObject);
return Objects.toString(getUnderlyingObject());
}

public double[] asVector() {
double[] doubles;
if (underlyingObject instanceof double[]) {
doubles = (double[]) underlyingObject;
if (getUnderlyingObject() instanceof double[]) {
doubles = (double[]) getUnderlyingObject();
} else {
if (underlyingObject instanceof String) {
String string = (String) this.underlyingObject;
if (getUnderlyingObject() instanceof String) {
String string = (String) getUnderlyingObject();
doubles = parseVectorString(string);
} else if (underlyingObject instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) underlyingObject;
} else if (getUnderlyingObject() instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) getUnderlyingObject();
String string = StandardCharsets.UTF_8.decode(byteBuffer).toString();
doubles = parseVectorString(string);
} else {
Expand Down Expand Up @@ -138,11 +154,11 @@ public boolean equals(Object o) {
return false;
}
Value value = (Value) o;
return Objects.equals(underlyingObject, value.underlyingObject);
return Objects.equals(getUnderlyingObject(), value.getUnderlyingObject());
}

@Override
public int hashCode() {
return Objects.hash(underlyingObject);
return Objects.hash(getUnderlyingObject());
}
}
Loading
Loading