This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git
The following commit(s) were added to refs/heads/main by this push:
new a3a5e0fb OPENNLP-1668: Avoid multiple DecimalFormat instances in
AbstractModel (#710)
a3a5e0fb is described below
commit a3a5e0fb991dc84fa6f57f28f8f9abf1820d02ae
Author: Martin Wiesner <[email protected]>
AuthorDate: Fri Dec 13 19:38:08 2024 +0100
OPENNLP-1668: Avoid multiple DecimalFormat instances in AbstractModel (#710)
---
.../src/main/java/opennlp/tools/ml/model/AbstractModel.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git
a/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java
b/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java
index 9d434e51..b3f26c46 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java
@@ -30,6 +30,8 @@ import opennlp.tools.ml.ArrayMath;
*/
public abstract class AbstractModel implements MaxentModel {
+ private static final DecimalFormat DECIMAL_FORMAT = new
DecimalFormat("0.0000");
+
/** Mapping between predicates/contexts and an integer representing them. */
protected Map<String, Context> pmap;
/** The names of the outcomes. */
@@ -119,11 +121,10 @@ public abstract class AbstractModel implements
MaxentModel {
"must not have been produced by this model.";
}
else {
- DecimalFormat df = new DecimalFormat("0.0000");
StringBuilder sb = new StringBuilder(ocs.length * 2);
-
sb.append(outcomeNames[0]).append("[").append(df.format(ocs[0])).append("]");
+
sb.append(outcomeNames[0]).append("[").append(DECIMAL_FORMAT.format(ocs[0])).append("]");
for (int i = 1; i < ocs.length; i++) {
- sb.append("
").append(outcomeNames[i]).append("[").append(df.format(ocs[i])).append("]");
+ sb.append("
").append(outcomeNames[i]).append("[").append(DECIMAL_FORMAT.format(ocs[i])).append("]");
}
return sb.toString();
}