Class DownloadUtil.DownloadParser

java.lang.Object
opennlp.tools.util.DownloadUtil.DownloadParser
Enclosing class:
DownloadUtil

@Internal static class DownloadUtil.DownloadParser extends Object
  • Field Details

    • indexUrl

      private final URL indexUrl
    • localIndex

      private final Path localIndex
  • Constructor Details

    • DownloadParser

      DownloadParser(URL indexUrl)
      Initializes a parser that keeps no copy of the index page.
      Parameters:
      indexUrl - The index page.
      Throws:
      NullPointerException - Thrown if indexUrl is null.
    • DownloadParser

      DownloadParser(URL indexUrl, Path localIndex)
      Initializes a parser that keeps a copy of the index page.
      Parameters:
      indexUrl - The index page.
      localIndex - The file that keeps a copy of the index page, or null to keep no copy.
      Throws:
      NullPointerException - Thrown if indexUrl is null.
  • Method Details

    • getAvailableModels

      Map<String, Map<ModelType, String>> getAvailableModels()
      Lists the models of the index page. If the page lists models, it is stored as the local copy. Otherwise, for example if the page cannot be read, the local copy is used.
      Returns:
      The model URLs per language and ModelType. Empty if neither the page nor the local copy lists models.
    • extractLinks

      private List<String> extractLinks(String page)
    • readLocalIndex

      private String readLocalIndex()
      Reads the local copy of the index page.
      Returns:
      The page content, or null if there is no readable copy.
    • storeLocalIndex

      private void storeLocalIndex(String page)
      Stores the index page as the local copy. The page is written to a temporary file that then replaces the copy, so a reader never sees a partly written copy. A failure is only logged.
      Parameters:
      page - The page content.
    • toMap

      private Map<String, Map<ModelType, String>> toMap(List<String> links)
    • addModel

      private void addModel(String locale, String link, Map<String, Map<ModelType, String>> result)
    • fetchPageIndex

      private String fetchPageIndex()
      Reads the index page from its URL, joining its lines.
      Returns:
      The page content, or null if the page could not be read completely.