mawiesne commented on code in PR #1003:
URL: https://github.com/apache/opennlp/pull/1003#discussion_r3060063984
##########
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:
Fail fast for < -1 is fine for me, please adjust via additional commit in
this PR.
--
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]