mawiesne commented on code in PR #459:
URL: https://github.com/apache/opennlp/pull/459#discussion_r1054097099
##########
opennlp-tools/src/main/java/opennlp/tools/util/DownloadUtil.java:
##########
@@ -144,29 +158,20 @@ public static BaseModel downloadModel(URL url, Class<?>
type) throws IOException
final Path localFile = Paths.get(homeDirectory.toString(), filename);
if (!Files.exists(localFile)) {
-
System.out.println("Downloading model " + url + " to " + localFile);
try (final InputStream in = url.openStream()) {
Files.copy(in, localFile, StandardCopyOption.REPLACE_EXISTING);
}
System.out.println("Download complete.");
-
}
- if (type == TokenizerModel.class) {
- return new TokenizerModel(localFile);
- } else if (type == ChunkerModel.class) {
- return new ChunkerModel(localFile);
- } else if (type == SentenceModel.class) {
- return new SentenceModel(localFile);
- } else if (type == POSModel.class) {
- return new POSModel(localFile);
- } else {
- return new TokenNameFinderModel(localFile);
+ try {
+ return type.getConstructor(Path.class).newInstance(localFile);
Review Comment:
@kinow I checked, but this won't work due to `T` not being a
`@FunctionalInterface`. For this to work, we'd need to introduce a functional
interface `Model` first. For now, I'll leave it _as is_ for this PR. Feel free
to investigate deeper or open a separate issue for this, if you think, it could
be reworked and offers benefits in other classes/situations.
--
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]