krickert commented on code in PR #1003:
URL: https://github.com/apache/opennlp/pull/1003#discussion_r3059093793


##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/postag/POSTaggerME.java:
##########
@@ -131,26 +140,45 @@ public POSTaggerME(POSModel model) {
   }
 
   /**
-   * Initializes a {@link POSTaggerME} with the provided {@link POSModel 
model}.
+   * Initializes a {@link POSTaggerME} with the provided
+   * {@link POSModel model}.
    *
    * @param model  A valid {@link POSModel}.
    * @param format A valid {@link POSTagFormat}.
    */
   public POSTaggerME(POSModel model, POSTagFormat format) {
+    this(model, format, -1);
+  }
+
+  /**
+   * Initializes a {@link POSTaggerME} with the provided
+   * {@link POSModel model} and explicit cache configuration.
+   *
+   * @param model  A valid {@link POSModel}.
+   * @param format A valid {@link POSTagFormat}.
+   * @param contextCacheSize Size of the per-thread context
+   *        generator cache. Use {@code 0} to disable caching,
+   *        or {@code -1} to use the default (beam size).
+   */
+  public POSTaggerME(POSModel model, POSTagFormat format,
+      int contextCacheSize) {
     this.posTagFormat = format;
     POSTaggerFactory factory = model.getFactory();
 
     int beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;
 
-    String beamSizeString = 
model.getManifestProperty(BeamSearch.BEAM_SIZE_PARAMETER);
+    String beamSizeString = model.getManifestProperty(
+        BeamSearch.BEAM_SIZE_PARAMETER);
 
     if (beamSizeString != null) {
       beamSize = Integer.parseInt(beamSizeString);
     }
 
     modelPackage = model;
 
-    cg = factory.getPOSContextGenerator(beamSize);
+    int cacheSize = contextCacheSize >= 0

Review Comment:
   You’re right to call this out — the Javadoc promises more precision than the 
constructor used to enforce.
   
   Where we are now: `0` flows through to `getPOSContextGenerator(0)` (no 
context cache), and `-1` is normalized to `beamSize` before we build the 
generator. Anything **below** `-1` today follows that same “default” branch, 
which is misleading if we claim only `-1` is special.
   
   I’ll fix that by rejecting `contextCacheSize < -1` with 
`IllegalArgumentException` (unless you’d rather document the alias — I’d rather 
fail fast). I can push that as a small follow-up commit on this branch unless 
you want it held for after merge.



##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/postag/POSTaggerME.java:
##########
@@ -159,13 +187,14 @@ public POSTaggerME(POSModel model, POSTagFormat format) {
     if (model.getPosSequenceModel() != null) {
       this.model = model.getPosSequenceModel();
     } else {
-      this.model = new BeamSearch(beamSize, 
model.getArtifact(POSModel.POS_MODEL_ENTRY_NAME), 0);
+      this.model = new BeamSearch(beamSize,

Review Comment:
   That wrap crept in while touching the constructor — nothing semantic 
changed. If you want those two statements back on one line (still under 110 
cols) I can push a whitespace-only fix.



##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/postag/POSTaggerME.java:
##########
@@ -159,13 +187,14 @@ public POSTaggerME(POSModel model, POSTagFormat format) {
     if (model.getPosSequenceModel() != null) {
       this.model = model.getPosSequenceModel();
     } else {
-      this.model = new BeamSearch(beamSize, 
model.getArtifact(POSModel.POS_MODEL_ENTRY_NAME), 0);
+      this.model = new BeamSearch(beamSize,
+              model.getArtifact(POSModel.POS_MODEL_ENTRY_NAME), 0);
     }
 
-    this.posTagFormatMapper = (format == POSTagFormat.CUSTOM)
+    this.posTagFormatMapper =
+        (format == POSTagFormat.CUSTOM)

Review Comment:
   Same here — formatter/IDE split the ternary when the block moved. Happy to 
collapse it if it’s just noise in the diff.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to