Skip to content

Commit

Permalink
Merge pull request #3049 from krichter722/checkstyle-pmml
Browse files Browse the repository at this point in the history
STORM-3433: pmml: fix all checkstyle warnings
  • Loading branch information
srdo committed Jul 1, 2019
2 parents 220338f + d5434f5 commit a4a1070
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 71 deletions.
2 changes: 1 addition & 1 deletion external/storm-pmml/pom.xml
Expand Up @@ -94,7 +94,7 @@
<!--Note - the version would be inherited-->
<configuration>

<maxAllowedViolations>67</maxAllowedViolations>
<maxAllowedViolations>0</maxAllowedViolations>
</configuration>
</plugin>
<plugin>
Expand Down
Expand Up @@ -18,6 +18,9 @@

package org.apache.storm.pmml;

import java.util.List;
import java.util.Map;

import org.apache.storm.pmml.model.ModelOutputs;
import org.apache.storm.pmml.runner.ModelRunner;
import org.apache.storm.pmml.runner.ModelRunnerFactory;
Expand All @@ -32,9 +35,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
public class PMMLPredictorBolt extends BaseTickTupleAwareRichBolt {
protected static final Logger LOG = LoggerFactory.getLogger(PMMLPredictorBolt.class);

Expand All @@ -52,7 +53,7 @@ public class PMMLPredictorBolt extends BaseTickTupleAwareRichBolt {
* Creates an instance of {@link PMMLPredictorBolt} that executes, for every tuple, the runner constructed with
* the {@link ModelRunnerFactory} specified in the parameter
* The {@link PMMLPredictorBolt} instantiated with this constructor declares the output fields as specified
* by the {@link ModelOutputs} parameter
* by the {@link ModelOutputs} parameter.
*/
public PMMLPredictorBolt(ModelRunnerFactory modelRunnerFactory, ModelOutputs modelOutputs) {
this.outputs = modelOutputs;
Expand Down Expand Up @@ -95,11 +96,11 @@ public void declareOutputFields(OutputFieldsDeclarer declarer) {

@Override
public String toString() {
return "PMMLPredictorBolt{" +
"outputFields=" + outputs +
", runnerFactory=" + runnerFactory.getClass().getName() +
", runner=" + runner +
", collector=" + collector +
"} ";
return "PMMLPredictorBolt{"
+ "outputFields=" + outputs
+ ", runnerFactory=" + runnerFactory.getClass().getName()
+ ", runner=" + runner
+ ", collector=" + collector
+ "} ";
}
}
Expand Up @@ -18,25 +18,27 @@

package org.apache.storm.pmml.model;

import org.apache.storm.pmml.PMMLPredictorBolt;
import org.apache.storm.tuple.Fields;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

import org.apache.storm.pmml.PMMLPredictorBolt;
import org.apache.storm.tuple.Fields;

/**
* Represents the streams and output fields declared by the {@link PMMLPredictorBolt}
* Represents the streams and output fields declared by the {@link PMMLPredictorBolt}.
*/
public interface ModelOutputs extends Serializable {

/**
* Stream fields.
* @return a map with the output fields declared for each stream by the {@link PMMLPredictorBolt}
*/
Map<String, ? extends Fields> streamFields();

/**
* Convenience method that returns a set with all the streams declared by the {@link PMMLPredictorBolt}.
* By default this this method calls {@link #streamFields()}{@code .keySet()}
* By default this this method calls {@link #streamFields()}{@code .keySet()}.
* @return The set with all declared streams
*/
default Set<String> streams() {
Expand Down
Expand Up @@ -18,14 +18,6 @@

package org.apache.storm.pmml.model.jpmml;

import org.apache.storm.pmml.model.ModelOutputs;
import org.apache.storm.pmml.runner.jpmml.JpmmlFactory;
import org.apache.storm.tuple.Fields;
import org.apache.storm.utils.Utils;
import org.dmg.pmml.FieldName;
import org.dmg.pmml.PMML;
import org.jpmml.evaluator.Evaluator;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
Expand All @@ -38,6 +30,14 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.storm.pmml.model.ModelOutputs;
import org.apache.storm.pmml.runner.jpmml.JpmmlFactory;
import org.apache.storm.tuple.Fields;
import org.apache.storm.utils.Utils;
import org.dmg.pmml.FieldName;
import org.dmg.pmml.PMML;
import org.jpmml.evaluator.Evaluator;

public class JpmmlModelOutputs implements ModelOutputs {
private final Map<String, ? extends Fields> declared;

Expand All @@ -60,7 +60,7 @@ public String toString() {
/**
* Factory method that creates an instance of {@link ModelOutputs} that declares
* the {@code predicted} and {@code output} fields specified in the {@link PMML} model
* specified as argument into the {@code default} stream
* specified as argument into the {@code default} stream.
*/
public static ModelOutputs toDefaultStream(PMML pmmlModel) {
Objects.requireNonNull(pmmlModel);
Expand Down Expand Up @@ -100,7 +100,7 @@ public static ModelOutputs toDefaultStream(String blobKey, Map<String, Object> c
/**
* Factory method that creates an instance of {@link ModelOutputs} that declares
* the {@code predicted} and {@code output} fields specified in the {@link PMML} model
* specified as argument into the list of streams specified
* specified as argument into the list of streams specified.
*/
public static ModelOutputs toStreams(PMML pmmlModel, List<String> streams) {
return create(pmmlModel, streams);
Expand Down
Expand Up @@ -18,13 +18,14 @@

package org.apache.storm.pmml.runner;

import org.apache.storm.pmml.model.ModelOutputs;
import org.apache.storm.tuple.Tuple;

import java.util.List;
import java.util.Map;

import org.apache.storm.pmml.model.ModelOutputs;
import org.apache.storm.tuple.Tuple;

public interface ModelRunner {

/**
* Creates and returns a map with the predicted scores that are to be emitted on each stream.
* The keys of this map are the stream ids, and the values the predicted scores.
Expand Down
Expand Up @@ -21,14 +21,15 @@
import org.apache.storm.tuple.Tuple;

/**
* Runner for models defined using PMML
* Runner for models defined using PMML.
*
* @param <I> type of the input source. For Storm it is typically a {@link Tuple}
* @param <R> the type of extracted raw input
* @param <P> the type of preprocessed input
* @param <S> the type of predicted scores
*/
public interface PmmlModelRunner<I, R, P, S> extends ModelRunner {

/**
* Extracts from the tuple the raw inputs that are to be scored according to the predictive model.
*
Expand All @@ -46,7 +47,7 @@ public interface PmmlModelRunner<I, R, P, S> extends ModelRunner {
P preProcessInputs(R rawInputs);

/**
* Compute the predicted scores from the pre-processed inputs in the step above
* Compute the predicted scores from the pre-processed inputs in the step above.
*
* @param preProcInputs that are to be preprocessed
* @return predicted scores
Expand Down
Expand Up @@ -18,6 +18,13 @@

package org.apache.storm.pmml.runner.jpmml;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.storm.pmml.model.ModelOutputs;
import org.apache.storm.pmml.runner.PmmlModelRunner;
import org.apache.storm.tuple.Tuple;
Expand All @@ -28,19 +35,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* JPMML implementation of {@link PmmlModelRunner}. It extracts the raw inputs from the tuple for all
* 'active fields', and builds a tuple with the predicted scores for the 'predicted fields' and 'output fields'.
* In this implementation all the declared streams will have the same scored tuple.
*
* The 'predicted', 'active', and 'output' fields are extracted from the PMML model.
* <p>The 'predicted', 'active', and 'output' fields are extracted from the PMML model.
*/
public class JPmmlModelRunner implements PmmlModelRunner<Tuple,
Map<FieldName, Object>,
Expand All @@ -64,6 +64,7 @@ public JPmmlModelRunner(Evaluator evaluator, ModelOutputs modelOutputs) {
}

/**
* Extract raw inputs.
* @return The raw inputs extracted from the tuple for all 'active fields'
*/
@Override
Expand Down Expand Up @@ -97,8 +98,9 @@ public Map<FieldName, FieldValue> preProcessInputs(Map<FieldName, Object> rawInp
}

/**
* Retrieve scores.
* @return the predicted scores for the 'predicted fields' and 'output fields'.
* All the declared streams will have the same scored tuple.
* All the declared streams will have the same scored tuple.
*/
@Override
public Map<String, List<Object>> scoredTuplePerStream(Tuple input) {
Expand Down

0 comments on commit a4a1070

Please sign in to comment.