Package opennlp.tools.util
Class DownloadUtil.DownloadParser
java.lang.Object
opennlp.tools.util.DownloadUtil.DownloadParser
- Enclosing class:
DownloadUtil
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDownloadParser(URL indexUrl, Path localIndex) Initializes a parser that keeps a copy of the index page. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate intclosingQuote(String page, char quote, int from) Finds the quote that closes an attribute value and is followed by the end of the tag.extractLinks(String page) Collects the href values of the anchor elements in an index page.private StringReads the index page from its URL, joining its lines.Lists the models of the index page.private intindexOfIgnoreCase(String text, String literal, int from) Finds a literal in the text, ignoring case.private StringReads the local copy of the index page.private voidstoreLocalIndex(String page) Stores the index page as the local copy.
-
Field Details
-
ANCHOR_START
- See Also:
-
ANCHOR_END
- See Also:
-
TAG_END
private static final char TAG_END- See Also:
-
indexUrl
-
localIndex
-
-
Constructor Details
-
DownloadParser
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, ornullto keep no copy.- Throws:
IllegalArgumentException- Thrown ifindexUrlisnull.
-
-
Method Details
-
getAvailableModels
Map<String,Map<ModelType, getAvailableModels() throws MalformedURLException, URISyntaxExceptionURL>> 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. - Throws:
MalformedURLException- Thrown if a model URL is malformed.URISyntaxException- Thrown if a model URL is not a valid URI.
-
readLocalIndex
Reads the local copy of the index page.- Returns:
- The page content, or
nullif there is no readable copy.
-
storeLocalIndex
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.
-
extractLinks
Collects the href values of the anchor elements in an index page. The tag name and attribute are matched ignoring case, the value is quoted with double or single quotes, a value ends at its closing quote followed by>, a link ends at the first</a>, and both may span lines. An anchor whose value is not quoted, or whose value or tag is not closed, is skipped.- Parameters:
page- The page content.- Returns:
- The href values in order.
-
closingQuote
Finds the quote that closes an attribute value and is followed by the end of the tag.- Parameters:
page- The page content.quote- The quote character that opened the value.from- The first offset of the value.- Returns:
- The offset of the closing quote, or
-1.
-
indexOfIgnoreCase
Finds a literal in the text, ignoring case.- Parameters:
text- The text.literal- The literal.from- The start offset.- Returns:
- The first match offset, or
-1.
-
toMap
private Map<String,Map<ModelType, toMapURL>> (List<String> links) throws MalformedURLException, URISyntaxException -
addModel
private void addModel(String locale, String link, Map<String, Map<ModelType, throws URISyntaxException, MalformedURLExceptionURL>> result) -
fetchPageIndex
Reads the index page from its URL, joining its lines.- Returns:
- The page content, or
nullif the page could not be read completely.
-