uschindler commented on a change in pull request #643: URL: https://github.com/apache/lucene/pull/643#discussion_r800200763
########## File path: lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/TokenInfoDictionary.java ########## @@ -38,21 +44,73 @@ * @param resourceScheme - scheme for loading resources (FILE or CLASSPATH). * @param resourcePath - where to load resources (dictionaries) from. If null, with CLASSPATH * scheme only, use this class's name as the path. + * @deprecated replaced by {@link #TokenInfoDictionary(Path, Path, Path, Path)} */ + @Deprecated(forRemoval = true, since = "9.1") + @SuppressWarnings("removal") public TokenInfoDictionary(ResourceScheme resourceScheme, String resourcePath) throws IOException { - super(resourceScheme, resourcePath); + this( + resourceScheme == ResourceScheme.FILE + ? () -> Files.newInputStream(Paths.get(resourcePath + TARGETMAP_FILENAME_SUFFIX)) + : () -> getClassResource(TARGETMAP_FILENAME_SUFFIX), + resourceScheme == ResourceScheme.FILE + ? () -> Files.newInputStream(Paths.get(resourcePath + POSDICT_FILENAME_SUFFIX)) + : () -> getClassResource(POSDICT_FILENAME_SUFFIX), + resourceScheme == ResourceScheme.FILE + ? () -> Files.newInputStream(Paths.get(resourcePath + DICT_FILENAME_SUFFIX)) + : () -> getClassResource(DICT_FILENAME_SUFFIX), + resourceScheme == ResourceScheme.FILE + ? () -> Files.newInputStream(Paths.get(resourcePath + FST_FILENAME_SUFFIX)) + : () -> getClassResource(FST_FILENAME_SUFFIX)); + } + + /** + * Create a {@link TokenInfoDictionary} from an external resource path. + * + * @param targetMapFile where to load target map resource + * @param posDictFile where to load POS dictionary resource + * @param dictFile where to load dictionary entries resource + * @param fstFile where to load encoded FST data resource + * @throws IOException if resource was not found or broken + */ + public TokenInfoDictionary(Path targetMapFile, Path posDictFile, Path dictFile, Path fstFile) + throws IOException { + this( + () -> Files.newInputStream(targetMapFile), + () -> Files.newInputStream(posDictFile), + () -> Files.newInputStream(dictFile), + () -> Files.newInputStream(fstFile)); + } + + private TokenInfoDictionary() throws IOException { + this( + () -> getClassResource(TARGETMAP_FILENAME_SUFFIX), + () -> getClassResource(POSDICT_FILENAME_SUFFIX), + () -> getClassResource(DICT_FILENAME_SUFFIX), + () -> getClassResource(FST_FILENAME_SUFFIX)); + } + + private TokenInfoDictionary( + IOSupplier<InputStream> targetMapResource, + IOSupplier<InputStream> posResource, + IOSupplier<InputStream> dictResource, + IOSupplier<InputStream> fstResource) + throws IOException { + super(targetMapResource, posResource, dictResource); FST<Long> fst; - try (InputStream is = new BufferedInputStream(getResource(FST_FILENAME_SUFFIX))) { + try (InputStream is = new BufferedInputStream(fstResource.get())) { DataInput in = new InputStreamDataInput(is); fst = new FST<>(in, in, PositiveIntOutputs.getSingleton()); } // TODO: some way to configure? this.fst = new TokenInfoFST(fst, true); } - private TokenInfoDictionary() throws IOException { - this(ResourceScheme.CLASSPATH, null); + private static InputStream getClassResource(String suffix) throws IOException { + final String resourcePath = TokenInfoDictionary.class.getSimpleName() + suffix; Review comment: I think this is at least fine for the "default loading" for our own resources. It should not be used for public resources (there we now only have constructors taking file streams, as it makes no sense for external files). -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org