Skip to content

Commit

Permalink
feat: display post-processed value in analyzed results (#229)
Browse files Browse the repository at this point in the history
* feat: display post-processed value in analyzed results
  • Loading branch information
stew-ro authored Apr 30, 2020
1 parent 0302357 commit f3e42f6
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/react/components/pages/predict/predictResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class PredictResult extends React.Component<IPredictResultProps,
}

private renderItem = (item: any, key: any) => {
const postProcessedValue = this.getPostProcessedValue(item);
const style: any = {
marginLeft: "0px",
marginRight: "0px",
Expand All @@ -77,9 +78,14 @@ export default class PredictResult extends React.Component<IPredictResultProps,
{this.getPredictionTagContent(item)}
</div>
</li>
<li className="predictiontag-item-label">
{item.text}
<li className={postProcessedValue ? "predictiontag-item-label mt-0" : "predictiontag-item-label mt-0 mb-1"}>
{postProcessedValue ? "text: " + item.text : item.text}
</li>
{postProcessedValue &&
<li className="predictiontag-item-label mb-1">
{postProcessedValue}
</li>
}
</div>
);
}
Expand Down Expand Up @@ -162,4 +168,43 @@ export default class PredictResult extends React.Component<IPredictResultProps,
this.props.onPredictionMouseLeave(prediction);
}
}

private getPostProcessedValue = (prediction: any) => {
if (!prediction.type || !prediction.text) {
return null;
}
const predictionType = prediction.type;
const predictionText = prediction.text;
let postProcessedValue;
let valueType;
switch (predictionType) {
case "string":
valueType = "valueString";
postProcessedValue = prediction.valueString;
break;
case "date":
valueType = "valueDate";
postProcessedValue = prediction.valueDate;
break;
case "number":
valueType = "valueNumber";
postProcessedValue = prediction.valueNumber.toString();
break;
case "integer":
valueType = "valueInteger";
postProcessedValue = prediction.valueInteger.toString();
break;
case "time":
valueType = "valueTime";
postProcessedValue = prediction.valueTime;
break;
default:
return null;
}
if (predictionText !== postProcessedValue) {
return valueType + ": " + postProcessedValue;
} else {
return null;
}
}
}

0 comments on commit f3e42f6

Please sign in to comment.