[
https://issues.apache.org/jira/browse/OPENNLP-1413?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17650273#comment-17650273
]
ASF GitHub Bot commented on OPENNLP-1413:
-----------------------------------------
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.
> Enhance JavaDoc in opennlp.tools.util package
> ---------------------------------------------
>
> Key: OPENNLP-1413
> URL: https://issues.apache.org/jira/browse/OPENNLP-1413
> Project: OpenNLP
> Issue Type: Improvement
> Components: Documentation
> Affects Versions: 2.1.0
> Reporter: Martin Wiesner
> Assignee: Martin Wiesner
> Priority: Minor
> Fix For: 2.1.1
>
>
> The JavaDoc the _opennlp.tools.util_ package suffers from several
> inconsistencies and missing descriptions. Moreover, several typos are present
> that need sanitizing.
> It needs enhancements and/or additions to provide more clarity for readers.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)