org.dmg.pmml.rule_set.SimpleRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pmml-model-gwt Show documentation
Show all versions of pmml-model-gwt Show documentation
JPMML GWT compatible class model
package org.dmg.pmml.rule_set;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElements;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlSchemaType;
import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.dmg.pmml.Extension;
import org.dmg.pmml.HasExtensions;
import org.dmg.pmml.HasRecordCount;
import org.dmg.pmml.HasScoreDistributions;
import org.dmg.pmml.PMMLObject;
import org.dmg.pmml.Predicate;
import org.dmg.pmml.ScoreDistribution;
import org.dmg.pmml.Visitor;
import org.dmg.pmml.VisitorAction;
import org.dmg.pmml.adapters.NumberAdapter;
import org.dmg.pmml.adapters.ObjectAdapter;
import org.jpmml.model.MissingAttributeException;
import org.jpmml.model.MissingElementException;
import org.jpmml.model.annotations.ValueConstructor;
@XmlRootElement(name = "SimpleRule", namespace = "http://www.dmg.org/PMML-4_4")
@XmlType(name = "", propOrder = {
"extensions",
"predicate",
"scoreDistributions"
})
@JsonRootName("SimpleRule")
@JsonPropertyOrder({
"id",
"score",
"recordCount",
"nbCorrect",
"confidence",
"weight",
"extensions",
"predicate",
"scoreDistributions"
})
public class SimpleRule
extends Rule
implements HasExtensions , HasRecordCount , HasScoreDistributions
{
@XmlAttribute(name = "id")
@JsonProperty("id")
private String id;
@XmlAttribute(name = "score", required = true)
@XmlJavaTypeAdapter(ObjectAdapter.class)
@XmlSchemaType(name = "anySimpleType")
@JsonProperty("score")
private Object score;
@XmlAttribute(name = "recordCount")
@XmlJavaTypeAdapter(NumberAdapter.class)
@JsonProperty("recordCount")
private Number recordCount;
@XmlAttribute(name = "nbCorrect")
@XmlJavaTypeAdapter(NumberAdapter.class)
@JsonProperty("nbCorrect")
private Number nbCorrect;
@XmlAttribute(name = "confidence")
@XmlJavaTypeAdapter(NumberAdapter.class)
@JsonProperty("confidence")
private Number confidence;
@XmlAttribute(name = "weight")
@XmlJavaTypeAdapter(NumberAdapter.class)
@JsonProperty("weight")
private Number weight;
@XmlElement(name = "Extension", namespace = "http://www.dmg.org/PMML-4_4")
@JsonProperty("Extension")
private List extensions;
@XmlElements({
@XmlElement(name = "SimplePredicate", namespace = "http://www.dmg.org/PMML-4_4", type = org.dmg.pmml.SimplePredicate.class),
@XmlElement(name = "CompoundPredicate", namespace = "http://www.dmg.org/PMML-4_4", type = org.dmg.pmml.CompoundPredicate.class),
@XmlElement(name = "SimpleSetPredicate", namespace = "http://www.dmg.org/PMML-4_4", type = org.dmg.pmml.SimpleSetPredicate.class),
@XmlElement(name = "True", namespace = "http://www.dmg.org/PMML-4_4", type = org.dmg.pmml.True.class),
@XmlElement(name = "False", namespace = "http://www.dmg.org/PMML-4_4", type = org.dmg.pmml.False.class)
})
@JsonProperty("Predicate")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
@JsonSubTypes({
@JsonSubTypes.Type(name = "SimplePredicate", value = org.dmg.pmml.SimplePredicate.class),
@JsonSubTypes.Type(name = "CompoundPredicate", value = org.dmg.pmml.CompoundPredicate.class),
@JsonSubTypes.Type(name = "SimpleSetPredicate", value = org.dmg.pmml.SimpleSetPredicate.class),
@JsonSubTypes.Type(name = "True", value = org.dmg.pmml.True.class),
@JsonSubTypes.Type(name = "False", value = org.dmg.pmml.False.class)
})
private Predicate predicate;
@XmlElements({
@XmlElement(name = "ScoreDistribution", namespace = "http://www.dmg.org/PMML-4_4", type = org.dmg.pmml.ComplexScoreDistribution.class)
})
@JsonProperty("ScoreDistribution")
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE, defaultImpl = org.dmg.pmml.ComplexScoreDistribution.class)
@JsonDeserialize(contentAs = org.dmg.pmml.ComplexScoreDistribution.class)
private List scoreDistributions;
private final static Number DEFAULT_CONFIDENCE = new NumberAdapter().unmarshal("1");
private final static Number DEFAULT_WEIGHT = new NumberAdapter().unmarshal("1");
private final static long serialVersionUID = 67371270L;
public SimpleRule() {
}
@ValueConstructor
public SimpleRule(
@org.jpmml.model.annotations.Property("score")
Object score,
@org.jpmml.model.annotations.Property("predicate")
Predicate predicate) {
this.score = score;
this.predicate = predicate;
}
@Override
public String getId() {
return id;
}
@Override
public SimpleRule setId(
@org.jpmml.model.annotations.Property("id")
String id) {
this.id = id;
return this;
}
@Override
public Object requireScore() {
if (this.score == null) {
throw new MissingAttributeException(this, PMMLAttributes.SIMPLERULE_SCORE);
}
return this.score;
}
@Override
public Object getScore() {
return score;
}
@Override
public SimpleRule setScore(
@org.jpmml.model.annotations.Property("score")
Object score) {
this.score = score;
return this;
}
@Override
public Number getRecordCount() {
return recordCount;
}
@Override
public SimpleRule setRecordCount(
@org.jpmml.model.annotations.Property("recordCount")
Number recordCount) {
this.recordCount = recordCount;
return this;
}
public Number getNbCorrect() {
return nbCorrect;
}
public SimpleRule setNbCorrect(
@org.jpmml.model.annotations.Property("nbCorrect")
Number nbCorrect) {
this.nbCorrect = nbCorrect;
return this;
}
public Number getConfidence() {
if (confidence == null) {
return DEFAULT_CONFIDENCE;
} else {
return confidence;
}
}
public SimpleRule setConfidence(
@org.jpmml.model.annotations.Property("confidence")
Number confidence) {
this.confidence = confidence;
return this;
}
public Number getWeight() {
if (weight == null) {
return DEFAULT_WEIGHT;
} else {
return weight;
}
}
public SimpleRule setWeight(
@org.jpmml.model.annotations.Property("weight")
Number weight) {
this.weight = weight;
return this;
}
@Override
public boolean hasExtensions() {
return ((this.extensions!= null)&&(!this.extensions.isEmpty()));
}
@Override
public List getExtensions() {
if (extensions == null) {
extensions = new ArrayList();
}
return this.extensions;
}
@Override
public SimpleRule addExtensions(Extension... extensions) {
getExtensions().addAll(Arrays.asList(extensions));
return this;
}
@Override
public Predicate requirePredicate() {
if (this.predicate == null) {
throw new MissingElementException(this, PMMLElements.SIMPLERULE_PREDICATE);
}
return this.predicate;
}
@Override
public Predicate getPredicate() {
return predicate;
}
@Override
public SimpleRule setPredicate(
@org.jpmml.model.annotations.Property("predicate")
Predicate predicate) {
this.predicate = predicate;
return this;
}
@Override
public boolean hasScoreDistributions() {
return ((this.scoreDistributions!= null)&&(!this.scoreDistributions.isEmpty()));
}
@Override
public List getScoreDistributions() {
if (scoreDistributions == null) {
scoreDistributions = new ArrayList();
}
return this.scoreDistributions;
}
@Override
public SimpleRule addScoreDistributions(ScoreDistribution... scoreDistributions) {
getScoreDistributions().addAll(Arrays.asList(scoreDistributions));
return this;
}
@Override
public VisitorAction accept(Visitor visitor) {
VisitorAction status = visitor.visit(this);
if (status == VisitorAction.CONTINUE) {
visitor.pushParent(this);
if ((status == VisitorAction.CONTINUE)&&hasExtensions()) {
status = PMMLObject.traverse(visitor, getExtensions());
}
if (status == VisitorAction.CONTINUE) {
status = PMMLObject.traverse(visitor, getPredicate());
}
if ((status == VisitorAction.CONTINUE)&&hasScoreDistributions()) {
status = PMMLObject.traverse(visitor, getScoreDistributions());
}
visitor.popParent();
}
if (status == VisitorAction.TERMINATE) {
return VisitorAction.TERMINATE;
}
return VisitorAction.CONTINUE;
}
}